Skip to content

Commit

Permalink
update api test
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Sep 27, 2024
1 parent 46d4184 commit cf339ed
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ journey(`CustomStatusAlert`, async ({ page, params }) => {
expect(rules.length).toBe(3);
expect(rules[2].params).toStrictEqual({
condition: {
downThreshold: 5,
downThreshold: 3,
locationsThreshold: 1,
groupBy: 'locationId',
window: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,20 +622,20 @@ describe('setRecoveredAlertsContext', () => {
status: 'recovered',
recoveryReason: 'the alert condition is no longer met',
recoveryStatus: 'has recovered',
locationId: 'us_central | us_west',
locationId: 'us_central and us_west',
checkedAt: 'Feb 26, 2023 @ 00:00:00.000',
linkMessage:
'- Link: https://localhost:5601/app/synthetics/monitor/56789/errors/123456?locationId=us_central',
monitorUrl: 'http://test_url.com',
hostName: 'test-agent',
monitorUrlLabel: 'URL',
reason:
'Monitor "test-monitor" from us-central | us-east is recovered. Alert when 1 out of the last 1 checks are down from at least 1 location.',
'Monitor "test-monitor" from us-central and us-east is recovered. Alert when 1 out of the last 1 checks are down from at least 1 location.',
stateId: '123456',
timestamp: '2023-02-26T00:00:00.000Z',
downThreshold: 1,
locationNames: 'us-central | us-east',
locationName: 'us-central | us-east',
locationNames: 'us-central and us-east',
locationName: 'us-central and us-east',
monitorType: 'HTTP',
lastErrorMessage: 'test-error-message',
},
Expand Down Expand Up @@ -707,12 +707,12 @@ describe('setRecoveredAlertsContext', () => {
hostName: 'test-agent',
monitorUrlLabel: 'URL',
reason:
'Monitor "test-monitor" from us-central | us-east is recovered. Alert when 1 out of the last 1 checks are down from at least 1 location.',
'Monitor "test-monitor" from us-central and us-east is recovered. Alert when 1 out of the last 1 checks are down from at least 1 location.',
stateId: '123456',
timestamp: '2023-02-26T00:00:00.000Z',
downThreshold: 1,
locationNames: 'us-central | us-east',
locationName: 'us-central | us-east',
locationNames: 'us-central and us-east',
locationName: 'us-central and us-east',
monitorType: 'HTTP',
lastErrorMessage: 'test-error-message',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const setRecoveredAlertsContext = ({
const context = {
...alertState,
...(monitorSummary ? monitorSummary : {}),
locationId: locationIds.join(' | '),
locationId: locationIds.join(` ${AND_LABEL} `),
idWithLocation: recoveredAlertId,
lastErrorMessage,
recoveryStatus,
Expand Down Expand Up @@ -580,6 +580,6 @@ export function getTimeUnitLabel(timeWindow: TimeWindow) {
}
}

const AND_LABEL = i18n.translate('xpack.synthetics.alerts.monitorStatus.andLabel', {
export const AND_LABEL = i18n.translate('xpack.synthetics.alerts.monitorStatus.andLabel', {
defaultMessage: 'and',
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n';
import { ALERT_REASON } from '@kbn/rule-data-utils';
import { AlertStatusMetaData } from '../../../common/runtime_types/alert_rules/common';
import { getConditionType, StatusRuleParams } from '../../../common/rules/status_rule';
import { getTimeUnitLabel } from '../common';
import { AND_LABEL, getTimeUnitLabel } from '../common';
import { ALERT_REASON_MSG } from '../action_variables';
import { MonitorSummaryStatusRule } from './types';
import {
Expand Down Expand Up @@ -80,7 +80,7 @@ export const getMonitorSummary = ({
const monitorName = monitorInfo?.monitor?.name ?? monitorInfo?.monitor?.id;
const locationName = monitorInfo?.observer?.geo?.name ?? UNNAMED_LOCATION;
const formattedLocationName = Array.isArray(locationName)
? locationName.join(' | ')
? locationName.join(` ${AND_LABEL} `)
: locationName;
const checkedAt = moment(monitorInfo?.['@timestamp'])
.tz(tz || 'UTC')
Expand All @@ -104,7 +104,7 @@ export const getMonitorSummary = ({

return {
checkedAt,
locationId: locationId?.join?.(' | ') ?? '',
locationId: locationId?.join?.(` ${AND_LABEL} `) ?? '',
configId,
monitorUrl: monitorInfo.url?.full || UNAVAILABLE_LABEL,
monitorUrlLabel: typeToUrlLabelMap[monitorType] || 'URL',
Expand Down Expand Up @@ -190,7 +190,7 @@ export const getUngroupedReasonMessage = ({
}
);
})
.join(' | '),
.join(` ${AND_LABEL} `),
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ export default function ({ getService }: FtrProviderContext) {
expect(alert).to.have.property('kibana.alert.status', 'active');

expect(alert['kibana.alert.reason']).to.eql(
`Monitor "${monitor.name}" is down 1 time from Dev Service | 1 time from Dev Service 2. Alert when down 1 time out of the last 1 checks from at least 2 locations.`
`Monitor "${monitor.name}" is down 1 time from Dev Service and 1 time from Dev Service 2. Alert when down 1 time out of the last 1 checks from at least 2 locations.`
);
const downResponse = await waitForDocumentInIndex<{
ruleType: string;
Expand All @@ -527,17 +527,17 @@ export default function ({ getService }: FtrProviderContext) {
});
expect(downResponse.hits.hits[0]._source).property(
'reason',
`Monitor "${monitor.name}" is down 1 time from Dev Service | 1 time from Dev Service 2. Alert when down 1 time out of the last 1 checks from at least 2 locations.`
`Monitor "${monitor.name}" is down 1 time from Dev Service and 1 time from Dev Service 2. Alert when down 1 time out of the last 1 checks from at least 2 locations.`
);
expect(downResponse.hits.hits[0]._source).property(
'locationNames',
'Dev Service | Dev Service 2'
'Dev Service and Dev Service 2'
);
expect(downResponse.hits.hits[0]._source).property(
'linkMessage',
`- Link: https://localhost:5601/app/synthetics/monitor/${monitor.id}/errors/Test%20private%20location-18524a3d9a7-0?locationId=dev`
);
expect(downResponse.hits.hits[0]._source).property('locationId', 'dev | dev2');
expect(downResponse.hits.hits[0]._source).property('locationId', 'dev and dev2');
});

it('should trigger recovered alert', async () => {
Expand Down Expand Up @@ -583,17 +583,17 @@ export default function ({ getService }: FtrProviderContext) {
});
expect(recoveryResponse.hits.hits[1]._source).property(
'reason',
`Monitor "${monitor.name}" from Dev Service | Dev Service 2 is recovered. Alert when 1 out of the last 1 checks are down from at least 2 locations.`
`Monitor "${monitor.name}" from Dev Service and Dev Service 2 is recovered. Alert when 1 out of the last 1 checks are down from at least 2 locations.`
);
expect(recoveryResponse.hits.hits[1]._source).property(
'locationNames',
'Dev Service | Dev Service 2'
'Dev Service and Dev Service 2'
);
expect(recoveryResponse.hits.hits[1]._source).property(
'linkMessage',
`- Link: https://localhost:5601/app/synthetics/monitor/${monitor.id}/errors/Test%20private%20location-18524a3d9a7-0?locationId=dev`
);
expect(recoveryResponse.hits.hits[1]._source).property('locationId', 'dev | dev2');
expect(recoveryResponse.hits.hits[1]._source).property('locationId', 'dev and dev2');
});

let downDocs: any[] = [];
Expand All @@ -616,7 +616,7 @@ export default function ({ getService }: FtrProviderContext) {
const alert: any = response.hits.hits?.[0]._source;
expect(alert).to.have.property('kibana.alert.status', 'active');
expect(alert['kibana.alert.reason']).to.eql(
`Monitor "${monitor.name}" is down 1 time from Dev Service | 1 time from Dev Service 2. Alert when down 1 time out of the last 1 checks from at least 2 locations.`
`Monitor "${monitor.name}" is down 1 time from Dev Service and 1 time from Dev Service 2. Alert when down 1 time out of the last 1 checks from at least 2 locations.`
);
const downResponse = await waitForDocumentInIndex<{
ruleType: string;
Expand All @@ -632,17 +632,17 @@ export default function ({ getService }: FtrProviderContext) {
});
expect(downResponse.hits.hits[2]._source).property(
'reason',
`Monitor "${monitor.name}" is down 1 time from Dev Service | 1 time from Dev Service 2. Alert when down 1 time out of the last 1 checks from at least 2 locations.`
`Monitor "${monitor.name}" is down 1 time from Dev Service and 1 time from Dev Service 2. Alert when down 1 time out of the last 1 checks from at least 2 locations.`
);
expect(downResponse.hits.hits[2]._source).property(
'locationNames',
'Dev Service | Dev Service 2'
'Dev Service and Dev Service 2'
);
expect(downResponse.hits.hits[2]._source).property(
'linkMessage',
`- Link: https://localhost:5601/app/synthetics/monitor/${monitor.id}/errors/Test%20private%20location-18524a3d9a7-0?locationId=dev`
);
expect(downResponse.hits.hits[2]._source).property('locationId', 'dev | dev2');
expect(downResponse.hits.hits[2]._source).property('locationId', 'dev and dev2');
});

it('should trigger recovered alert when the location threshold is no longer met', async () => {
Expand Down Expand Up @@ -676,17 +676,17 @@ export default function ({ getService }: FtrProviderContext) {
});
expect(recoveryResponse.hits.hits[3]._source).property(
'reason',
`Monitor "${monitor.name}" from Dev Service | Dev Service 2 is recovered. Alert when 1 out of the last 1 checks are down from at least 2 locations.`
`Monitor "${monitor.name}" from Dev Service and Dev Service 2 is recovered. Alert when 1 out of the last 1 checks are down from at least 2 locations.`
);
expect(recoveryResponse.hits.hits[3]._source).property(
'locationNames',
'Dev Service | Dev Service 2'
'Dev Service and Dev Service 2'
);
expect(recoveryResponse.hits.hits[3]._source).property(
'linkMessage',
`- Link: https://localhost:5601/app/synthetics/monitor/${monitor.id}/errors/Test%20private%20location-18524a3d9a7-0?locationId=dev`
);
expect(recoveryResponse.hits.hits[3]._source).property('locationId', 'dev | dev2');
expect(recoveryResponse.hits.hits[3]._source).property('locationId', 'dev and dev2');
expect(recoveryResponse.hits.hits[3]._source).property(
'recoveryReason',
'the alert condition is no longer met'
Expand Down Expand Up @@ -875,7 +875,7 @@ export default function ({ getService }: FtrProviderContext) {
const alert: any = response.hits.hits?.[0]._source;
expect(alert).to.have.property('kibana.alert.status', 'active');
expect(alert['kibana.alert.reason']).to.eql(
`Monitor "${monitor.name}" is down 5 times from Dev Service | 5 times from Dev Service 2. Alert when down 5 times within the last 5 minutes from at least 2 locations.`
`Monitor "${monitor.name}" is down 5 times from Dev Service and 5 times from Dev Service 2. Alert when down 5 times within the last 5 minutes from at least 2 locations.`
);
const downResponse = await waitForDocumentInIndex<{
ruleType: string;
Expand All @@ -895,17 +895,17 @@ export default function ({ getService }: FtrProviderContext) {

expect(downResponse.hits.hits[0]._source).property(
'reason',
`Monitor "${monitor.name}" is down 5 times from Dev Service | 5 times from Dev Service 2. Alert when down 5 times within the last 5 minutes from at least 2 locations.`
`Monitor "${monitor.name}" is down 5 times from Dev Service and 5 times from Dev Service 2. Alert when down 5 times within the last 5 minutes from at least 2 locations.`
);
expect(downResponse.hits.hits[0]._source).property(
'locationNames',
'Dev Service | Dev Service 2'
'Dev Service and Dev Service 2'
);
expect(downResponse.hits.hits[0]._source).property(
'linkMessage',
`- Link: https://localhost:5601/app/synthetics/monitor/${monitor.id}/errors/Test%20private%20location-18524a3d9a7-0?locationId=dev`
);
expect(downResponse.hits.hits[0]._source).property('locationId', 'dev | dev2');
expect(downResponse.hits.hits[0]._source).property('locationId', 'dev and dev2');
});

it('should trigger alert action', async function () {
Expand All @@ -928,17 +928,17 @@ export default function ({ getService }: FtrProviderContext) {

expect(alertAction.hits.hits[0]._source).property(
'reason',
`Monitor "${monitor.name}" is down 5 times from Dev Service | 5 times from Dev Service 2. Alert when down 5 times within the last 5 minutes from at least 2 locations.`
`Monitor "${monitor.name}" is down 5 times from Dev Service and 5 times from Dev Service 2. Alert when down 5 times within the last 5 minutes from at least 2 locations.`
);
expect(alertAction.hits.hits[0]._source).property(
'locationNames',
'Dev Service | Dev Service 2'
'Dev Service and Dev Service 2'
);
expect(alertAction.hits.hits[0]._source).property(
'linkMessage',
`- Link: https://localhost:5601/app/synthetics/monitor/${monitor.id}/errors/Test%20private%20location-18524a3d9a7-0?locationId=dev`
);
expect(alertAction.hits.hits[0]._source).property('locationId', 'dev | dev2');
expect(alertAction.hits.hits[0]._source).property('locationId', 'dev and dev2');
});

it('should trigger recovered alert', async function () {
Expand Down Expand Up @@ -974,7 +974,7 @@ export default function ({ getService }: FtrProviderContext) {

expect(recoveryAction.hits.hits[1]._source).property(
'reason',
`Monitor "${monitor.name}" from Dev Service | Dev Service 2 is recovered. Alert when 5 checks are down within the last 5 minutes from at least 2 locations.`
`Monitor "${monitor.name}" from Dev Service and Dev Service 2 is recovered. Alert when 5 checks are down within the last 5 minutes from at least 2 locations.`
);
expect(recoveryAction.hits.hits[1]._source).property(
'recoveryReason',
Expand All @@ -983,13 +983,13 @@ export default function ({ getService }: FtrProviderContext) {
expect(recoveryAction.hits.hits[1]._source).property('recoveryStatus', 'has recovered');
expect(recoveryAction.hits.hits[1]._source).property(
'locationNames',
'Dev Service | Dev Service 2'
'Dev Service and Dev Service 2'
);
expect(recoveryAction.hits.hits[1]._source).property(
'linkMessage',
`- Link: https://localhost:5601/app/synthetics/monitor/${monitor.id}/errors/Test%20private%20location-18524a3d9a7-0?locationId=dev`
);
expect(recoveryAction.hits.hits[1]._source).property('locationId', 'dev | dev2');
expect(recoveryAction.hits.hits[1]._source).property('locationId', 'dev and dev2');
});
});

Expand Down

0 comments on commit cf339ed

Please sign in to comment.