From cdb5777fd2dda88aeeef86ec1b66919b14abd54d Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Mon, 23 Sep 2024 09:34:49 +0200 Subject: [PATCH 1/8] Update alertDetailsUrl --- .../anomaly/register_anomaly_rule_type.ts | 19 ++++++-------- .../register_error_count_rule_type.ts | 15 +++-------- ...gister_transaction_error_rate_rule_type.ts | 15 +++-------- .../inventory_metric_threshold_executor.ts | 26 +++---------------- .../metric_threshold_executor.ts | 20 +++----------- .../lib/rules/slo_burn_rate/executor.ts | 22 +++------------- .../alert_rules/tls_rule/message_utils.ts | 11 ++------ .../server/alert_rules/tls_rule/tls_rule.ts | 13 +++------- 8 files changed, 33 insertions(+), 108 deletions(-) diff --git a/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/anomaly/register_anomaly_rule_type.ts b/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/anomaly/register_anomaly_rule_type.ts index 4678622a7d1223..898829b7641744 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/anomaly/register_anomaly_rule_type.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/anomaly/register_anomaly_rule_type.ts @@ -18,7 +18,11 @@ import { import { KibanaRequest, DEFAULT_APP_CATEGORIES } from '@kbn/core/server'; import datemath from '@kbn/datemath'; import type { ESSearchResponse } from '@kbn/es-types'; -import { getAlertUrl, observabilityPaths, ProcessorEvent } from '@kbn/observability-plugin/common'; +import { + getAlertDetailsUrl, + observabilityPaths, + ProcessorEvent, +} from '@kbn/observability-plugin/common'; import { termQuery, termsQuery } from '@kbn/observability-plugin/server'; import { ALERT_EVALUATION_THRESHOLD, @@ -128,7 +132,7 @@ export function registerAnomalyRuleType({ return { state: {} }; } - const { params, services, spaceId, startedAt, getTimeRange } = options; + const { params, services, spaceId, getTimeRange } = options; const { alertsClient, savedObjectsClient, scopedClusterClient } = services; if (!alertsClient) { throw new AlertsClientError(); @@ -302,11 +306,10 @@ export function registerAnomalyRuleType({ const alertId = bucketKey.join('_'); - const { uuid, start } = alertsClient.report({ + const { uuid } = alertsClient.report({ id: alertId, actionGroup: ruleTypeConfig.defaultActionGroupId, }); - const indexedStartedAt = start ?? startedAt.toISOString(); const relativeViewInAppUrl = getAlertUrlTransaction( serviceName, @@ -318,13 +321,7 @@ export function registerAnomalyRuleType({ spaceId, relativeViewInAppUrl ); - const alertDetailsUrl = await getAlertUrl( - uuid, - spaceId, - indexedStartedAt, - alertsLocator, - basePath.publicBaseUrl - ); + const alertDetailsUrl = await getAlertDetailsUrl(basePath, spaceId, uuid); const payload = { [SERVICE_NAME]: serviceName, diff --git a/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/error_count/register_error_count_rule_type.ts b/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/error_count/register_error_count_rule_type.ts index d90aa0e143a143..4fffbd89999c5d 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/error_count/register_error_count_rule_type.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/error_count/register_error_count_rule_type.ts @@ -17,7 +17,7 @@ import { } from '@kbn/alerting-plugin/server'; import { formatDurationFromTimeUnitChar, - getAlertUrl, + getAlertDetailsUrl, observabilityPaths, ProcessorEvent, TimeUnitChar, @@ -127,7 +127,7 @@ export function registerErrorCountRuleType({ ErrorCountAlert > ) => { - const { params: ruleParams, services, spaceId, startedAt, getTimeRange } = options; + const { params: ruleParams, services, spaceId, getTimeRange } = options; const { alertsClient, savedObjectsClient, scopedClusterClient } = services; if (!alertsClient) { throw new AlertsClientError(); @@ -220,11 +220,10 @@ export function registerErrorCountRuleType({ groupByFields, }); - const { uuid, start } = alertsClient.report({ + const { uuid } = alertsClient.report({ id: alertId, actionGroup: ruleTypeConfig.defaultActionGroupId, }); - const indexedStartedAt = start ?? startedAt.toISOString(); const relativeViewInAppUrl = getAlertUrlErrorCount( groupByFields[SERVICE_NAME], @@ -235,13 +234,7 @@ export function registerErrorCountRuleType({ spaceId, relativeViewInAppUrl ); - const alertDetailsUrl = await getAlertUrl( - uuid, - spaceId, - indexedStartedAt, - alertsLocator, - basePath.publicBaseUrl - ); + const alertDetailsUrl = await getAlertDetailsUrl(basePath, spaceId, uuid); const groupByActionVariables = getGroupByActionVariables(groupByFields); const payload = { diff --git a/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/transaction_error_rate/register_transaction_error_rate_rule_type.ts b/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/transaction_error_rate/register_transaction_error_rate_rule_type.ts index 81b4612244b1bd..e6cb843a80b90f 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/transaction_error_rate/register_transaction_error_rate_rule_type.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/transaction_error_rate/register_transaction_error_rate_rule_type.ts @@ -17,7 +17,7 @@ import { } from '@kbn/alerting-plugin/server'; import { formatDurationFromTimeUnitChar, - getAlertUrl, + getAlertDetailsUrl, observabilityPaths, ProcessorEvent, TimeUnitChar, @@ -137,7 +137,7 @@ export function registerTransactionErrorRateRuleType({ TransactionErrorRateAlert > ) => { - const { services, spaceId, params: ruleParams, startedAt, getTimeRange } = options; + const { services, spaceId, params: ruleParams, getTimeRange } = options; const { alertsClient, savedObjectsClient, scopedClusterClient } = services; if (!alertsClient) { throw new AlertsClientError(); @@ -272,11 +272,10 @@ export function registerTransactionErrorRateRuleType({ groupByFields, }); - const { uuid, start } = alertsClient.report({ + const { uuid } = alertsClient.report({ id: alertId, actionGroup: ruleTypeConfig.defaultActionGroupId, }); - const indexedStartedAt = start ?? startedAt.toISOString(); const relativeViewInAppUrl = getAlertUrlTransaction( groupByFields[SERVICE_NAME], @@ -288,13 +287,7 @@ export function registerTransactionErrorRateRuleType({ spaceId, relativeViewInAppUrl ); - const alertDetailsUrl = await getAlertUrl( - uuid, - spaceId, - indexedStartedAt, - alertsLocator, - basePath.publicBaseUrl - ); + const alertDetailsUrl = await getAlertDetailsUrl(basePath, spaceId, uuid); const groupByActionVariables = getGroupByActionVariables(groupByFields); const payload = { diff --git a/x-pack/plugins/observability_solution/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts b/x-pack/plugins/observability_solution/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts index d4c5a3b25c902f..38bbe40e698552 100644 --- a/x-pack/plugins/observability_solution/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts +++ b/x-pack/plugins/observability_solution/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts @@ -21,7 +21,7 @@ import { AlertInstanceState as AlertState, } from '@kbn/alerting-plugin/common'; import { AlertsClientError, RuleExecutorOptions, RuleTypeState } from '@kbn/alerting-plugin/server'; -import { convertToBuiltInComparators, getAlertUrl } from '@kbn/observability-plugin/common'; +import { convertToBuiltInComparators, getAlertDetailsUrl } from '@kbn/observability-plugin/common'; import type { InventoryItemType, SnapshotMetricType } from '@kbn/metrics-data-access-plugin/common'; import { ObservabilityMetricsAlert } from '@kbn/alerts-as-data-utils'; import { getOriginalActionGroup } from '../../../utils/get_original_action_group'; @@ -140,13 +140,7 @@ export const createInventoryMetricThresholdExecutor = [ALERT_REASON]: reason, }, context: { - alertDetailsUrl: await getAlertUrl( - uuid, - spaceId, - indexedStartedAt, - alertsLocator, - libs.basePath.publicBaseUrl - ), + alertDetailsUrl: await getAlertDetailsUrl(libs.basePath, spaceId, uuid), alertState: stateToAlertMessage[AlertStates.ERROR], group: UNGROUPED_FACTORY_KEY, metric: mapToConditionsLookup(criteria, (c) => c.metric), @@ -292,13 +286,7 @@ export const createInventoryMetricThresholdExecutor = scheduledActionsCount++; const context = { - alertDetailsUrl: await getAlertUrl( - uuid, - spaceId, - indexedStartedAt, - alertsLocator, - libs.basePath.publicBaseUrl - ), + alertDetailsUrl: await getAlertDetailsUrl(libs.basePath, spaceId, uuid), alertState: stateToAlertMessage[nextState], group, reason, @@ -346,13 +334,7 @@ export const createInventoryMetricThresholdExecutor = const originalActionGroup = getOriginalActionGroup(alertHits); const recoveredContext = { - alertDetailsUrl: await getAlertUrl( - alertUuid, - spaceId, - indexedStartedAt, - alertsLocator, - libs.basePath.publicBaseUrl - ), + alertDetailsUrl: await getAlertDetailsUrl(libs.basePath, spaceId, alertUuid), alertState: stateToAlertMessage[AlertStates.OK], group: recoveredAlertId, metric: mapToConditionsLookup(criteria, (c) => c.metric), diff --git a/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts b/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts index a98253553e4f28..ff75a4b84c466e 100644 --- a/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts +++ b/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts @@ -20,7 +20,7 @@ import { RecoveredActionGroup, } from '@kbn/alerting-plugin/common'; import { AlertsClientError, RuleExecutorOptions, RuleTypeState } from '@kbn/alerting-plugin/server'; -import { TimeUnitChar, getAlertUrl } from '@kbn/observability-plugin/common'; +import { TimeUnitChar, getAlertDetailsUrl } from '@kbn/observability-plugin/common'; import { ObservabilityMetricsAlert } from '@kbn/alerts-as-data-utils'; import { COMPARATORS } from '@kbn/alerting-comparators'; import { getEcsGroups, type Group } from '@kbn/observability-alerting-rule-utils'; @@ -153,7 +153,7 @@ export const createMetricThresholdExecutor = groups, thresholds, }) => { - const { uuid, start } = alertsClient.report({ + const { uuid } = alertsClient.report({ id, actionGroup, }); @@ -170,13 +170,7 @@ export const createMetricThresholdExecutor = }, context: { ...contextWithoutAlertDetailsUrl, - alertDetailsUrl: await getAlertUrl( - uuid, - spaceId, - start ?? startedAt.toISOString(), - alertsLocator, - libs.basePath.publicBaseUrl - ), + alertDetailsUrl: await getAlertDetailsUrl(libs.basePath, spaceId, uuid), }, }); }; @@ -456,13 +450,7 @@ export const createMetricThresholdExecutor = const originalActionGroup = getOriginalActionGroup(alertHits); recoveredAlert.alert.setContext({ - alertDetailsUrl: await getAlertUrl( - alertUuid, - spaceId, - indexedStartedAt, - alertsLocator, - libs.basePath.publicBaseUrl - ), + alertDetailsUrl: await getAlertDetailsUrl(libs.basePath, spaceId, alertUuid), alertState: stateToAlertMessage[AlertStates.OK], group: recoveredAlertId, groupByKeys: groupByKeysObjectForRecovered[recoveredAlertId], diff --git a/x-pack/plugins/observability_solution/slo/server/lib/rules/slo_burn_rate/executor.ts b/x-pack/plugins/observability_solution/slo/server/lib/rules/slo_burn_rate/executor.ts index 6fbf8bcc0e8913..7671ed7ebbaa34 100644 --- a/x-pack/plugins/observability_solution/slo/server/lib/rules/slo_burn_rate/executor.ts +++ b/x-pack/plugins/observability_solution/slo/server/lib/rules/slo_burn_rate/executor.ts @@ -21,7 +21,7 @@ import { LocatorPublic } from '@kbn/share-plugin/common'; import { upperCase } from 'lodash'; import { addSpaceIdToPath } from '@kbn/spaces-plugin/server'; import { ALL_VALUE } from '@kbn/slo-schema'; -import { AlertsLocatorParams, getAlertUrl } from '@kbn/observability-plugin/common'; +import { AlertsLocatorParams, getAlertDetailsUrl } from '@kbn/observability-plugin/common'; import { ObservabilitySloAlert } from '@kbn/alerts-as-data-utils'; import { ExecutorType } from '@kbn/alerting-plugin/server'; import { @@ -171,7 +171,7 @@ export const getRuleExecutor = ({ ? SUPPRESSED_PRIORITY_ACTION.id : windowDef.actionGroup; - const { uuid, start } = alertsClient.report({ + const { uuid } = alertsClient.report({ id: alertId, actionGroup, state: { @@ -189,14 +189,7 @@ export const getRuleExecutor = ({ }, }); - const indexedStartedAt = start ?? startedAt.toISOString(); - const alertDetailsUrl = await getAlertUrl( - uuid, - spaceId, - indexedStartedAt, - alertsLocator, - basePath.publicBaseUrl - ); + const alertDetailsUrl = await getAlertDetailsUrl(basePath, spaceId, uuid); const context = { alertDetailsUrl, @@ -228,15 +221,8 @@ export const getRuleExecutor = ({ const recoveredAlerts = alertsClient.getRecoveredAlerts() ?? []; for (const recoveredAlert of recoveredAlerts) { const alertId = recoveredAlert.alert.getId(); - const indexedStartedAt = recoveredAlert.alert.getStart() ?? startedAt.toISOString(); const alertUuid = recoveredAlert.alert.getUuid(); - const alertDetailsUrl = await getAlertUrl( - alertUuid, - spaceId, - indexedStartedAt, - alertsLocator, - basePath.publicBaseUrl - ); + const alertDetailsUrl = await getAlertDetailsUrl(basePath, spaceId, alertUuid); const urlQuery = alertId === ALL_VALUE ? '' : `?instanceId=${alertId}`; const viewInAppUrl = addSpaceIdToPath( diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.ts index 5fc23a370caea4..fe252130046d18 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.ts @@ -8,7 +8,7 @@ import moment from 'moment/moment'; import { IBasePath } from '@kbn/core-http-server'; import { LocatorPublic } from '@kbn/share-plugin/common'; -import { AlertsLocatorParams, getAlertUrl } from '@kbn/observability-plugin/common'; +import { AlertsLocatorParams, getAlertDetailsUrl } from '@kbn/observability-plugin/common'; import { AlertInstanceContext as AlertContext, AlertInstanceState as AlertState, @@ -107,16 +107,9 @@ export const setTLSRecoveredAlertsContext = async ({ for (const recoveredAlert of recoveredAlerts) { const recoveredAlertId = recoveredAlert.alert.getId(); const alertUuid = recoveredAlert.alert.getUuid(); - const indexedStartedAt = recoveredAlert.alert.getStart() ?? defaultStartedAt; const state = recoveredAlert.alert.getState(); - const alertUrl = await getAlertUrl( - alertUuid, - spaceId, - indexedStartedAt, - alertsLocator, - basePath.publicBaseUrl - ); + const alertUrl = await getAlertDetailsUrl(basePath, spaceId, alertUuid); const configId = state.configId; const latestPing = latestPings.find((ping) => ping.config_id === configId); diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/tls_rule.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/tls_rule.ts index 3aaafcaf174681..5613338204f327 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/tls_rule.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/tls_rule.ts @@ -18,7 +18,7 @@ import { ALERT_REASON, ALERT_UUID } from '@kbn/rule-data-utils'; import { alertsLocatorID, AlertsLocatorParams, - getAlertUrl, + getAlertDetailsUrl, observabilityPaths, } from '@kbn/observability-plugin/common'; import { LocatorPublic } from '@kbn/share-plugin/common'; @@ -121,12 +121,11 @@ export const registerSyntheticsTLSCheckRule = ( } const alertId = cert.sha256; - const { uuid, start } = alertsClient.report({ + const { uuid } = alertsClient.report({ id: alertId, actionGroup: TLS_CERTIFICATE.id, state: { ...updateState(ruleState, foundCerts), ...summary }, }); - const indexedStartedAt = start ?? startedAt.toISOString(); const payload = { [CERT_COMMON_NAME]: cert.common_name, @@ -139,13 +138,7 @@ export const registerSyntheticsTLSCheckRule = ( }; const context = { - [ALERT_DETAILS_URL]: await getAlertUrl( - uuid, - spaceId, - indexedStartedAt, - alertsLocator, - basePath.publicBaseUrl - ), + [ALERT_DETAILS_URL]: await getAlertDetailsUrl(basePath, spaceId, uuid), ...summary, }; From 662bc6a98c850758cf6b9d2b63f837d7f16ddaa0 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Mon, 23 Sep 2024 09:54:25 +0200 Subject: [PATCH 2/8] Remove extra getAlertDetailsUrl --- .../synthetics/server/alert_rules/common.ts | 8 ++------ .../status_rule/monitor_status_rule.ts | 3 +-- .../alert_rules/tls_rule/message_utils.test.ts | 12 +----------- .../server/alert_rules/tls_rule/message_utils.ts | 7 +------ .../server/alert_rules/tls_rule/tls_rule.ts | 16 +++------------- 5 files changed, 8 insertions(+), 38 deletions(-) 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 20c84109b0be19..6a8aebfc7378c5 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 @@ -4,6 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ + import moment, { Moment } from 'moment'; import { isRight } from 'fp-ts/lib/Either'; import Mustache from 'mustache'; @@ -14,6 +15,7 @@ import { AlertInstanceContext as AlertContext, AlertInstanceState as AlertState, } from '@kbn/alerting-plugin/server'; +import { getAlertDetailsUrl } from '@kbn/observability-plugin/common'; import { addSpaceIdToPath } from '@kbn/spaces-plugin/common'; import { i18n } from '@kbn/i18n'; import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query'; @@ -113,12 +115,6 @@ export const getViewInAppUrl = ( relativeViewInAppUrl: string ) => addSpaceIdToPath(basePath.publicBaseUrl, spaceId, relativeViewInAppUrl); -export const getAlertDetailsUrl = ( - basePath: IBasePath, - spaceId: string, - alertUuid: string | null -) => addSpaceIdToPath(basePath.publicBaseUrl, spaceId, `/app/observability/alerts/${alertUuid}`); - export const getRelativeViewInAppUrl = ({ configId, stateId, diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/monitor_status_rule.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/monitor_status_rule.ts index c823abe7d083fa..f6e867c350c6c1 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/monitor_status_rule.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/status_rule/monitor_status_rule.ts @@ -14,7 +14,7 @@ import { RuleExecutorOptions, AlertsClientError, } from '@kbn/alerting-plugin/server'; -import { observabilityPaths } from '@kbn/observability-plugin/common'; +import { getAlertDetailsUrl, observabilityPaths } from '@kbn/observability-plugin/common'; import { ObservabilityUptimeAlert } from '@kbn/alerts-as-data-utils'; import { syntheticsRuleFieldMap } from '../../../common/rules/synthetics_rule_field_map'; import { SyntheticsPluginsSetupDependencies, SyntheticsServerSetup } from '../../types'; @@ -33,7 +33,6 @@ import { import { setRecoveredAlertsContext, updateState, - getAlertDetailsUrl, getViewInAppUrl, getRelativeViewInAppUrl, getFullViewInAppMessage, diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.test.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.test.ts index e07ba00c1de6c0..39fa7b185fb8d9 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.test.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.test.ts @@ -4,9 +4,8 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ + import { IBasePath } from '@kbn/core/server'; -import { AlertsLocatorParams } from '@kbn/observability-plugin/common'; -import { LocatorPublic } from '@kbn/share-plugin/common'; import { setTLSRecoveredAlertsContext } from './message_utils'; import { TLSLatestPing } from './tls_rule_executor'; @@ -17,11 +16,6 @@ describe('setTLSRecoveredAlertsContext', () => { const basePath = { publicBaseUrl: 'https://localhost:5601', } as IBasePath; - const alertsLocatorMock = { - getLocation: jest.fn().mockImplementation(() => ({ - path: 'https://localhost:5601/app/observability/alerts/alert-id', - })), - } as any as LocatorPublic; const alertState = { summary: 'test-summary', status: 'has expired', @@ -57,9 +51,7 @@ describe('setTLSRecoveredAlertsContext', () => { await setTLSRecoveredAlertsContext({ alertsClient: alertsClientMock, basePath, - defaultStartedAt: timestamp, spaceId: 'default', - alertsLocator: alertsLocatorMock, latestPings: [ { config_id: configId, @@ -122,9 +114,7 @@ describe('setTLSRecoveredAlertsContext', () => { await setTLSRecoveredAlertsContext({ alertsClient: alertsClientMock, basePath, - defaultStartedAt: timestamp, spaceId: 'default', - alertsLocator: alertsLocatorMock, latestPings: [ { config_id: configId, diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.ts index fe252130046d18..3f0650f12ee8b2 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/message_utils.ts @@ -7,8 +7,7 @@ import moment from 'moment/moment'; import { IBasePath } from '@kbn/core-http-server'; -import { LocatorPublic } from '@kbn/share-plugin/common'; -import { AlertsLocatorParams, getAlertDetailsUrl } from '@kbn/observability-plugin/common'; +import { getAlertDetailsUrl } from '@kbn/observability-plugin/common'; import { AlertInstanceContext as AlertContext, AlertInstanceState as AlertState, @@ -85,9 +84,7 @@ export const getCertSummary = (cert: Cert, expirationThreshold: number, ageThres export const setTLSRecoveredAlertsContext = async ({ alertsClient, basePath, - defaultStartedAt, spaceId, - alertsLocator, latestPings, }: { alertsClient: PublicAlertsClient< @@ -96,10 +93,8 @@ export const setTLSRecoveredAlertsContext = async ({ AlertContext, ActionGroupIdsOf >; - defaultStartedAt: string; basePath: IBasePath; spaceId: string; - alertsLocator?: LocatorPublic; latestPings: TLSLatestPing[]; }) => { const recoveredAlerts = alertsClient.getRecoveredAlerts() ?? []; diff --git a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/tls_rule.ts b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/tls_rule.ts index 5613338204f327..1339aeac89ad39 100644 --- a/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/tls_rule.ts +++ b/x-pack/plugins/observability_solution/synthetics/server/alert_rules/tls_rule/tls_rule.ts @@ -15,13 +15,7 @@ import { } from '@kbn/alerting-plugin/server'; import { asyncForEach } from '@kbn/std'; import { ALERT_REASON, ALERT_UUID } from '@kbn/rule-data-utils'; -import { - alertsLocatorID, - AlertsLocatorParams, - getAlertDetailsUrl, - observabilityPaths, -} from '@kbn/observability-plugin/common'; -import { LocatorPublic } from '@kbn/share-plugin/common'; +import { getAlertDetailsUrl, observabilityPaths } from '@kbn/observability-plugin/common'; import { schema } from '@kbn/config-schema'; import { ObservabilityUptimeAlert } from '@kbn/alerts-as-data-utils'; import { syntheticsRuleFieldMap } from '../../../common/rules/synthetics_rule_field_map'; @@ -92,14 +86,12 @@ export const registerSyntheticsTLSCheckRule = ( TLSAlert > ) => { - const { state: ruleState, params, services, spaceId, previousStartedAt, startedAt } = options; + const { state: ruleState, params, services, spaceId, previousStartedAt } = options; const { alertsClient, savedObjectsClient, scopedClusterClient } = services; if (!alertsClient) { throw new AlertsClientError(); } - const { basePath, share } = server; - const alertsLocator: LocatorPublic | undefined = - share.url.locators.get(alertsLocatorID); + const { basePath } = server; const tlsRule = new TLSRuleExecutor( previousStartedAt, @@ -152,9 +144,7 @@ export const registerSyntheticsTLSCheckRule = ( await setTLSRecoveredAlertsContext({ alertsClient, basePath, - defaultStartedAt: startedAt.toISOString(), spaceId, - alertsLocator, latestPings, }); From 0f62eea59f835695e9980be23cbb6ff778f23816 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Mon, 23 Sep 2024 12:13:58 +0200 Subject: [PATCH 3/8] Fix SLO test --- .../lib/rules/slo_burn_rate/executor.test.ts | 40 ++----------------- 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/x-pack/plugins/observability_solution/slo/server/lib/rules/slo_burn_rate/executor.test.ts b/x-pack/plugins/observability_solution/slo/server/lib/rules/slo_burn_rate/executor.test.ts index 28fdae0c12f38a..32090cf88390c8 100644 --- a/x-pack/plugins/observability_solution/slo/server/lib/rules/slo_burn_rate/executor.test.ts +++ b/x-pack/plugins/observability_solution/slo/server/lib/rules/slo_burn_rate/executor.test.ts @@ -25,9 +25,7 @@ import { import { ISearchStartSearchSource } from '@kbn/data-plugin/public'; import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks'; import { MockedLogger } from '@kbn/logging-mocks'; -import { AlertsLocatorParams } from '@kbn/observability-plugin/common'; import { Rule } from '@kbn/alerting-plugin/common'; -import { LocatorPublic } from '@kbn/share-plugin/common'; import { SharePluginStart } from '@kbn/share-plugin/server'; import { sloDefinitionSchema } from '@kbn/slo-schema'; import { get } from 'lodash'; @@ -148,13 +146,6 @@ describe('BurnRateRuleExecutor', () => { let soClientMock: jest.Mocked; let loggerMock: jest.Mocked; const basePathMock = { publicBaseUrl: 'https://kibana.dev' } as IBasePath; - const alertsLocatorMock = { - getLocation: jest.fn().mockImplementation(() => ({ - path: 'mockedAlertsLocator > getLocation', - })), - } as any as LocatorPublic; - const ISO_DATE_REGEX = - /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)((-(\d{2}):(\d{2})|Z)?)$/; let searchSourceClientMock: jest.Mocked; let uiSettingsClientMock: jest.Mocked; @@ -375,7 +366,6 @@ describe('BurnRateRuleExecutor', () => { const executor = getRuleExecutor({ basePath: basePathMock, - alertsLocator: alertsLocatorMock, }); await executor({ @@ -456,7 +446,7 @@ describe('BurnRateRuleExecutor', () => { burnRateThreshold: 2, reason: 'CRITICAL: The burn rate for the past 1h is 2.3 and for the past 5m is 2.1 for foo,asia. Alert when above 2 for both windows', - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'https://kibana.dev/s/irrelevant/app/observability/alerts/uuid-foo,asia', }), }); expect(servicesMock.alertsClient?.setAlertData).toHaveBeenNthCalledWith(2, { @@ -467,23 +457,9 @@ describe('BurnRateRuleExecutor', () => { burnRateThreshold: 2, reason: 'CRITICAL: The burn rate for the past 1h is 2.5 and for the past 5m is 2.2 for bar,asia. Alert when above 2 for both windows', - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'https://kibana.dev/s/irrelevant/app/observability/alerts/uuid-bar,asia', }), }); - - expect(alertsLocatorMock.getLocation).toHaveBeenCalledTimes(2); - expect(alertsLocatorMock.getLocation).toHaveBeenNthCalledWith(1, { - baseUrl: 'https://kibana.dev', - kuery: 'kibana.alert.uuid: "uuid-foo,asia"', - rangeFrom: expect.stringMatching(ISO_DATE_REGEX), - spaceId: 'irrelevant', - }); - expect(alertsLocatorMock.getLocation).toHaveBeenNthCalledWith(2, { - baseUrl: 'https://kibana.dev', - kuery: 'kibana.alert.uuid: "uuid-bar,asia"', - rangeFrom: expect.stringMatching(ISO_DATE_REGEX), - spaceId: 'irrelevant', - }); }); it('schedules a suppressed alert when both windows of first window definition burn rate have reached the threshold but the dependency matches', async () => { @@ -539,7 +515,6 @@ describe('BurnRateRuleExecutor', () => { const executor = getRuleExecutor({ basePath: basePathMock, - alertsLocator: alertsLocatorMock, }); await executor({ @@ -609,7 +584,7 @@ describe('BurnRateRuleExecutor', () => { burnRateThreshold: 2, reason: 'SUPPRESSED - CRITICAL: The burn rate for the past 1h is 2.3 and for the past 5m is 2.1 for foo. Alert when above 2 for both windows', - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'https://kibana.dev/s/irrelevant/app/observability/alerts/uuid-foo', }), }); expect(servicesMock.alertsClient?.setAlertData).toHaveBeenNthCalledWith(2, { @@ -620,16 +595,9 @@ describe('BurnRateRuleExecutor', () => { burnRateThreshold: 2, reason: 'SUPPRESSED - CRITICAL: The burn rate for the past 1h is 2.5 and for the past 5m is 2.2 for bar. Alert when above 2 for both windows', - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'https://kibana.dev/s/irrelevant/app/observability/alerts/uuid-bar', }), }); - - expect(alertsLocatorMock.getLocation).toBeCalledWith({ - baseUrl: 'https://kibana.dev', - kuery: 'kibana.alert.uuid: "uuid-foo"', - rangeFrom: expect.stringMatching(ISO_DATE_REGEX), - spaceId: 'irrelevant', - }); }); it('schedules an alert when both windows of second window definition burn rate have reached the threshold', async () => { From 26397185f958c85492d32ad0b57c63d90f23fbe9 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Mon, 23 Sep 2024 12:16:47 +0200 Subject: [PATCH 4/8] Fix APM error count test --- .../register_error_count_rule_type.test.ts | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/error_count/register_error_count_rule_type.test.ts b/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/error_count/register_error_count_rule_type.test.ts index 2115a517beedf7..a27b0ca78e510d 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/error_count/register_error_count_rule_type.test.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/error_count/register_error_count_rule_type.test.ts @@ -142,7 +142,7 @@ describe('Error count alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo', errorGroupingKey: undefined, interval: '5 mins', @@ -167,7 +167,7 @@ describe('Error count alert', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo-2', errorGroupingKey: undefined, interval: '5 mins', @@ -192,7 +192,7 @@ describe('Error count alert', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-bar', errorGroupingKey: undefined, interval: '5 mins', @@ -283,7 +283,7 @@ describe('Error count alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo', errorGroupingKey: undefined, interval: '5 mins', @@ -310,7 +310,7 @@ describe('Error count alert', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo-2', errorGroupingKey: undefined, interval: '5 mins', @@ -337,7 +337,7 @@ describe('Error count alert', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-bar', errorGroupingKey: undefined, interval: '5 mins', @@ -433,7 +433,7 @@ describe('Error count alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo', errorGroupingKey: 'error-key-foo', interval: '5 mins', @@ -458,7 +458,7 @@ describe('Error count alert', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo-2', errorGroupingKey: 'error-key-foo-2', interval: '5 mins', @@ -483,7 +483,7 @@ describe('Error count alert', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-bar', errorGroupingKey: 'error-key-bar', interval: '5 mins', @@ -573,7 +573,7 @@ describe('Error count alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo', errorGroupingKey: undefined, interval: '5 mins', @@ -598,7 +598,7 @@ describe('Error count alert', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo-2', errorGroupingKey: undefined, interval: '5 mins', @@ -623,7 +623,7 @@ describe('Error count alert', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-bar', errorGroupingKey: undefined, interval: '5 mins', @@ -714,7 +714,7 @@ describe('Error count alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'Not defined', errorGroupingKey: undefined, interval: '5 mins', @@ -740,7 +740,7 @@ describe('Error count alert', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'Not defined', errorGroupingKey: undefined, interval: '5 mins', @@ -766,7 +766,7 @@ describe('Error count alert', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-bar', errorGroupingKey: undefined, interval: '5 mins', @@ -860,7 +860,7 @@ describe('Error count alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo', errorGroupingKey: 'error-key-foo', errorGroupingName: 'error-name-foo', @@ -887,7 +887,7 @@ describe('Error count alert', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo-2', errorGroupingKey: 'error-key-foo-2', errorGroupingName: 'error-name-foo2', @@ -914,7 +914,7 @@ describe('Error count alert', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-bar', errorGroupingKey: 'error-key-bar', errorGroupingName: 'error-name-bar', @@ -1001,7 +1001,7 @@ describe('Error count alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo', errorGroupingKey: undefined, interval: '5 mins', From 2abb3d3664bcefccb202787136b9899f398c9cc1 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Mon, 23 Sep 2024 12:22:56 +0200 Subject: [PATCH 5/8] Fix APM tests --- .../anomaly/register_anomaly_rule_type.test.ts | 2 +- .../register_transaction_error_rate_rule_type.test.ts | 10 +++++----- .../apm/server/routes/alerts/test_utils/index.ts | 7 ------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/anomaly/register_anomaly_rule_type.test.ts b/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/anomaly/register_anomaly_rule_type.test.ts index 5649af59ce4e0e..e5fc1a41abdfd5 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/anomaly/register_anomaly_rule_type.test.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/anomaly/register_anomaly_rule_type.test.ts @@ -217,7 +217,7 @@ describe('Transaction duration anomaly alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'development', reason: 'critical latency anomaly with a score of 80, was detected in the last 5 mins for foo.', diff --git a/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/transaction_error_rate/register_transaction_error_rate_rule_type.test.ts b/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/transaction_error_rate/register_transaction_error_rate_rule_type.test.ts index 382cc9f53767e1..98eda3ef9e9042 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/transaction_error_rate/register_transaction_error_rate_rule_type.test.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/alerts/rule_types/transaction_error_rate/register_transaction_error_rate_rule_type.test.ts @@ -129,7 +129,7 @@ describe('Transaction error rate alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo', interval: '5 mins', reason: @@ -242,7 +242,7 @@ describe('Transaction error rate alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo', interval: '5 mins', reason: @@ -355,7 +355,7 @@ describe('Transaction error rate alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-foo', interval: '5 mins', reason: @@ -468,7 +468,7 @@ describe('Transaction error rate alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'Not defined', interval: '5 mins', reason: @@ -569,7 +569,7 @@ describe('Transaction error rate alert', () => { expect(services.alertsClient.setAlertData).toHaveBeenCalledWith({ context: { - alertDetailsUrl: 'mockedAlertsLocator > getLocation', + alertDetailsUrl: 'http://localhost:5601/eyr/app/observability/alerts/test-uuid', environment: 'env-bar', interval: '5 mins', reason: diff --git a/x-pack/plugins/observability_solution/apm/server/routes/alerts/test_utils/index.ts b/x-pack/plugins/observability_solution/apm/server/routes/alerts/test_utils/index.ts index 1f8ddeaff4620a..3a1765bb1b3bdb 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/alerts/test_utils/index.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/alerts/test_utils/index.ts @@ -7,8 +7,6 @@ import { IBasePath, Logger } from '@kbn/core/server'; import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; -import type { AlertsLocatorParams } from '@kbn/observability-plugin/common'; -import { LocatorPublic } from '@kbn/share-plugin/common'; import { IRuleDataClient } from '@kbn/rule-registry-plugin/server'; import { ruleRegistryMocks } from '@kbn/rule-registry-plugin/server/mocks'; import { PluginSetupContract as AlertingPluginSetupContract } from '@kbn/alerting-plugin/server'; @@ -77,11 +75,6 @@ export const createRuleTypeMocks = () => { ruleDataClient: ruleRegistryMocks.createRuleDataClient( '.alerts-observability.apm.alerts' ) as IRuleDataClient, - alertsLocator: { - getLocation: jest.fn().mockImplementation(() => ({ - path: 'mockedAlertsLocator > getLocation', - })), - } as any as LocatorPublic, } as unknown as RegisterRuleDependencies; return { From 7f039129b8d953c1bc29ddb2408a49ac95e4b4fe Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Mon, 23 Sep 2024 16:27:59 +0200 Subject: [PATCH 6/8] Fix metric threshold related tests --- .../alerting/metric_threshold/metric_threshold_executor.test.ts | 2 +- .../observability/metric_threshold_rule.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts b/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts index 47266cee5ec062..9777f7ceda4761 100644 --- a/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts +++ b/x-pack/plugins/observability_solution/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts @@ -2384,7 +2384,7 @@ describe('The metric threshold rule type', () => { }); expect(services.alertsClient.setAlertData).toHaveBeenNthCalledWith(index, { context: { - alertDetailsUrl: '', + alertDetailsUrl: `http://localhost:5601/app/observability/alerts/uuid-${id}`, alertState, group: id, reason, diff --git a/x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts b/x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts index bc36566f91f52d..b7e633ae8df8a6 100644 --- a/x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts +++ b/x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts @@ -224,7 +224,7 @@ export default function ({ getService }: FtrProviderContext) { expect(resp.hits.hits[0]._source?.ruleType).eql('metrics.alert.threshold'); expect(resp.hits.hits[0]._source?.alertDetailsUrl).eql( - `https://localhost:5601/app/observability/alerts?_a=(kuery:%27kibana.alert.uuid:%20%22${alertId}%22%27%2CrangeFrom:%27${rangeFrom}%27%2CrangeTo:now%2Cstatus:all)` + `https://localhost:5601/app/observability/alerts/${alertId}` ); expect(resp.hits.hits[0]._source?.reason).eql( `system.cpu.user.pct is 90% in the last 5 mins. Alert when above 50%.` From 96ab532a4397e5e17414171db0758130c8aaec8d Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Mon, 23 Sep 2024 18:09:39 +0200 Subject: [PATCH 7/8] Remove unused var --- .../observability/metric_threshold_rule.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts b/x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts index b7e633ae8df8a6..8e86374060c176 100644 --- a/x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts +++ b/x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts @@ -5,7 +5,6 @@ * 2.0. */ -import moment from 'moment'; import expect from '@kbn/expect'; import { cleanup, generate, Dataset, PartialConfig } from '@kbn/data-forge'; import { @@ -210,7 +209,6 @@ export default function ({ getService }: FtrProviderContext) { }); it('should set correct action parameter: ruleType', async () => { - const rangeFrom = moment(startedAt).subtract('5', 'minute').toISOString(); const resp = await waitForDocumentInIndex<{ ruleType: string; alertDetailsUrl: string; From eee6f610ccf89ce27db6783369e178d04c7b7d09 Mon Sep 17 00:00:00 2001 From: Maryam Saeidi Date: Tue, 24 Sep 2024 09:51:07 +0200 Subject: [PATCH 8/8] Remove unused variable --- .../observability/metric_threshold_rule.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts b/x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts index 8e86374060c176..4a1459d350ea66 100644 --- a/x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts +++ b/x-pack/test/alerting_api_integration/observability/metric_threshold_rule.ts @@ -32,7 +32,6 @@ export default function ({ getService }: FtrProviderContext) { describe('Metric threshold rule >', () => { let ruleId: string; let alertId: string; - let startedAt: string; let actionId: string; let dataForgeConfig: PartialConfig; let dataForgeIndices: string[]; @@ -158,7 +157,6 @@ export default function ({ getService }: FtrProviderContext) { logger, }); alertId = (resp.hits.hits[0]._source as any)['kibana.alert.uuid']; - startedAt = (resp.hits.hits[0]._source as any)['kibana.alert.start']; expect(resp.hits.hits[0]._source).property( 'kibana.alert.rule.category', 'Metric threshold'