Repository: elastic/synthetics (ts)

Issue:
Global monitor options enabled and retestOnFailure are ignored
Not all global `synthetics.config.ts` settings for [MonitorConfig](https://github.com/elastic/synthetics/blob/main/src/dsl/monitor.ts#L56-L79) get applied to individual monitors.

Example valid `synthetics.config.ts` for cases where by default all monitors (`enabled`), all alerts (`alert`) and retest on failure (`retestOnFailure`) should be disabled:
```ts
import type { SyntheticsConfig } from "@elastic/synthetics";

export default (env: string) => {
  const config: SyntheticsConfig = {
    params: {},
    playwrightOptions: {},
    /**
     * Configure global monitor settings
     */
    monitor: {
      schedule: 10,
      locations: [],
      privateLocations: [],
      alert: {
        status: {
          enabled: false,
        },
        tls: {
          enabled: false,
        },
      },
      enabled: false,
      throttling: false,
      retestOnFailure: false,
    },
    /**
     * Project monitors settings
     */
    project: {
      id: "foo",
      url: "https://example.com/",
      space: "default",
    },
  };
  if (env !== "development") {
    /**
     * Override configuration specific to environment
     * Ex: config.params.url = ""
     */
  }
  return config;
};

```

Expected monitor config would be something like this:
```ts
const j1 = new Journey({ name: 'j1', tags: ['foo*'] }, () => {});
j1.updateMonitor({
  id: 'test-j1',
  schedule: 3,
  locations: ['united_kingdom'],
  privateLocations: ['spain'],
});
runner.addJourney(j1);

const monitors = runner.buildMonitors( /* put global settings here */ );
expect(monitors.length).toBe(1);
console.dir(monitors[0].config);
expect(monitors[0].config).toEqual({
  // from local config
  id: 'test-j1',
  name: 'j1',
  type: 'browser',
  tags: ['foo*'],
  locations: ['united_kingdom'],
  privateLocations: ['spain'],
  schedule: 3,
  // Params and PlaywrightOptions, not in scope of this issue
  playwrightOptions: {},
  params: {},
  // from global config
  enabled: false,
  retestOnFailure: false,
  throttling: false,
  alert: { status: { enabled: false }, tls: { enabled: false } },
  screenshot: undefined,
});
```
But instead you're getting `MonitorConfig`:
```ts
{
  throttling: false,
  schedule: 3,
  locations: [ 'united_kingdom' ],
  privateLocations: [ 'spain' ],
  params: {},
  playwrightOptions: {},
  screenshot: undefined,
  tags: [ 'foo*' ],
  alert: { status: { enabled: false }, tls: { enabled: false } },
  name: 'j1',
  id: 'test-j1',
  type: 'browser'
}
```
with `enabled` and `retestOnFailure` settings completely ignored.
Tests for this also seem to be wrong, because [runner.updateMonitor](https://github.com/elastic/synthetics/blob/main/__tests__/core/runner.test.ts#L757) gets executed by test with global settings and `runner.buildMonitors(options)` is called with local settings which is wrong, `runner.buildMonitors(options)` should be called with global settings and `runner.updateMonitor` should not be executed at all, because it's invoked by `runner.buildMonitors` [here](https://github.com/elastic/synthetics/blob/main/src/core/runner.ts#L410).

Pull request description:
fix: allow overriding enabled/retestOnFailure via global config
+ fix #894 
+ enabled: false and retestOnFailure: false on the synthetics global config did not get passed to Kibana which effectively meant the users can only enable/disable them via individual monitor config. This PR fixes the problem and allows all monitors to be overridden with correct value. 

Patch:
diff --git a/src/common_types.ts b/src/common_types.ts
index 220be52..210d36e 100644
--- a/src/common_types.ts
+++ b/src/common_types.ts
@@ -248,6 +248,7 @@ export type PushOptions = Partial<ProjectSettings> &
     yes?: boolean;
     alert?: AlertConfig;
     retestOnFailure?: MonitorConfig['retestOnFailure'];
+    enabled?: boolean;
   };
 
 export type ProjectSettings = {
diff --git a/src/core/runner.ts b/src/core/runner.ts
index 0cc9f46..3d28737 100644
--- a/src/core/runner.ts
+++ b/src/core/runner.ts
@@ -417,6 +417,8 @@ export default class Runner {
       screenshot: options.screenshots,
       tags: options.tags,
       alert: options.alert,
+      retestOnFailure: options.retestOnFailure,
+      enabled: options.enabled,
     });
 
     const monitors: Monitor[] = [];
diff --git a/src/push/monitor.ts b/src/push/monitor.ts
index 4152c42..356f736 100644
--- a/src/push/monitor.ts
+++ b/src/push/monitor.ts
@@ -250,6 +250,7 @@ export function buildMonitorFromYaml(
   const alertConfig = parseAlertConfig(config, options.alert);
 
   const mon = new Monitor({
+    enabled: config.enabled ?? options.enabled,
     locations: options.locations,
     tags: options.tags,
     ...normalizeConfig(config),


Test patch:
diff --git a/__tests__/core/runner.test.ts b/__tests__/core/runner.test.ts
index 5112cff..b642c10 100644
--- a/__tests__/core/runner.test.ts
+++ b/__tests__/core/runner.test.ts
@@ -754,6 +754,7 @@ describe('runner', () => {
     });
 
     it('runner - build monitors with global config', async () => {
+      // Faking monitor.use across file level
       runner.updateMonitor({
         schedule: 5,
         locations: ['us_east'],
@@ -772,16 +773,22 @@ describe('runner', () => {
         schedule: 3,
         locations: ['united_kingdom'],
         privateLocations: ['spain'],
+        retestOnFailure: true,
       });
-      j2.updateMonitor({ throttling: { latency: 1000 } });
+      j2.updateMonitor({ throttling: { latency: 1000 }, enabled: true });
       runner.addJourney(j1);
       runner.addJourney(j2);
 
-      const monitors = runner.buildMonitors(options);
+      const monitors = runner.buildMonitors({
+        ...options,
+        enabled: false,
+        retestOnFailure: false,
+      });
       expect(monitors.length).toBe(2);
       expect(monitors[0].config).toEqual({
         id: 'test-j1',
         name: 'j1',
+        enabled: false,
         type: 'browser',
         tags: ['foo*'],
         locations: ['united_kingdom'],
@@ -791,11 +798,13 @@ describe('runner', () => {
         playwrightOptions: { ignoreHTTPSErrors: true },
         throttling: { download: 100, latency: 20, upload: 50 },
         alert: { tls: { enabled: true } },
+        retestOnFailure: true,
       });
       expect(monitors[1].config).toMatchObject({
         locations: ['us_east'],
         privateLocations: ['germany'],
         schedule: 5,
+        enabled: true,
         tags: ['g1', 'g2'],
         throttling: { latency: 1000 },
         alert: { tls: { enabled: true } },