Repository: elastic/synthetics
Pull request #845 (2023-10-04 11:39:23)

feat: add retest on failure monitor property
add retest on failure monitor property !!

devcorpio: Overall looks good, but I have a few questions/statements:

- Does this property work via `synthetics.config` file?
- Does this property work through `monitor.use`?
- I believe we should update cli.ts adding the description of this new CLI flag, too
shahzad31: > Overall looks good, but I have a few questions/statements:
> 
> * Does this property work via `synthetics.config` file?
Yes it does, unit test has been updated to reflect that
> * Does this property work through `monitor.use`?
yes it does, unit test has been updated to reflect that
> * I believe we should update cli.ts adding the description of this new CLI flag, too
no, it's not a cli option



Patch:
diff --git a/src/common_types.ts b/src/common_types.ts
index 1c9f9e4..da50a7a 100644
--- a/src/common_types.ts
+++ b/src/common_types.ts
@@ -218,6 +218,7 @@ type BaseArgs = {
   locations?: MonitorConfig['locations'];
   privateLocations?: MonitorConfig['privateLocations'];
   alert?: AlertConfig;
+  retestOnFailure?: MonitorConfig['retestOnFailure'];
 };
 
 export type CliArgs = BaseArgs & {
diff --git a/src/dsl/monitor.ts b/src/dsl/monitor.ts
index eb94337..9f3411f 100644
--- a/src/dsl/monitor.ts
+++ b/src/dsl/monitor.ts
@@ -72,6 +72,10 @@ export type MonitorConfig = {
   params?: Params;
   playwrightOptions?: PlaywrightOptions;
   alert?: AlertConfig;
+  /**
+   * By default, the monitor will be retested on failure
+   */
+  retestOnFailure?: boolean;
 };
 
 type MonitorFilter = {
diff --git a/src/push/monitor.ts b/src/push/monitor.ts
index a920de6..c95dc03 100644
--- a/src/push/monitor.ts
+++ b/src/push/monitor.ts
@@ -246,6 +246,7 @@ export function buildMonitorFromYaml(
   const alertConfig = parseAlertConfig(config, options.alert);
   const mon = new Monitor({
     locations: options.locations,
+    retestOnFailure: options.retestOnFailure,
     tags: options.tags,
     ...config,
     privateLocations,


Test patch:
diff --git a/__tests__/push/monitor.test.ts b/__tests__/push/monitor.test.ts
index cd0b62e..f3acff3 100644
--- a/__tests__/push/monitor.test.ts
+++ b/__tests__/push/monitor.test.ts
@@ -245,6 +245,7 @@ heartbeat.monitors:
   tags:
     - ltag1
     - ltag2
+  retestOnFailure: true
       `);
 
       const [mon] = await createLightweightMonitors(PROJECT_DIR, {
@@ -254,6 +255,7 @@ heartbeat.monitors:
         tags: ['gtag1', 'gtag2'],
         privateLocations: ['gbaz'],
         schedule: 10,
+        retestOnFailure: false,
       } as any);
 
       expect(mon.config).toEqual({
@@ -265,6 +267,7 @@ heartbeat.monitors:
         params: { foo: 'bar' },
         schedule: 5,
         tags: ['ltag1', 'ltag2'],
+        retestOnFailure: true,
       });
     });
 
@@ -280,6 +283,7 @@ heartbeat.monitors:
         tags: ['gtag1', 'gtag2'],
         privateLocations: ['gbaz'],
         schedule: 10,
+        retestOnFailure: false,
       } as PushOptions);
 
       expect(mon.config).toEqual({
@@ -289,6 +293,7 @@ heartbeat.monitors:
         type: 'icmp',
         schedule: 10,
         tags: ['gtag1', 'gtag2'],
+        retestOnFailure: false,
       });
     });