Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] [Alert details page] Update alertDetailsUrl context variable URL (#193674) #193920

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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