Skip to content

fix: add types for namespace #1021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __tests__/core/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'],
Expand Down
28 changes: 28 additions & 0 deletions __tests__/push/monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 2 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const {
tags,
match,
fields,
namespace,
} = getCommonCommandOpts();

program
Expand Down Expand Up @@ -197,6 +198,7 @@ program
.addOption(pattern)
.addOption(tags)
.addOption(fields)
.addOption(namespace)
.addOption(match)
.addOption(params)
.addOption(playwrightOpts)
Expand Down
1 change: 1 addition & 0 deletions src/common_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export type PushOptions = Partial<ProjectSettings> &
retestOnFailure?: MonitorConfig['retestOnFailure'];
enabled?: boolean;
grepOpts?: GrepOptions;
namespace?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have raised this before, this should belong inside data_stream #697 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's already at namespace in kibana, we can't change it, though we can additionally add support for it here?

};

export type ProjectSettings = {
Expand Down
1 change: 1 addition & 0 deletions src/core/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down
1 change: 1 addition & 0 deletions src/dsl/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type MonitorConfig = {
* By default, the monitor will be retested on failure
*/
retestOnFailure?: boolean;
namespace?: string;
};

type MonitorFilter = {
Expand Down
5 changes: 5 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ export function getCommonCommandOpts() {
'--match <name>',
'run/push tests with a name or tags that matches a pattern'
);
const namespace = createOption(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused with this option now, Is it synthetics data stream namespace or something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well it's data stream namespace option

'--namespace <name>',
'Kibana namespace to use for the monitor. Defaults to the spaceId of the current project.'
);
const fields = createOption(
'--fields <jsonstring>',
'add fields to the monitor(s) in the format { "key": "value"}'
Expand Down Expand Up @@ -265,6 +269,7 @@ export function getCommonCommandOpts() {
tags,
match,
fields,
namespace,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/push/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down