From cf339ed630d4ff79b7ff84a601fc656192e421ba Mon Sep 17 00:00:00 2001 From: shahzad31 Date: Fri, 27 Sep 2024 17:10:20 +0200 Subject: [PATCH] update api test --- .../custom_status_alert.journey.ts | 2 +- .../server/alert_rules/common.test.ts | 14 +++--- .../synthetics/server/alert_rules/common.ts | 4 +- .../alert_rules/status_rule/message_utils.ts | 8 ++-- .../synthetics/custom_status_rule.ts | 48 +++++++++---------- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/journeys/alert_rules/custom_status_alert.journey.ts b/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/journeys/alert_rules/custom_status_alert.journey.ts index c7ac484429f7db..161a58d650e6c9 100644 --- a/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/journeys/alert_rules/custom_status_alert.journey.ts +++ b/x-pack/plugins/observability_solution/synthetics/e2e/synthetics/journeys/alert_rules/custom_status_alert.journey.ts @@ -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: { diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/common.test.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/common.test.ts index 578e6887f8b92b..34f3be6128a3f9 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/common.test.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/common.test.ts @@ -622,7 +622,7 @@ 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', @@ -630,12 +630,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', }, @@ -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', }, diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/common.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/common.ts index 623f07e9839172..c1bf18e18e90ba 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/common.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/common.ts @@ -262,7 +262,7 @@ export const setRecoveredAlertsContext = ({ const context = { ...alertState, ...(monitorSummary ? monitorSummary : {}), - locationId: locationIds.join(' | '), + locationId: locationIds.join(` ${AND_LABEL} `), idWithLocation: recoveredAlertId, lastErrorMessage, recoveryStatus, @@ -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', }); diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/message_utils.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/message_utils.ts index f73aeeeb8bedc5..a0a14ddaebfed2 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/message_utils.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/message_utils.ts @@ -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 { @@ -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') @@ -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', @@ -190,7 +190,7 @@ export const getUngroupedReasonMessage = ({ } ); }) - .join(' | '), + .join(` ${AND_LABEL} `), }, } ); diff --git a/x-pack/test/alerting_api_integration/observability/synthetics/custom_status_rule.ts b/x-pack/test/alerting_api_integration/observability/synthetics/custom_status_rule.ts index d13d713d4f76eb..6600054e03ab93 100644 --- a/x-pack/test/alerting_api_integration/observability/synthetics/custom_status_rule.ts +++ b/x-pack/test/alerting_api_integration/observability/synthetics/custom_status_rule.ts @@ -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; @@ -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 () => { @@ -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[] = []; @@ -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; @@ -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 () => { @@ -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' @@ -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; @@ -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 () { @@ -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 () { @@ -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', @@ -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'); }); });