Skip to content
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

feat: camelcase retest config for lightweight monitors #847

Merged
merged 1 commit into from
Oct 11, 2023
Merged
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
8 changes: 5 additions & 3 deletions __tests__/push/monitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,19 @@ heartbeat.monitors:
tags:
- ltag1
- ltag2
retestOnFailure: true
retest_on_failure: true
`);

const [mon] = await createLightweightMonitors(PROJECT_DIR, {
auth: 'foo',
params: { foo: 'bar' },
kibanaVersion: '8.8.0',
locations: ['australia_east'],
tags: ['gtag1', 'gtag2'],
privateLocations: ['gbaz'],
schedule: 10,
retestOnFailure: false,
} as any);
});

expect(mon.config).toEqual({
id: 'test-icmp',
Expand All @@ -280,11 +281,12 @@ heartbeat.monitors:
`);

const [mon] = await createLightweightMonitors(PROJECT_DIR, {
auth: 'foo',
tags: ['gtag1', 'gtag2'],
privateLocations: ['gbaz'],
schedule: 10,
retestOnFailure: false,
} as PushOptions);
});

expect(mon.config).toEqual({
id: 'test-icmp',
Expand Down
4 changes: 2 additions & 2 deletions src/common_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,6 @@ type BaseArgs = {
schedule?: MonitorConfig['schedule'];
locations?: MonitorConfig['locations'];
privateLocations?: MonitorConfig['privateLocations'];
alert?: AlertConfig;
retestOnFailure?: MonitorConfig['retestOnFailure'];
};

export type CliArgs = BaseArgs & {
Expand Down Expand Up @@ -249,6 +247,8 @@ export type PushOptions = Partial<ProjectSettings> &
auth: string;
kibanaVersion?: string;
yes?: boolean;
alert?: AlertConfig;
retestOnFailure?: MonitorConfig['retestOnFailure'];
};

export type ProjectSettings = {
Expand Down
16 changes: 13 additions & 3 deletions src/push/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,15 @@ export function buildMonitorFromYaml(
config['private_locations'] ||
config.privateLocations ||
options.privateLocations;
delete config['private_locations'];
const retestOnFailure =
config['retest_on_failure'] ?? options.retestOnFailure;
const alertConfig = parseAlertConfig(config, options.alert);

const mon = new Monitor({
locations: options.locations,
retestOnFailure: options.retestOnFailure,
tags: options.tags,
...config,
...normalizeConfig(config),
retestOnFailure,
privateLocations,
schedule: schedule || options.schedule,
alert: alertConfig,
Expand All @@ -264,6 +266,14 @@ export function buildMonitorFromYaml(
return mon;
}

// Deletes unncessary fields from the lightweight monitor config
// that is not supported by the Kibana API
function normalizeConfig(config: MonitorConfig) {
delete config['private_locations'];
delete config['retest_on_failure'];
return config;
}

export const parseAlertConfig = (
config: MonitorConfig,
gConfig?: AlertConfig
Expand Down