mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Synthetics] Support project lightweight 10 and 30 seconds schedules (#185920)
## Summary Companion PR to https://github.com/elastic/synthetics/pull/932
This commit is contained in:
parent
f4f927b3d0
commit
e3a85ddb39
3 changed files with 70 additions and 6 deletions
|
@ -6,9 +6,23 @@
|
|||
*/
|
||||
|
||||
import * as t from 'io-ts';
|
||||
import { Either } from 'fp-ts/Either';
|
||||
import { AlertConfigsCodec } from './alert_config';
|
||||
import { ScreenshotOptionCodec } from './monitor_configs';
|
||||
|
||||
const ProjectMonitorSchedule = new t.Type<string | number, string | number, unknown>(
|
||||
'ProjectMonitorSchedule',
|
||||
t.string.is,
|
||||
(input, context): Either<t.Errors, string | number> => {
|
||||
if (typeof input === 'number' || input === '10s' || input === '30s') {
|
||||
return t.success(input);
|
||||
} else {
|
||||
return t.failure(input, context);
|
||||
}
|
||||
},
|
||||
t.identity
|
||||
);
|
||||
|
||||
export const ProjectMonitorThrottlingConfigCodec = t.union([
|
||||
t.interface({
|
||||
download: t.number,
|
||||
|
@ -23,7 +37,7 @@ export const ProjectMonitorCodec = t.intersection([
|
|||
type: t.string,
|
||||
id: t.string,
|
||||
name: t.string,
|
||||
schedule: t.number,
|
||||
schedule: ProjectMonitorSchedule,
|
||||
}),
|
||||
t.partial({
|
||||
content: t.string,
|
||||
|
|
|
@ -75,10 +75,7 @@ export const getNormalizeCommonFields = ({
|
|||
[ConfigKey.JOURNEY_ID]: monitor.id || defaultFields[ConfigKey.JOURNEY_ID],
|
||||
[ConfigKey.MONITOR_SOURCE_TYPE]: SourceType.PROJECT,
|
||||
[ConfigKey.NAME]: monitor.name || '',
|
||||
[ConfigKey.SCHEDULE]: {
|
||||
number: `${monitor.schedule}`,
|
||||
unit: ScheduleUnit.MINUTES,
|
||||
},
|
||||
[ConfigKey.SCHEDULE]: getMonitorSchedule(monitor.schedule, defaultFields[ConfigKey.SCHEDULE]),
|
||||
[ConfigKey.PROJECT_ID]: projectId,
|
||||
[ConfigKey.LOCATIONS]: monLocations,
|
||||
[ConfigKey.TAGS]: getOptionalListField(monitor.tags) || defaultFields[ConfigKey.TAGS],
|
||||
|
@ -145,8 +142,27 @@ export const getCustomHeartbeatId = (
|
|||
return `${monitor.id}-${projectId}-${namespace}`;
|
||||
};
|
||||
|
||||
export const getMonitorSchedule = (schedule: number | string | MonitorFields['schedule']) => {
|
||||
export const getMonitorSchedule = (
|
||||
schedule: number | string | MonitorFields['schedule'],
|
||||
defaultValue?: MonitorFields['schedule']
|
||||
) => {
|
||||
if (!schedule && defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (typeof schedule === 'number' || typeof schedule === 'string') {
|
||||
if (typeof schedule === 'number') {
|
||||
return {
|
||||
number: `${schedule}`,
|
||||
unit: ScheduleUnit.MINUTES,
|
||||
};
|
||||
}
|
||||
if (schedule.includes('s')) {
|
||||
return {
|
||||
number: schedule.replace('s', ''),
|
||||
unit: ScheduleUnit.SECONDS,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
number: `${schedule}`,
|
||||
unit: ScheduleUnit.MINUTES,
|
||||
|
|
|
@ -194,6 +194,40 @@ describe('ProjectMonitorFormatter', () => {
|
|||
updatedMonitors: [],
|
||||
});
|
||||
});
|
||||
it('should return invalid schedule error', async () => {
|
||||
const invalidMonitor = {
|
||||
...testMonitors[0],
|
||||
schedule: '3m',
|
||||
};
|
||||
const pushMonitorFormatter = new ProjectMonitorFormatter({
|
||||
projectId: 'test-project',
|
||||
spaceId: 'default',
|
||||
routeContext,
|
||||
encryptedSavedObjectsClient,
|
||||
monitors: [invalidMonitor],
|
||||
});
|
||||
|
||||
pushMonitorFormatter.getProjectMonitorsForProject = jest.fn().mockResolvedValue([]);
|
||||
|
||||
await pushMonitorFormatter.configureAllProjectMonitors();
|
||||
|
||||
expect({
|
||||
createdMonitors: pushMonitorFormatter.createdMonitors,
|
||||
updatedMonitors: pushMonitorFormatter.updatedMonitors,
|
||||
failedMonitors: pushMonitorFormatter.failedMonitors,
|
||||
}).toStrictEqual({
|
||||
createdMonitors: [],
|
||||
failedMonitors: [
|
||||
{
|
||||
details: 'Invalid value "3m" supplied to "schedule"',
|
||||
id: 'check if title is present 10 0',
|
||||
payload: invalidMonitor,
|
||||
reason: "Couldn't save or update monitor because of an invalid configuration.",
|
||||
},
|
||||
],
|
||||
updatedMonitors: [],
|
||||
});
|
||||
});
|
||||
|
||||
it('catches errors from bulk edit method', async () => {
|
||||
soClient.bulkCreate.mockImplementation(async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue