Skip to content

Commit

Permalink
[8.x] [Alert details page] Update alertDetailsUrl context variable URL (
Browse files Browse the repository at this point in the history
#193674) (#193920)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Alert details page] Update alertDetailsUrl context variable URL
(#193674)](#193674)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Maryam
Saeidi","email":"maryam.saeidi@elastic.co"},"sourceCommit":{"committedDate":"2024-09-24T20:02:14Z","message":"[Alert
details page] Update alertDetailsUrl context variable URL
(#193674)\n\nCloses #180889\r\n\r\n## Summary\r\n\r\nUpdate the
alertDetailsUrl context variable for the following rules:\r\n\r\n-
Inventory rule\r\n- Metric threshold rule\r\n- Error count threshold
rule\r\n- Failed transaction rate threshold rule\r\n- APM Anomaly
rule\r\n- Synthetics TLS rule\r\n- Synthetics monitor status
rule","sha":"09082f2d3e751776c8546e31cdad95db11cab8d5","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-infra_services","Team:obs-ux-management","apm:review"],"title":"[Alert
details page] Update alertDetailsUrl context variable
URL","number":193674,"url":"https://github.com/elastic/kibana/pull/193674","mergeCommit":{"message":"[Alert
details page] Update alertDetailsUrl context variable URL
(#193674)\n\nCloses #180889\r\n\r\n## Summary\r\n\r\nUpdate the
alertDetailsUrl context variable for the following rules:\r\n\r\n-
Inventory rule\r\n- Metric threshold rule\r\n- Error count threshold
rule\r\n- Failed transaction rate threshold rule\r\n- APM Anomaly
rule\r\n- Synthetics TLS rule\r\n- Synthetics monitor status
rule","sha":"09082f2d3e751776c8546e31cdad95db11cab8d5"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193674","number":193674,"mergeCommit":{"message":"[Alert
details page] Update alertDetailsUrl context variable URL
(#193674)\n\nCloses #180889\r\n\r\n## Summary\r\n\r\nUpdate the
alertDetailsUrl context variable for the following rules:\r\n\r\n-
Inventory rule\r\n- Metric threshold rule\r\n- Error count threshold
rule\r\n- Failed transaction rate threshold rule\r\n- APM Anomaly
rule\r\n- Synthetics TLS rule\r\n- Synthetics monitor status
rule","sha":"09082f2d3e751776c8546e31cdad95db11cab8d5"}}]}] BACKPORT-->

Co-authored-by: Maryam Saeidi <maryam.saeidi@elastic.co>
  • Loading branch information
kibanamachine and maryam-saeidi authored Sep 24, 2024
1 parent bdfccd2 commit 74a099c
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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, uiSettingsClient } = services;
if (!alertsClient) {
throw new AlertsClientError();
Expand Down Expand Up @@ -303,11 +307,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,
Expand All @@ -319,13 +322,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@kbn/alerting-plugin/server';
import {
formatDurationFromTimeUnitChar,
getAlertUrl,
getAlertDetailsUrl,
observabilityPaths,
ProcessorEvent,
TimeUnitChar,
Expand Down Expand Up @@ -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, uiSettingsClient } = services;
if (!alertsClient) {
throw new AlertsClientError();
Expand Down Expand Up @@ -221,11 +221,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],
Expand All @@ -236,13 +235,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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@kbn/alerting-plugin/server';
import {
formatDurationFromTimeUnitChar,
getAlertUrl,
getAlertDetailsUrl,
observabilityPaths,
ProcessorEvent,
TimeUnitChar,
Expand Down Expand Up @@ -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, uiSettingsClient } = services;
if (!alertsClient) {
throw new AlertsClientError();
Expand Down Expand Up @@ -273,11 +273,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],
Expand All @@ -289,13 +288,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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -80,11 +78,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<AlertsLocatorParams>,
} as unknown as RegisterRuleDependencies;

return {
Expand Down
Loading

0 comments on commit 74a099c

Please sign in to comment.