diff --git a/__tests__/core/runner.test.ts b/__tests__/core/runner.test.ts index 938ac430..30a76428 100644 --- a/__tests__/core/runner.test.ts +++ b/__tests__/core/runner.test.ts @@ -788,6 +788,7 @@ describe('runner', () => { alert: { tls: { enabled: true } }, playwrightOptions: { ignoreHTTPSErrors: true }, fields: { area: 'website' }, + namespace: 'test', }); const j1 = new Journey({ name: 'j1', tags: ['foo*'] }, noop); @@ -824,6 +825,7 @@ describe('runner', () => { alert: { tls: { enabled: true } }, retestOnFailure: true, fields: { area: 'website' }, + namespace: 'test', }); expect(monitors[1].config).toMatchObject({ locations: ['us_east'], diff --git a/__tests__/push/monitor.test.ts b/__tests__/push/monitor.test.ts index e10ff463..ac356864 100644 --- a/__tests__/push/monitor.test.ts +++ b/__tests__/push/monitor.test.ts @@ -523,6 +523,34 @@ heartbeat.monitors: }, }); }); + + it('supports namespace in config', async () => { + await writeHBFile(` +heartbeat.monitors: +- type: icmp + schedule: @every 5m + id: "test-icmp" + name: "test-icmp" + namespace: "foo" + `); + + const [mon] = await createLightweightMonitors(PROJECT_DIR, { + auth: 'foo', + kibanaVersion: '8.8.0', + locations: ['australia_east'], + schedule: 10, + namespace: 'foo', + }); + + expect(mon.config).toEqual({ + id: 'test-icmp', + name: 'test-icmp', + locations: ['australia_east'], + type: 'icmp', + schedule: 5, + namespace: 'foo', + }); + }); }); describe('parseAlertConfig', () => { diff --git a/src/cli.ts b/src/cli.ts index 8115b31d..1a05f0e6 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -68,6 +68,7 @@ const { tags, match, fields, + namespace, } = getCommonCommandOpts(); program @@ -197,6 +198,7 @@ program .addOption(pattern) .addOption(tags) .addOption(fields) + .addOption(namespace) .addOption(match) .addOption(params) .addOption(playwrightOpts) diff --git a/src/common_types.ts b/src/common_types.ts index 476ccb8e..00a7bca2 100644 --- a/src/common_types.ts +++ b/src/common_types.ts @@ -263,6 +263,7 @@ export type PushOptions = Partial & retestOnFailure?: MonitorConfig['retestOnFailure']; enabled?: boolean; grepOpts?: GrepOptions; + namespace?: string; }; export type ProjectSettings = { diff --git a/src/core/runner.ts b/src/core/runner.ts index a1b6b486..24d037c9 100644 --- a/src/core/runner.ts +++ b/src/core/runner.ts @@ -443,6 +443,7 @@ export default class Runner implements RunnerInfo { retestOnFailure: options.retestOnFailure, enabled: options.enabled, fields: options.fields, + namespace: options.namespace, }); const monitors: Monitor[] = []; diff --git a/src/dsl/monitor.ts b/src/dsl/monitor.ts index 87d56289..c29bf191 100644 --- a/src/dsl/monitor.ts +++ b/src/dsl/monitor.ts @@ -77,6 +77,7 @@ export type MonitorConfig = { * By default, the monitor will be retested on failure */ retestOnFailure?: boolean; + namespace?: string; }; type MonitorFilter = { diff --git a/src/options.ts b/src/options.ts index 355b5491..59902a9f 100644 --- a/src/options.ts +++ b/src/options.ts @@ -236,6 +236,10 @@ export function getCommonCommandOpts() { '--match ', 'run/push tests with a name or tags that matches a pattern' ); + const namespace = createOption( + '--namespace ', + 'Kibana namespace to use for the monitor. Defaults to the spaceId of the current project.' + ); const fields = createOption( '--fields ', 'add fields to the monitor(s) in the format { "key": "value"}' @@ -265,6 +269,7 @@ export function getCommonCommandOpts() { tags, match, fields, + namespace, }; } diff --git a/src/push/monitor.ts b/src/push/monitor.ts index a9c1c497..a9143038 100644 --- a/src/push/monitor.ts +++ b/src/push/monitor.ts @@ -288,6 +288,7 @@ export function buildMonitorFromYaml( const alertConfig = parseAlertConfig(config, options.alert); const mon = new Monitor({ + namespace: config.namespace ?? options.namespace, enabled: config.enabled ?? options.enabled, locations: options.locations, tags: options.tags,