Skip to content

Commit

Permalink
Configure "View rule in Kibana" Url for Observability rule types (#16…
Browse files Browse the repository at this point in the history
…3292)

Closes #163168

## Summary

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


![image](https://github.com/elastic/kibana/assets/12370520/58e625a4-eb8f-491b-962f-30a0e3950fb1)
  • Loading branch information
maryam-saeidi authored Aug 11, 2023
1 parent 5e49bfd commit feb2493
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import { KibanaRequest } from '@kbn/core/server';
import datemath from '@kbn/datemath';
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 {
ALERT_EVALUATION_THRESHOLD,
Expand Down Expand Up @@ -329,6 +335,8 @@ export function registerAnomalyRuleType({
return { state: {} };
},
alerts: ApmRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
})
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
* 2.0.
*/

import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import {
formatDurationFromTimeUnitChar,
getAlertUrl,
observabilityPaths,
ProcessorEvent,
TimeUnitChar,
} from '@kbn/observability-plugin/common';
Expand Down Expand Up @@ -254,6 +256,8 @@ export function registerErrorCountRuleType({
return { state: {} };
},
alerts: ApmRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
})
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
*/

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

alerting.registerType(ruleType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
* 2.0.
*/

import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import {
formatDurationFromTimeUnitChar,
getAlertUrl,
observabilityPaths,
ProcessorEvent,
TimeUnitChar,
} from '@kbn/observability-plugin/common';
Expand Down Expand Up @@ -306,6 +308,8 @@ export function registerTransactionErrorRateRuleType({
return { state: {} };
},
alerts: ApmRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
})
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import { schema, Type } from '@kbn/config-schema';
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 {
Comparator,
Expand Down Expand Up @@ -147,5 +148,7 @@ export async function registerMetricInventoryThresholdRuleType(
},
alerts: MetricsRulesTypeAlertDefinition,
fieldsForAAD: O11Y_AAD_FIELDS,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

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 { createLogThresholdExecutor, FIRED_ACTIONS } from './log_threshold_executor';
import { extractReferences, injectReferences } from './log_threshold_references_manager';
Expand Down Expand Up @@ -166,5 +167,7 @@ export async function registerLogThresholdRuleType(
},
alerts: LogsRulesTypeAlertDefinition,
fieldsForAAD: O11Y_AAD_FIELDS,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
RuleType,
AlertInstanceState as AlertState,
AlertInstanceContext as AlertContext,
GetViewInAppRelativeUrlFnOpts,
} from '@kbn/alerting-plugin/server';
import { RecoveredActionGroupId } from '@kbn/alerting-plugin/common';
import { observabilityPaths } from '@kbn/observability-plugin/common';
import { O11Y_AAD_FIELDS } from '../../../../common/constants';
import {
createMetricAnomalyExecutor,
Expand Down Expand Up @@ -116,4 +118,6 @@ export const registerMetricAnomalyRuleType = (
},
],
},
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
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 { METRIC_EXPLORER_AGGREGATIONS } from '../../../../common/http_api';
import { InfraBackendLibs } from '../../infra_types';
Expand Down Expand Up @@ -185,5 +190,7 @@ export async function registerMetricThresholdRuleType(
},
producer: 'infrastructure',
alerts: MetricsRulesTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
});
}
2 changes: 2 additions & 0 deletions x-pack/plugins/observability/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ export const rulesLocatorID = 'RULES_LOCATOR';
export const sloDetailsLocatorID = 'SLO_DETAILS_LOCATOR';
export const sloEditLocatorID = 'SLO_EDIT_LOCATOR';

import { paths } from './locators/paths';
export const observabilityPaths = paths.observability;
export type { AlertsLocatorParams } from './locators/alerts';
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
* 2.0.
*/

import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import { LicenseType } from '@kbn/licensing-plugin/server';
import { createLifecycleExecutor } from '@kbn/rule-registry-plugin/server';
import { legacyExperimentalFieldMap } from '@kbn/alerts-as-data-utils';
import { IBasePath } from '@kbn/core/server';
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 {
Expand Down Expand Up @@ -85,6 +86,8 @@ export function sloBurnRateRuleType(
useEcs: false,
useLegacyAlerts: true,
},
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import { createLifecycleExecutor, IRuleDataClient } from '@kbn/rule-registry-plu
import { LicenseType } from '@kbn/licensing-plugin/server';
import { LocatorPublic } from '@kbn/share-plugin/common';
import { EsQueryRuleParamsExtractedParams } from '@kbn/stack-alerts-plugin/server/rule_types/es_query/rule_type_params';
import { paths } from '../../../../common/locators/paths';
import { AlertsLocatorParams, observabilityFeatureId } from '../../../../common';
import {
AlertsLocatorParams,
observabilityFeatureId,
observabilityPaths,
} from '../../../../common';
import { Comparator } from '../../../../common/threshold_rule/types';
import { OBSERVABILITY_THRESHOLD_RULE_TYPE_ID } from '../../../../common/constants';
import { THRESHOLD_RULE_REGISTRATION_CONTEXT } from '../../../common/constants';
Expand Down Expand Up @@ -181,8 +184,7 @@ export function thresholdRuleType(
},
producer: observabilityFeatureId,
alerts: MetricsRulesTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) => {
return paths.observability.ruleDetails(rule.id);
},
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { isEmpty } from 'lodash';
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 { SyntheticsPluginsSetupDependencies, SyntheticsServerSetup } from '../../types';
import { DOWN_LABEL, getMonitorAlertDocument, getMonitorSummary } from './message_utils';
Expand Down Expand Up @@ -155,5 +158,7 @@ export const registerSyntheticsStatusCheckRule = (
};
},
alerts: UptimeRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common';
import { GetViewInAppRelativeUrlFnOpts } from '@kbn/alerting-plugin/server';
import { createLifecycleRuleTypeFactory, IRuleDataClient } from '@kbn/rule-registry-plugin/server';
import { asyncForEach } from '@kbn/std';
import { ALERT_REASON, ALERT_UUID } from '@kbn/rule-data-utils';
import {
alertsLocatorID,
AlertsLocatorParams,
getAlertUrl,
observabilityPaths,
} from '@kbn/observability-plugin/common';
import { LocatorPublic } from '@kbn/share-plugin/common';
import { schema } from '@kbn/config-schema';
Expand Down Expand Up @@ -148,5 +151,7 @@ export const registerSyntheticsTLSCheckRule = (
return { state: updateState(ruleState, foundCerts) };
},
alerts: UptimeRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

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

Expand All @@ -19,6 +20,7 @@ import {
AlertsLocatorParams,
formatDurationFromTimeUnitChar,
getAlertUrl,
observabilityPaths,
TimeUnitChar,
} from '@kbn/observability-plugin/common';
import { LocatorPublic } from '@kbn/share-plugin/common';
Expand Down Expand Up @@ -572,4 +574,6 @@ export const statusCheckAlertFactory: UptimeAlertTypeFactory<ActionGroupIds> = (
return { state: updateState(state, downMonitorsByLocation.length > 0) };
},
alerts: UptimeRuleTypeAlertDefinition,
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
});
4 changes: 4 additions & 0 deletions x-pack/plugins/uptime/server/legacy_uptime/lib/alerts/tls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
* 2.0.
*/

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

import { observabilityPaths } from '@kbn/observability-plugin/common';
import moment from 'moment';
import { schema } from '@kbn/config-schema';
import { ActionGroupIdsOf } 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 { updateState } from './common';
import { CLIENT_ALERT_TYPES, TLS_LEGACY } from '../../../../common/constants/uptime_alerts';
Expand Down Expand Up @@ -166,4 +167,6 @@ export const tlsLegacyAlertFactory: UptimeAlertTypeFactory<ActionGroupIds> = (_s

return { state: updateState(state, foundCerts) };
},
getViewInAppRelativeUrl: ({ rule }: GetViewInAppRelativeUrlFnOpts<{}>) =>
observabilityPaths.ruleDetails(rule.id),
});

0 comments on commit feb2493

Please sign in to comment.