Skip to content

Commit

Permalink
feat: camelcase retest config for lightweight monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshshanmugam committed Oct 10, 2023
1 parent ae4938b commit e907b11
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
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

0 comments on commit e907b11

Please sign in to comment.