Skip to content

Commit

Permalink
[Synthetics] allow retest on failure to be turned off (#189013)
Browse files Browse the repository at this point in the history
## Summary

Resolves #188804

Allows retest on failure to be configured in the monitor creation UI.

https://www.loom.com/share/2302ccfd150b4668a61966be165478f8

### Testing
1. Create a monitor and toggle retest on failure off.
2. Navigate to edit that monitor. Ensure the setting remains off.

### Release note
Fixes a bug where retest on failure was not able to be turned off when
creating a monitor in the Synthetics app. Retest on failure can now be
turned off.
  • Loading branch information
dominiqueclarke authored Jul 24, 2024
1 parent 13b0749 commit 14f370b
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export class AddEditMonitorAPI {
...DEFAULT_FIELDS[monitorType],
...monitor,
[ConfigKey.SCHEDULE]: getMonitorSchedule(schedule ?? defaultFields[ConfigKey.SCHEDULE]),
[ConfigKey.MAX_ATTEMPTS]: getMaxAttempts(retestOnFailure),
[ConfigKey.MAX_ATTEMPTS]: getMaxAttempts(retestOnFailure, monitor[ConfigKey.MAX_ATTEMPTS]),
[ConfigKey.LOCATIONS]: locationsVal,
} as MonitorFields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ const getAlertConfig = (monitor: ProjectMonitor) => {

const ONLY_ONE_ATTEMPT = 1;

export const getMaxAttempts = (retestOnFailure?: boolean) => {
export const getMaxAttempts = (retestOnFailure?: boolean, maxAttempts?: number) => {
const defaultFields = DEFAULT_COMMON_FIELDS;
if (!retestOnFailure && maxAttempts) {
return maxAttempts;
}
if (retestOnFailure) {
return defaultFields[ConfigKey.MAX_ATTEMPTS];
} else if (retestOnFailure === false) {
Expand Down
31 changes: 31 additions & 0 deletions x-pack/test/api_integration/apis/synthetics/add_monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/
import expect from '@kbn/expect';
import epct from 'expect';
import moment from 'moment/moment';
import { v4 as uuidv4 } from 'uuid';
import { omit, omitBy } from 'lodash';
Expand Down Expand Up @@ -141,6 +142,36 @@ export default function ({ getService }: FtrProviderContext) {
);
});

it('can disable retries', async () => {
const maxAttempts = 1;
const newMonitor = {
max_attempts: maxAttempts,
urls: 'https://elastic.co',
name: `Sample name ${uuidv4()}`,
type: 'http',
locations: [localLoc],
};

const { body: apiResponse } = await addMonitorAPI(newMonitor);

epct(apiResponse).toEqual(epct.objectContaining({ max_attempts: maxAttempts }));
});

it('can enable retries', async () => {
const maxAttempts = 2;
const newMonitor = {
max_attempts: maxAttempts,
urls: 'https://elastic.co',
name: `Sample name ${uuidv4()}`,
type: 'http',
locations: [localLoc],
};

const { body: apiResponse } = await addMonitorAPI(newMonitor);

epct(apiResponse).toEqual(epct.objectContaining({ max_attempts: maxAttempts }));
});

it('cannot create a invalid monitor without a monitor type', async () => {
// Delete a required property to make payload invalid
const newMonitor = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/
import expect from '@kbn/expect';
import { v4 as uuidv4 } from 'uuid';
import { omitBy } from 'lodash';

import { DEFAULT_FIELDS } from '@kbn/synthetics-plugin/common/constants/monitor_defaults';
Expand Down Expand Up @@ -135,6 +136,52 @@ export default function ({ getService }: FtrProviderContext) {
})
);
});

it('can enable retries', async () => {
const name = `test name ${uuidv4()}`;
const monitor = {
type: 'http',
locations: ['dev'],
url: 'https://www.google.com',
name,
retest_on_failure: true,
};
const { body: result } = await addMonitorAPI(monitor);

expect(result).eql(
omitMonitorKeys({
...defaultFields,
...monitor,
locations: [localLoc],
name,
max_attempts: 2,
retest_on_failure: undefined, // this key is not part of the SO and should not be defined
})
);
});

it('can disable retries', async () => {
const name = `test name ${uuidv4()}`;
const monitor = {
type: 'http',
locations: ['dev'],
url: 'https://www.google.com',
name,
retest_on_failure: false,
};
const { body: result } = await addMonitorAPI(monitor);

expect(result).eql(
omitMonitorKeys({
...defaultFields,
...monitor,
locations: [localLoc],
name,
max_attempts: 1,
retest_on_failure: undefined, // this key is not part of the SO and should not be defined
})
);
});
});

describe('TCP Monitor', () => {
Expand Down

0 comments on commit 14f370b

Please sign in to comment.