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

[Uptime] migrate to observability rules registry #100699

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
52564d2
uptime - migrate to observability rules registry
dominiqueclarke Apr 30, 2021
18683b5
Modify Uptime alert types to work with server rule registry.
justinkambic May 3, 2021
73a2dd7
Export `RuleType` type for consumption by client plugins.
justinkambic May 6, 2021
995cb88
Add platinum as an option for `minimumLicenseRequired` field of `Rule…
justinkambic May 6, 2021
881a1cc
Simplify alert bootstrapping, inherit `RuleType` for alert factories.
justinkambic May 6, 2021
1753bbc
update rule field map
dominiqueclarke May 10, 2021
d5a597b
adjust rule registery to be created within setup instead of mount
dominiqueclarke May 10, 2021
8e247b5
merge master
dominiqueclarke May 24, 2021
31ac049
adjust plugin setup to account for rule registry changes
dominiqueclarke May 24, 2021
7f8f6ef
export types from rule registry
dominiqueclarke May 26, 2021
493b55e
move alert action message translations to common
dominiqueclarke May 26, 2021
fbb530e
update rule field map
dominiqueclarke May 26, 2021
d9b3294
update monitor status public alert model
dominiqueclarke May 26, 2021
804ad55
update tls public alert model
dominiqueclarke May 26, 2021
17aa286
update monitor status alert server model
dominiqueclarke May 26, 2021
53a05bc
update tls alert sever model
dominiqueclarke May 26, 2021
cbc95a6
update server plugin file to scope alerts indices to synthetics
dominiqueclarke May 26, 2021
24036d5
Merge branch 'master' of github.com:elastic/kibana into feature/98382…
dominiqueclarke May 26, 2021
96e1ddb
add initContext to server Plugin class
dominiqueclarke May 26, 2021
c303eea
adjust public plugin to register alerts when core start is availabile
dominiqueclarke May 26, 2021
6d1e628
update mappings
dominiqueclarke May 26, 2021
95ea9f7
update asset names
dominiqueclarke May 26, 2021
b9a7c78
adjust dependencies for alert initialization
dominiqueclarke May 27, 2021
e5c0304
adjust duration anomaly server alert model
dominiqueclarke May 27, 2021
764f9d0
adjust duration anomaly and monitor status public alert model to acco…
dominiqueclarke May 27, 2021
4d71a8c
add duration_anomaly tests
dominiqueclarke May 27, 2021
5811306
add anomaly severity
dominiqueclarke May 28, 2021
2e04e0b
adjust types
dominiqueclarke May 28, 2021
411dbdf
Merge branch 'master' of github.com:elastic/kibana into feature/98382…
dominiqueclarke May 28, 2021
555c237
update uptime server plugin
dominiqueclarke May 28, 2021
5964ac0
remove test_helpers
dominiqueclarke May 28, 2021
de27cbc
add getMonitorRouteFromMonitorId helper
dominiqueclarke May 28, 2021
bded189
export AlertTypeWithExecutor from rule_registry
dominiqueclarke May 28, 2021
93e68c4
adjust types
dominiqueclarke May 28, 2021
4a7e70d
merge master
dominiqueclarke Jun 1, 2021
38c5842
mock time zone
dominiqueclarke Jun 1, 2021
e9a2a17
merge master
dominiqueclarke Jun 23, 2021
994c42d
update types
dominiqueclarke Jun 24, 2021
26c5516
update types for legacy tls alert
dominiqueclarke Jun 24, 2021
1bac613
update mappings
dominiqueclarke Jun 24, 2021
416e50c
update monitor status check tls types
dominiqueclarke Jun 24, 2021
bd98bd4
update tls types and indexed fields
dominiqueclarke Jun 24, 2021
16c27c9
update duration anomaly types and indexed fields
dominiqueclarke Jun 24, 2021
5149ba4
update mappings
dominiqueclarke Jun 24, 2021
835caab
merge master
dominiqueclarke Jun 30, 2021
36248a1
delete unnecessary file
dominiqueclarke Jun 30, 2021
ddd18bd
Merge branch 'master' of github.com:elastic/kibana into feature/98382…
dominiqueclarke Jul 1, 2021
cf40852
adjust types
dominiqueclarke Jul 1, 2021
bedd91b
adjust ruleDataClient initialization
dominiqueclarke Jul 1, 2021
2ca90e2
index anomaly bucket span
dominiqueclarke Jul 1, 2021
cef6cb4
update types
dominiqueclarke Jul 1, 2021
8302df4
adjust registration of legacy tls alert type
dominiqueclarke Jul 1, 2021
664f122
adjust types
dominiqueclarke Jul 2, 2021
992c04f
merge master
dominiqueclarke Jul 5, 2021
36c8a4c
update index alias name
dominiqueclarke Jul 6, 2021
64c2091
update anomaly detection rule mappings
dominiqueclarke Jul 6, 2021
d541c85
Merge branch 'master' into feature/98382-uptime-migrate-to-observabil…
kibanamachine Jul 6, 2021
294137a
adjust import for certificate alert
dominiqueclarke Jul 6, 2021
1f4f4d7
Merge branch 'feature/98382-uptime-migrate-to-observability-rules-reg…
dominiqueclarke Jul 6, 2021
4ce1026
Merge branch 'master' into feature/98382-uptime-migrate-to-observabil…
kibanamachine Jul 9, 2021
7d41f4f
Merge branch 'master' of github.com:elastic/kibana into feature/98382…
dominiqueclarke Jul 12, 2021
dcdc486
adjust rbac settings
dominiqueclarke Jul 12, 2021
d350d81
Merge branch 'feature/98382-uptime-migrate-to-observability-rules-reg…
dominiqueclarke Jul 12, 2021
ed532b6
adjust content
dominiqueclarke Jul 12, 2021
1cf9f33
merge master
dominiqueclarke Jul 14, 2021
ee2468b
adjust uptime server plugin
dominiqueclarke Jul 14, 2021
e5b5d0f
Merge branch 'master' into feature/98382-uptime-migrate-to-observabil…
dominiqueclarke Jul 15, 2021
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
6 changes: 5 additions & 1 deletion x-pack/plugins/rule_registry/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ export type { RacRequestHandlerContext, RacApiRequestHandlerContext } from './ty
export { RuleDataClient } from './rule_data_client';
export { IRuleDataClient } from './rule_data_client/types';
export { getRuleExecutorData, RuleExecutorData } from './utils/get_rule_executor_data';
export { createLifecycleRuleTypeFactory } from './utils/create_lifecycle_rule_type_factory';
export {
createLifecycleRuleTypeFactory,
LifecycleAlertService,
} from './utils/create_lifecycle_rule_type_factory';
export {
LifecycleRuleExecutor,
LifecycleAlertServices,
createLifecycleExecutor,
} from './utils/create_lifecycle_executor';
export { createPersistenceRuleTypeFactory } from './utils/create_persistence_rule_type_factory';
export type { AlertTypeWithExecutor } from './types';

export const plugin = (initContext: PluginInitializerContext) =>
new RuleRegistryPlugin(initContext);
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import { AlertInstance } from '../../../alerting/server';
import { AlertTypeWithExecutor } from '../types';
import { createLifecycleExecutor } from './create_lifecycle_executor';

export type LifecycleAlertService<TAlertInstanceContext extends Record<string, unknown>> = (alert: {
export type LifecycleAlertService<
TAlertInstanceContext extends Record<string, unknown>,
TActionGroupIds extends string = string
> = (alert: {
id: string;
fields: Record<string, unknown>;
}) => AlertInstance<AlertInstanceState, TAlertInstanceContext, string>;
}) => AlertInstance<AlertInstanceState, TAlertInstanceContext, TActionGroupIds>;

export const createLifecycleRuleTypeFactory = ({
logger,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/rule_registry/server/utils/rbac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const mapConsumerToIndexName = {
infrastructure: '.alerts-observability.metrics',
observability: '.alerts-observability',
siem: ['.alerts-security.alerts', '.siem-signals'],
synthetics: '.alerts-observability-synthetics',
};
export type ValidFeatureId = keyof typeof mapConsumerToIndexName;

Expand Down
60 changes: 60 additions & 0 deletions x-pack/plugins/uptime/common/rules/uptime_rule_field_map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const uptimeRuleFieldMap = {
// common fields
'monitor.id': {
type: 'keyword',
},
'url.full': {
type: 'keyword',
},
'observer.geo.name': {
type: 'keyword',
},
reason: {
type: 'text',
},
// monitor status alert fields
'error.message': {
type: 'text',
},
'agent.name': {
type: 'keyword',
},
'monitor.name': {
type: 'keyword',
},
'monitor.type': {
type: 'keyword',
},
// tls alert fields
'tls.server.x509.issuer.common_name': {
type: 'keyword',
},
'tls.server.x509.subject.common_name': {
type: 'keyword',
},
'tls.server.x509.not_after': {
type: 'date',
},
'tls.server.x509.not_before': {
type: 'date',
},
'tls.server.hash.sha256': {
type: 'keyword',
},
// anomaly alert fields
'anomaly.start': {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need more fields for anomaly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the majority of the anomaly fields have been transitioned to use RAC technical fields, as well as ecs fields listed in the common section. You can see the change in the anomaly_duration.ts server file.

type: 'date',
},
'anomaly.bucket_span.minutes': {
type: 'keyword',
},
} as const;

export type UptimeRuleFieldMap = typeof uptimeRuleFieldMap;
75 changes: 75 additions & 0 deletions x-pack/plugins/uptime/common/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,78 @@ export const MonitorStatusTranslations = {
defaultMessage: 'Alert when a monitor is down or an availability threshold is breached.',
}),
};

export const TlsTranslations = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved alert translations to common, in order to use them within server to derive reason message.

defaultActionMessage: i18n.translate('xpack.uptime.alerts.tls.legacy.defaultActionMessage', {
defaultMessage: `Detected TLS certificate {commonName} from issuer {issuer} is {status}. Certificate {summary}
`,
values: {
commonName: '{{state.commonName}}',
issuer: '{{state.issuer}}',
summary: '{{state.summary}}',
status: '{{state.status}}',
},
}),
name: i18n.translate('xpack.uptime.alerts.tls.legacy.clientName', {
defaultMessage: 'Uptime TLS (Legacy)',
}),
description: i18n.translate('xpack.uptime.alerts.tls.legacy.description', {
defaultMessage:
'Alert when the TLS certificate of an Uptime monitor is about to expire. This alert will be deprecated in a future version.',
}),
};

export const TlsTranslationsLegacy = {
defaultActionMessage: i18n.translate('xpack.uptime.alerts.tls.defaultActionMessage', {
defaultMessage: `Detected {count} TLS certificates expiring or becoming too old.
{expiringConditionalOpen}
Expiring cert count: {expiringCount}
Expiring Certificates: {expiringCommonNameAndDate}
{expiringConditionalClose}
{agingConditionalOpen}
Aging cert count: {agingCount}
Aging Certificates: {agingCommonNameAndDate}
{agingConditionalClose}
`,
values: {
count: '{{state.count}}',
expiringCount: '{{state.expiringCount}}',
expiringCommonNameAndDate: '{{state.expiringCommonNameAndDate}}',
expiringConditionalOpen: '{{#state.hasExpired}}',
expiringConditionalClose: '{{/state.hasExpired}}',
agingCount: '{{state.agingCount}}',
agingCommonNameAndDate: '{{state.agingCommonNameAndDate}}',
agingConditionalOpen: '{{#state.hasAging}}',
agingConditionalClose: '{{/state.hasAging}}',
},
}),
name: i18n.translate('xpack.uptime.alerts.tls.clientName', {
defaultMessage: 'Uptime TLS',
}),
description: i18n.translate('xpack.uptime.alerts.tls.description', {
defaultMessage: 'Alert when the TLS certificate of an Uptime monitor is about to expire.',
}),
};

export const DurationAnomalyTranslations = {
defaultActionMessage: i18n.translate('xpack.uptime.alerts.durationAnomaly.defaultActionMessage', {
defaultMessage: `Abnormal ({severity} level) response time detected on {monitor} with url {monitorUrl} at {anomalyStartTimestamp}. Anomaly severity score is {severityScore}.
Response times as high as {slowestAnomalyResponse} have been detected from location {observerLocation}. Expected response time is {expectedResponseTime}.`,
values: {
severity: '{{state.severity}}',
anomalyStartTimestamp: '{{state.anomalyStartTimestamp}}',
monitor: '{{state.monitor}}',
monitorUrl: '{{{state.monitorUrl}}}',
slowestAnomalyResponse: '{{state.slowestAnomalyResponse}}',
expectedResponseTime: '{{state.expectedResponseTime}}',
severityScore: '{{state.severityScore}}',
observerLocation: '{{state.observerLocation}}',
},
}),
name: i18n.translate('xpack.uptime.alerts.durationAnomaly.clientName', {
defaultMessage: 'Uptime Duration Anomaly',
}),
description: i18n.translate('xpack.uptime.alerts.durationAnomaly.description', {
defaultMessage: 'Alert when the Uptime monitor duration is anaomalous.',
}),
};
25 changes: 21 additions & 4 deletions x-pack/plugins/uptime/kibana.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
{
"configPath": ["xpack", "uptime"],
"configPath": [
"xpack",
"uptime"
],
"id": "uptime",
"kibanaVersion": "kibana",
"optionalPlugins": ["data", "home", "ml", "fleet"],
"optionalPlugins": [
"data",
"home",
"ml",
"fleet"
],
"requiredPlugins": [
"alerting",
"embeddable",
"features",
"licensing",
"triggersActionsUi",
"usageCollection",
"ruleRegistry",
"observability"
],
"server": true,
"ui": true,
"version": "8.0.0",
"requiredBundles": ["observability", "kibanaReact", "kibanaUtils", "home", "data", "ml", "fleet"],
"requiredBundles": [
"observability",
"kibanaReact",
"kibanaUtils",
"home",
"data",
"ml",
"fleet"
],
"owner": {
"name": "Uptime",
"githubTeam": "uptime"
},
"description": "This plugin visualizes data from Synthetics and Heartbeat, and integrates with other Observability solutions."
}
}
47 changes: 31 additions & 16 deletions x-pack/plugins/uptime/public/apps/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import {
CoreSetup,
CoreStart,
Expand All @@ -29,7 +28,7 @@ import {
DataPublicPluginSetup,
DataPublicPluginStart,
} from '../../../../../src/plugins/data/public';
import { alertTypeInitializers } from '../lib/alert_types';
import { alertTypeInitializers, legacyAlertTypeInitializers } from '../lib/alert_types';
import { FleetStart } from '../../../fleet/public';
import {
FetchDataParams,
Expand Down Expand Up @@ -141,6 +140,36 @@ export class UptimePlugin
)
);

const { observabilityRuleTypeRegistry } = plugins.observability;

core.getStartServices().then(([coreStart, clientPluginsStart]) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

our alert initializers depend on coreStart and corePlugins, so initializing async after fetching coreStart and corePluginsStart

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not sure why we moved thisfrom setup to start?

in start we already have coreStart and clientPluginsStart available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shahzad31 you are right.

However, plugins.observability.observabilityRuleTypeRegistry is only available in setup

alertTypeInitializers.forEach((init) => {
const alertInitializer = init({
core: coreStart,
plugins: clientPluginsStart,
});
if (
clientPluginsStart.triggersActionsUi &&
!clientPluginsStart.triggersActionsUi.alertTypeRegistry.has(alertInitializer.id)
) {
observabilityRuleTypeRegistry.register(alertInitializer);
}
});

legacyAlertTypeInitializers.forEach((init) => {
const alertInitializer = init({
core: coreStart,
plugins: clientPluginsStart,
});
if (
clientPluginsStart.triggersActionsUi &&
!clientPluginsStart.triggersActionsUi.alertTypeRegistry.has(alertInitializer.id)
) {
plugins.triggersActionsUi.alertTypeRegistry.register(alertInitializer);
}
});
});

core.application.register({
id: PLUGIN.ID,
euiIconType: 'logoObservability',
Expand Down Expand Up @@ -171,26 +200,12 @@ export class UptimePlugin
const [coreStart, corePlugins] = await core.getStartServices();

const { renderApp } = await import('./render_app');

return renderApp(coreStart, plugins, corePlugins, params);
},
});
}

public start(start: CoreStart, plugins: ClientPluginsStart): void {
alertTypeInitializers.forEach((init) => {
const alertInitializer = init({
core: start,
plugins,
});
if (
plugins.triggersActionsUi &&
!plugins.triggersActionsUi.alertTypeRegistry.has(alertInitializer.id)
) {
plugins.triggersActionsUi.alertTypeRegistry.register(alertInitializer);
}
});

if (plugins.fleet) {
const { registerExtension } = plugins.fleet;

Expand Down
40 changes: 40 additions & 0 deletions x-pack/plugins/uptime/public/lib/alert_types/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { stringify } from 'querystring';

export const format = ({
pathname,
query,
}: {
pathname: string;
query: Record<string, any>;
}): string => {
return `${pathname}?${stringify(query)}`;
};

export const getMonitorRouteFromMonitorId = ({
monitorId,
dateRangeStart,
dateRangeEnd,
filters = {},
}: {
monitorId: string;
dateRangeStart: string;
dateRangeEnd: string;
filters?: Record<string, string[]>;
}) =>
format({
pathname: `/app/uptime/monitor/${btoa(monitorId)}`,
query: {
dateRangeEnd,
dateRangeStart,
...(Object.keys(filters).length
? { filters: JSON.stringify(Object.keys(filters).map((key) => [key, filters[key]])) }
: {}),
},
});
20 changes: 17 additions & 3 deletions x-pack/plugins/uptime/public/lib/alert_types/duration_anomaly.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
*/

import React from 'react';
import { AlertTypeModel } from '../../../../triggers_actions_ui/public';
import moment from 'moment';

import { CLIENT_ALERT_TYPES } from '../../../common/constants/alerts';
import { DurationAnomalyTranslations } from './translations';
import { DurationAnomalyTranslations } from '../../../common/translations';
import { AlertTypeInitializer } from '.';

import { getMonitorRouteFromMonitorId } from './common';

import { ObservabilityRuleTypeModel } from '../../../../observability/public';

const { defaultActionMessage, description } = DurationAnomalyTranslations;
const DurationAnomalyAlert = React.lazy(() => import('./lazy_wrapper/duration_anomaly'));

export const initDurationAnomalyAlertType: AlertTypeInitializer = ({
core,
plugins,
}): AlertTypeModel => ({
}): ObservabilityRuleTypeModel => ({
id: CLIENT_ALERT_TYPES.DURATION_ANOMALY,
iconClass: 'uptimeApp',
documentationUrl(docLinks) {
Expand All @@ -30,4 +35,13 @@ export const initDurationAnomalyAlertType: AlertTypeInitializer = ({
validate: () => ({ errors: {} }),
defaultActionMessage,
requiresAppContext: true,
format: ({ fields }) => ({
reason: fields.reason,
link: getMonitorRouteFromMonitorId({
monitorId: fields['monitor.id']!,
dateRangeEnd:
fields['kibana.rac.alert.status'] === 'open' ? 'now' : fields['kibana.rac.alert.end']!,
dateRangeStart: moment(new Date(fields['anomaly.start']!)).subtract('5', 'm').toISOString(),
}),
}),
});
Loading