Skip to content

Commit

Permalink
Remove extra getAlertDetailsUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
maryam-saeidi committed Sep 23, 2024
1 parent cdb5777 commit 662bc6a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -33,7 +33,6 @@ import {
import {
setRecoveredAlertsContext,
updateState,
getAlertDetailsUrl,
getViewInAppUrl,
getRelativeViewInAppUrl,
getFullViewInAppMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<AlertsLocatorParams>;
const alertState = {
summary: 'test-summary',
status: 'has expired',
Expand Down Expand Up @@ -57,9 +51,7 @@ describe('setTLSRecoveredAlertsContext', () => {
await setTLSRecoveredAlertsContext({
alertsClient: alertsClientMock,
basePath,
defaultStartedAt: timestamp,
spaceId: 'default',
alertsLocator: alertsLocatorMock,
latestPings: [
{
config_id: configId,
Expand Down Expand Up @@ -122,9 +114,7 @@ describe('setTLSRecoveredAlertsContext', () => {
await setTLSRecoveredAlertsContext({
alertsClient: alertsClientMock,
basePath,
defaultStartedAt: timestamp,
spaceId: 'default',
alertsLocator: alertsLocatorMock,
latestPings: [
{
config_id: configId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -85,9 +84,7 @@ export const getCertSummary = (cert: Cert, expirationThreshold: number, ageThres
export const setTLSRecoveredAlertsContext = async ({
alertsClient,
basePath,
defaultStartedAt,
spaceId,
alertsLocator,
latestPings,
}: {
alertsClient: PublicAlertsClient<
Expand All @@ -96,10 +93,8 @@ export const setTLSRecoveredAlertsContext = async ({
AlertContext,
ActionGroupIdsOf<MonitorStatusActionGroup>
>;
defaultStartedAt: string;
basePath: IBasePath;
spaceId: string;
alertsLocator?: LocatorPublic<AlertsLocatorParams>;
latestPings: TLSLatestPing[];
}) => {
const recoveredAlerts = alertsClient.getRecoveredAlerts() ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<AlertsLocatorParams> | undefined =
share.url.locators.get(alertsLocatorID);
const { basePath } = server;

const tlsRule = new TLSRuleExecutor(
previousStartedAt,
Expand Down Expand Up @@ -152,9 +144,7 @@ export const registerSyntheticsTLSCheckRule = (
await setTLSRecoveredAlertsContext({
alertsClient,
basePath,
defaultStartedAt: startedAt.toISOString(),
spaceId,
alertsLocator,
latestPings,
});

Expand Down

0 comments on commit 662bc6a

Please sign in to comment.