Configure "View rule in Kibana" Url for Observability rule types (#163292)

Closes #163168

## Summary

This PR configures the "View rule in Kibana" URL to point to the
observability rule details for observability rule types.


![image](58e625a4-eb8f-491b-962f-30a0e3950fb1)
This commit is contained in:
Maryam Saeidi 2023-08-11 09:09:35 +02:00 committed by GitHub
parent 5e49bfd9fc
commit feb249314b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 80 additions and 11 deletions

View file

@ -4,11 +4,17 @@
* 2.0; you may not use this file except in compliance with the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License
* 2.0. * 2.0.
*/ */
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import { KibanaRequest } from '@kbn/core/server'; import { KibanaRequest } from '@kbn/core/server';
import datemath from '@kbn/datemath'; import datemath from '@kbn/datemath';
import type { ESSearchResponse } from '@kbn/es-types'; import type { ESSearchResponse } from '@kbn/es-types';
import { getAlertUrl, ProcessorEvent } from '@kbn/observability-plugin/common'; import {
getAlertUrl,
observabilityPaths,
ProcessorEvent,
} from '@kbn/observability-plugin/common';
import { termQuery } from '@kbn/observability-plugin/server'; import { termQuery } from '@kbn/observability-plugin/server';
import { import {
ALERT_EVALUATION_THRESHOLD, ALERT_EVALUATION_THRESHOLD,
@ -329,6 +335,8 @@ export function registerAnomalyRuleType({
return { state: {} }; return { state: {} };
}, },
alerts: ApmRuleTypeAlertDefinition, alerts: ApmRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}) })
); );
} }

View file

@ -5,9 +5,11 @@
* 2.0. * 2.0.
*/ */
import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import { import {
formatDurationFromTimeUnitChar, formatDurationFromTimeUnitChar,
getAlertUrl, getAlertUrl,
observabilityPaths,
ProcessorEvent, ProcessorEvent,
TimeUnitChar, TimeUnitChar,
} from '@kbn/observability-plugin/common'; } from '@kbn/observability-plugin/common';
@ -254,6 +256,8 @@ export function registerErrorCountRuleType({
return { state: {} }; return { state: {} };
}, },
alerts: ApmRuleTypeAlertDefinition, alerts: ApmRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}) })
); );
} }

View file

@ -6,10 +6,12 @@
*/ */
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import { import {
asDuration, asDuration,
formatDurationFromTimeUnitChar, formatDurationFromTimeUnitChar,
getAlertDetailsUrl, getAlertDetailsUrl,
observabilityPaths,
ProcessorEvent, ProcessorEvent,
TimeUnitChar, TimeUnitChar,
} from '@kbn/observability-plugin/common'; } from '@kbn/observability-plugin/common';
@ -298,6 +300,8 @@ export function registerTransactionDurationRuleType({
return { state: {} }; return { state: {} };
}, },
alerts: ApmRuleTypeAlertDefinition, alerts: ApmRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}); });
alerting.registerType(ruleType); alerting.registerType(ruleType);

View file

@ -5,9 +5,11 @@
* 2.0. * 2.0.
*/ */
import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import { import {
formatDurationFromTimeUnitChar, formatDurationFromTimeUnitChar,
getAlertUrl, getAlertUrl,
observabilityPaths,
ProcessorEvent, ProcessorEvent,
TimeUnitChar, TimeUnitChar,
} from '@kbn/observability-plugin/common'; } from '@kbn/observability-plugin/common';
@ -306,6 +308,8 @@ export function registerTransactionErrorRateRuleType({
return { state: {} }; return { state: {} };
}, },
alerts: ApmRuleTypeAlertDefinition, alerts: ApmRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}) })
); );
} }

View file

@ -7,7 +7,8 @@
import { schema, Type } from '@kbn/config-schema'; import { schema, Type } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import { PluginSetupContract } from '@kbn/alerting-plugin/server'; import { GetViewInAppRelativeUrlFnOpts, PluginSetupContract } from '@kbn/alerting-plugin/server';
import { observabilityPaths } from '@kbn/observability-plugin/common';
import { TimeUnitChar } from '@kbn/observability-plugin/common/utils/formatters/duration'; import { TimeUnitChar } from '@kbn/observability-plugin/common/utils/formatters/duration';
import { import {
Comparator, Comparator,
@ -147,5 +148,7 @@ export async function registerMetricInventoryThresholdRuleType(
}, },
alerts: MetricsRulesTypeAlertDefinition, alerts: MetricsRulesTypeAlertDefinition,
fieldsForAAD: O11Y_AAD_FIELDS, fieldsForAAD: O11Y_AAD_FIELDS,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}); });
} }

View file

@ -6,7 +6,8 @@
*/ */
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import { PluginSetupContract } from '@kbn/alerting-plugin/server'; import { GetViewInAppRelativeUrlFnOpts, PluginSetupContract } from '@kbn/alerting-plugin/server';
import { observabilityPaths } from '@kbn/observability-plugin/common';
import { O11Y_AAD_FIELDS } from '../../../../common/constants'; import { O11Y_AAD_FIELDS } from '../../../../common/constants';
import { createLogThresholdExecutor, FIRED_ACTIONS } from './log_threshold_executor'; import { createLogThresholdExecutor, FIRED_ACTIONS } from './log_threshold_executor';
import { extractReferences, injectReferences } from './log_threshold_references_manager'; import { extractReferences, injectReferences } from './log_threshold_references_manager';
@ -166,5 +167,7 @@ export async function registerLogThresholdRuleType(
}, },
alerts: LogsRulesTypeAlertDefinition, alerts: LogsRulesTypeAlertDefinition,
fieldsForAAD: O11Y_AAD_FIELDS, fieldsForAAD: O11Y_AAD_FIELDS,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}); });
} }

View file

@ -12,8 +12,10 @@ import {
RuleType, RuleType,
AlertInstanceState as AlertState, AlertInstanceState as AlertState,
AlertInstanceContext as AlertContext, AlertInstanceContext as AlertContext,
GetViewInAppRelativeUrlFnOpts,
} from '@kbn/alerting-plugin/server'; } from '@kbn/alerting-plugin/server';
import { RecoveredActionGroupId } from '@kbn/alerting-plugin/common'; import { RecoveredActionGroupId } from '@kbn/alerting-plugin/common';
import { observabilityPaths } from '@kbn/observability-plugin/common';
import { O11Y_AAD_FIELDS } from '../../../../common/constants'; import { O11Y_AAD_FIELDS } from '../../../../common/constants';
import { import {
createMetricAnomalyExecutor, createMetricAnomalyExecutor,
@ -116,4 +118,6 @@ export const registerMetricAnomalyRuleType = (
}, },
], ],
}, },
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}); });

View file

@ -8,7 +8,12 @@
import { schema } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common'; import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common';
import { PluginSetupContract, RuleType } from '@kbn/alerting-plugin/server'; import {
GetViewInAppRelativeUrlFnOpts,
PluginSetupContract,
RuleType,
} from '@kbn/alerting-plugin/server';
import { observabilityPaths } from '@kbn/observability-plugin/common';
import { Comparator, METRIC_THRESHOLD_ALERT_TYPE_ID } from '../../../../common/alerting/metrics'; import { Comparator, METRIC_THRESHOLD_ALERT_TYPE_ID } from '../../../../common/alerting/metrics';
import { METRIC_EXPLORER_AGGREGATIONS } from '../../../../common/http_api'; import { METRIC_EXPLORER_AGGREGATIONS } from '../../../../common/http_api';
import { InfraBackendLibs } from '../../infra_types'; import { InfraBackendLibs } from '../../infra_types';
@ -185,5 +190,7 @@ export async function registerMetricThresholdRuleType(
}, },
producer: 'infrastructure', producer: 'infrastructure',
alerts: MetricsRulesTypeAlertDefinition, alerts: MetricsRulesTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}); });
} }

View file

@ -67,4 +67,6 @@ export const rulesLocatorID = 'RULES_LOCATOR';
export const sloDetailsLocatorID = 'SLO_DETAILS_LOCATOR'; export const sloDetailsLocatorID = 'SLO_DETAILS_LOCATOR';
export const sloEditLocatorID = 'SLO_EDIT_LOCATOR'; export const sloEditLocatorID = 'SLO_EDIT_LOCATOR';
import { paths } from './locators/paths';
export const observabilityPaths = paths.observability;
export type { AlertsLocatorParams } from './locators/alerts'; export type { AlertsLocatorParams } from './locators/alerts';

View file

@ -5,6 +5,7 @@
* 2.0. * 2.0.
*/ */
import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import { schema } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import { LicenseType } from '@kbn/licensing-plugin/server'; import { LicenseType } from '@kbn/licensing-plugin/server';
@ -12,7 +13,7 @@ import { createLifecycleExecutor } from '@kbn/rule-registry-plugin/server';
import { legacyExperimentalFieldMap } from '@kbn/alerts-as-data-utils'; import { legacyExperimentalFieldMap } from '@kbn/alerts-as-data-utils';
import { IBasePath } from '@kbn/core/server'; import { IBasePath } from '@kbn/core/server';
import { LocatorPublic } from '@kbn/share-plugin/common'; import { LocatorPublic } from '@kbn/share-plugin/common';
import { AlertsLocatorParams, sloFeatureId } from '../../../../common'; import { AlertsLocatorParams, observabilityPaths, sloFeatureId } from '../../../../common';
import { SLO_RULE_REGISTRATION_CONTEXT } from '../../../common/constants'; import { SLO_RULE_REGISTRATION_CONTEXT } from '../../../common/constants';
import { import {
@ -85,6 +86,8 @@ export function sloBurnRateRuleType(
useEcs: false, useEcs: false,
useLegacyAlerts: true, useLegacyAlerts: true,
}, },
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}; };
} }

View file

@ -15,8 +15,11 @@ import { createLifecycleExecutor, IRuleDataClient } from '@kbn/rule-registry-plu
import { LicenseType } from '@kbn/licensing-plugin/server'; import { LicenseType } from '@kbn/licensing-plugin/server';
import { LocatorPublic } from '@kbn/share-plugin/common'; import { LocatorPublic } from '@kbn/share-plugin/common';
import { EsQueryRuleParamsExtractedParams } from '@kbn/stack-alerts-plugin/server/rule_types/es_query/rule_type_params'; import { EsQueryRuleParamsExtractedParams } from '@kbn/stack-alerts-plugin/server/rule_types/es_query/rule_type_params';
import { paths } from '../../../../common/locators/paths'; import {
import { AlertsLocatorParams, observabilityFeatureId } from '../../../../common'; AlertsLocatorParams,
observabilityFeatureId,
observabilityPaths,
} from '../../../../common';
import { Comparator } from '../../../../common/threshold_rule/types'; import { Comparator } from '../../../../common/threshold_rule/types';
import { OBSERVABILITY_THRESHOLD_RULE_TYPE_ID } from '../../../../common/constants'; import { OBSERVABILITY_THRESHOLD_RULE_TYPE_ID } from '../../../../common/constants';
import { THRESHOLD_RULE_REGISTRATION_CONTEXT } from '../../../common/constants'; import { THRESHOLD_RULE_REGISTRATION_CONTEXT } from '../../../common/constants';
@ -181,8 +184,7 @@ export function thresholdRuleType(
}, },
producer: observabilityFeatureId, producer: observabilityFeatureId,
alerts: MetricsRulesTypeAlertDefinition, alerts: MetricsRulesTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) => { getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
return paths.observability.ruleDetails(rule.id); observabilityPaths.ruleDetails(rule.id),
},
}; };
} }

View file

@ -4,8 +4,11 @@
* 2.0; you may not use this file except in compliance with the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License
* 2.0. * 2.0.
*/ */
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common'; import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common';
import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import { observabilityPaths } from '@kbn/observability-plugin/common';
import { createLifecycleRuleTypeFactory, IRuleDataClient } from '@kbn/rule-registry-plugin/server'; import { createLifecycleRuleTypeFactory, IRuleDataClient } from '@kbn/rule-registry-plugin/server';
import { SyntheticsPluginsSetupDependencies, SyntheticsServerSetup } from '../../types'; import { SyntheticsPluginsSetupDependencies, SyntheticsServerSetup } from '../../types';
import { DOWN_LABEL, getMonitorAlertDocument, getMonitorSummary } from './message_utils'; import { DOWN_LABEL, getMonitorAlertDocument, getMonitorSummary } from './message_utils';
@ -155,5 +158,7 @@ export const registerSyntheticsStatusCheckRule = (
}; };
}, },
alerts: UptimeRuleTypeAlertDefinition, alerts: UptimeRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}); });
}; };

View file

@ -4,7 +4,9 @@
* 2.0; you may not use this file except in compliance with the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License
* 2.0. * 2.0.
*/ */
import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common'; import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common';
import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import { createLifecycleRuleTypeFactory, IRuleDataClient } from '@kbn/rule-registry-plugin/server'; import { createLifecycleRuleTypeFactory, IRuleDataClient } from '@kbn/rule-registry-plugin/server';
import { asyncForEach } from '@kbn/std'; import { asyncForEach } from '@kbn/std';
import { ALERT_REASON, ALERT_UUID } from '@kbn/rule-data-utils'; import { ALERT_REASON, ALERT_UUID } from '@kbn/rule-data-utils';
@ -12,6 +14,7 @@ import {
alertsLocatorID, alertsLocatorID,
AlertsLocatorParams, AlertsLocatorParams,
getAlertUrl, getAlertUrl,
observabilityPaths,
} from '@kbn/observability-plugin/common'; } from '@kbn/observability-plugin/common';
import { LocatorPublic } from '@kbn/share-plugin/common'; import { LocatorPublic } from '@kbn/share-plugin/common';
import { schema } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema';
@ -148,5 +151,7 @@ export const registerSyntheticsTLSCheckRule = (
return { state: updateState(ruleState, foundCerts) }; return { state: updateState(ruleState, foundCerts) };
}, },
alerts: UptimeRuleTypeAlertDefinition, alerts: UptimeRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}); });
}; };

View file

@ -5,6 +5,7 @@
* 2.0. * 2.0.
*/ */
import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import moment from 'moment'; import moment from 'moment';
import { KibanaRequest, SavedObjectsClientContract } from '@kbn/core/server'; import { KibanaRequest, SavedObjectsClientContract } from '@kbn/core/server';
import { schema } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema';
@ -19,6 +20,7 @@ import {
alertsLocatorID, alertsLocatorID,
AlertsLocatorParams, AlertsLocatorParams,
getAlertUrl, getAlertUrl,
observabilityPaths,
} from '@kbn/observability-plugin/common'; } from '@kbn/observability-plugin/common';
import { LocatorPublic } from '@kbn/share-plugin/common'; import { LocatorPublic } from '@kbn/share-plugin/common';
import { asyncForEach } from '@kbn/std'; import { asyncForEach } from '@kbn/std';
@ -226,4 +228,6 @@ export const durationAnomalyAlertFactory: UptimeAlertTypeFactory<ActionGroupIds>
return { state: updateState(state, foundAnomalies) }; return { state: updateState(state, foundAnomalies) };
}, },
alerts: UptimeRuleTypeAlertDefinition, alerts: UptimeRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}); });

View file

@ -4,6 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License
* 2.0. * 2.0.
*/ */
import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import { min } from 'lodash'; import { min } from 'lodash';
import moment from 'moment'; import moment from 'moment';
@ -19,6 +20,7 @@ import {
AlertsLocatorParams, AlertsLocatorParams,
formatDurationFromTimeUnitChar, formatDurationFromTimeUnitChar,
getAlertUrl, getAlertUrl,
observabilityPaths,
TimeUnitChar, TimeUnitChar,
} from '@kbn/observability-plugin/common'; } from '@kbn/observability-plugin/common';
import { LocatorPublic } from '@kbn/share-plugin/common'; import { LocatorPublic } from '@kbn/share-plugin/common';
@ -572,4 +574,6 @@ export const statusCheckAlertFactory: UptimeAlertTypeFactory<ActionGroupIds> = (
return { state: updateState(state, downMonitorsByLocation.length > 0) }; return { state: updateState(state, downMonitorsByLocation.length > 0) };
}, },
alerts: UptimeRuleTypeAlertDefinition, alerts: UptimeRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}); });

View file

@ -5,6 +5,7 @@
* 2.0. * 2.0.
*/ */
import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import moment from 'moment'; import moment from 'moment';
import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common'; import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common';
import { schema } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema';
@ -12,6 +13,7 @@ import {
alertsLocatorID, alertsLocatorID,
AlertsLocatorParams, AlertsLocatorParams,
getAlertUrl, getAlertUrl,
observabilityPaths,
} from '@kbn/observability-plugin/common'; } from '@kbn/observability-plugin/common';
import { LocatorPublic } from '@kbn/share-plugin/common'; import { LocatorPublic } from '@kbn/share-plugin/common';
import { ALERT_REASON, ALERT_UUID } from '@kbn/rule-data-utils'; import { ALERT_REASON, ALERT_UUID } from '@kbn/rule-data-utils';
@ -257,4 +259,6 @@ export const tlsAlertFactory: UptimeAlertTypeFactory<ActionGroupIds> = (
return { state: updateState(state, foundCerts) }; return { state: updateState(state, foundCerts) };
}, },
alerts: UptimeRuleTypeAlertDefinition, alerts: UptimeRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}); });

View file

@ -5,11 +5,12 @@
* 2.0. * 2.0.
*/ */
import { observabilityPaths } from '@kbn/observability-plugin/common';
import moment from 'moment'; import moment from 'moment';
import { schema } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema';
import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common'; import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common';
import { AlertInstanceContext } from '@kbn/alerting-plugin/common'; import { AlertInstanceContext } from '@kbn/alerting-plugin/common';
import { Alert } from '@kbn/alerting-plugin/server'; import { Alert, GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import { UptimeAlertTypeFactory } from './types'; import { UptimeAlertTypeFactory } from './types';
import { updateState } from './common'; import { updateState } from './common';
import { CLIENT_ALERT_TYPES, TLS_LEGACY } from '../../../../common/constants/uptime_alerts'; import { CLIENT_ALERT_TYPES, TLS_LEGACY } from '../../../../common/constants/uptime_alerts';
@ -166,4 +167,6 @@ export const tlsLegacyAlertFactory: UptimeAlertTypeFactory<ActionGroupIds> = (_s
return { state: updateState(state, foundCerts) }; return { state: updateState(state, foundCerts) };
}, },
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
}); });