Skip to content

Commit

Permalink
[8.x] [ResponseOps][Rules]Move uptime rule params to package (elastic…
Browse files Browse the repository at this point in the history
…#205238) (elastic#205725)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ResponseOps][Rules]Move uptime rule params to package
(elastic#205238)](elastic#205238)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Antonio","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-03T12:20:20Z","message":"[ResponseOps][Rules]Move
uptime rule params to package (elastic#205238)\n\nConnected with
elastic#195187\r\n\r\n## Summary\r\n\r\n- Moved params of duration anomaly rule
type to\r\n`/response-ops/rule_params/uptime_duration_anomaly/`\r\n-
Moved params of monitor status rule type
to\r\n`/response-ops/rule_params/uptime_monitor_status/`\r\n- Moved
params of TLS rule type
to\r\n`/response-ops/rule_params/uptime_tls/`\r\n- **Did not move
anything related to the legacy TLS rule type.**\r\n\r\nI ran into a
similar issue to elastic#205207 for the monitor status rule type.\r\nIt doesn't
block this PR but some follow up work might be needed
for\r\n`x-pack/solutions/observability/plugins/uptime/public/legacy_uptime/lib/alert_types/lazy_wrapper/validate_monitor_status.ts`.\r\nWe
will probably decide after the new
year.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"c8d46ee94982cf38163786f0890bafd43ec07247","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","backport
missing","v9.0.0","backport:prev-minor","Team:obs-ux-management"],"number":205238,"url":"https://github.com/elastic/kibana/pull/205238","mergeCommit":{"message":"[ResponseOps][Rules]Move
uptime rule params to package (elastic#205238)\n\nConnected with
elastic#195187\r\n\r\n## Summary\r\n\r\n- Moved params of duration anomaly rule
type to\r\n`/response-ops/rule_params/uptime_duration_anomaly/`\r\n-
Moved params of monitor status rule type
to\r\n`/response-ops/rule_params/uptime_monitor_status/`\r\n- Moved
params of TLS rule type
to\r\n`/response-ops/rule_params/uptime_tls/`\r\n- **Did not move
anything related to the legacy TLS rule type.**\r\n\r\nI ran into a
similar issue to elastic#205207 for the monitor status rule type.\r\nIt doesn't
block this PR but some follow up work might be needed
for\r\n`x-pack/solutions/observability/plugins/uptime/public/legacy_uptime/lib/alert_types/lazy_wrapper/validate_monitor_status.ts`.\r\nWe
will probably decide after the new
year.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"c8d46ee94982cf38163786f0890bafd43ec07247"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205238","number":205238,"mergeCommit":{"message":"[ResponseOps][Rules]Move
uptime rule params to package (elastic#205238)\n\nConnected with
elastic#195187\r\n\r\n## Summary\r\n\r\n- Moved params of duration anomaly rule
type to\r\n`/response-ops/rule_params/uptime_duration_anomaly/`\r\n-
Moved params of monitor status rule type
to\r\n`/response-ops/rule_params/uptime_monitor_status/`\r\n- Moved
params of TLS rule type
to\r\n`/response-ops/rule_params/uptime_tls/`\r\n- **Did not move
anything related to the legacy TLS rule type.**\r\n\r\nI ran into a
similar issue to elastic#205207 for the monitor status rule type.\r\nIt doesn't
block this PR but some follow up work might be needed
for\r\n`x-pack/solutions/observability/plugins/uptime/public/legacy_uptime/lib/alert_types/lazy_wrapper/validate_monitor_status.ts`.\r\nWe
will probably decide after the new
year.\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"c8d46ee94982cf38163786f0890bafd43ec07247"}}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
adcoelho and kibanamachine authored Jan 8, 2025
1 parent 4b931d0 commit 31e59f0
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { uptimeDurationAnomalyRuleParamsSchema } from './latest';
export { uptimeDurationAnomalyRuleParamsSchema as uptimeDurationAnomalyRuleParamsSchemaV1 } from './v1';

export type { UptimeDurationAnomalyRuleParams } from './latest';
export type { UptimeDurationAnomalyRuleParams as UptimeDurationAnomalyRuleParamsV1 } from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { TypeOf, schema } from '@kbn/config-schema';

export const uptimeDurationAnomalyRuleParamsSchema = schema.object({
stackVersion: schema.maybe(schema.string()),
monitorId: schema.string(),
severity: schema.number(),
});

export type UptimeDurationAnomalyRuleParams = TypeOf<typeof uptimeDurationAnomalyRuleParamsSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { uptimeMonitorStatusRuleParamsSchema } from './latest';
export { uptimeMonitorStatusRuleParamsSchema as uptimeMonitorStatusRuleParamsSchemaV1 } from './v1';

export type { UptimeMonitorStatusParams } from './latest';
export type { UptimeMonitorStatusParams as UptimeMonitorStatusParamsV1 } from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { TypeOf, schema } from '@kbn/config-schema';

export const uptimeMonitorStatusRuleParamsSchema = schema.object({
stackVersion: schema.maybe(schema.string()),
availability: schema.maybe(
schema.object({
range: schema.number(),
rangeUnit: schema.string(),
threshold: schema.string(),
})
),
// deprecated
filters: schema.maybe(
schema.oneOf([
// deprecated
schema.object({
'monitor.type': schema.maybe(schema.arrayOf(schema.string())),
'observer.geo.name': schema.maybe(schema.arrayOf(schema.string())),
tags: schema.maybe(schema.arrayOf(schema.string())),
'url.port': schema.maybe(schema.arrayOf(schema.string())),
}),
schema.string(),
])
),
locations: schema.maybe(schema.arrayOf(schema.string())),
numTimes: schema.number(),
search: schema.maybe(schema.string()),
shouldCheckStatus: schema.boolean(),
shouldCheckAvailability: schema.boolean(),
timerangeCount: schema.maybe(schema.number()),
timerangeUnit: schema.maybe(schema.string()),
// deprecated
timerange: schema.maybe(
schema.object({
from: schema.string(),
to: schema.string(),
})
),
version: schema.maybe(schema.number()),
isAutoGenerated: schema.maybe(schema.boolean()),
});

export type UptimeMonitorStatusParams = TypeOf<typeof uptimeMonitorStatusRuleParamsSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { uptimeTLSRuleParamsSchema } from './latest';
export { uptimeTLSRuleParamsSchema as uptimeTLSRuleParamsSchemaV1 } from './v1';

export type { UptimeTLSRuleParams } from './latest';
export type { UptimeTLSRuleParams as UptimeTLSRuleParamsV1 } from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { TypeOf, schema } from '@kbn/config-schema';

export const uptimeTLSRuleParamsSchema = schema.object({
stackVersion: schema.maybe(schema.string()),
search: schema.maybe(schema.string()),
certExpirationThreshold: schema.maybe(schema.number()),
certAgeThreshold: schema.maybe(schema.number()),
});

export type UptimeTLSRuleParams = TypeOf<typeof uptimeTLSRuleParamsSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
SavedObjectsClientContract,
DEFAULT_APP_CATEGORIES,
} from '@kbn/core/server';
import { schema } from '@kbn/config-schema';
import {
ALERT_EVALUATION_VALUE,
ALERT_EVALUATION_THRESHOLD,
Expand All @@ -21,6 +20,7 @@ import {
import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common';
import type { MlAnomaliesTableRecord } from '@kbn/ml-anomaly-utils';
import { getSeverityType } from '@kbn/ml-anomaly-utils';
import { uptimeDurationAnomalyRuleParamsSchema } from '@kbn/response-ops-rule-params/uptime_duration_anomaly';
import {
alertsLocatorID,
AlertsLocatorParams,
Expand Down Expand Up @@ -109,11 +109,7 @@ export const durationAnomalyAlertFactory: UptimeAlertTypeFactory<ActionGroupIds>
producer: 'uptime',
name: durationAnomalyTranslations.alertFactoryName,
validate: {
params: schema.object({
stackVersion: schema.maybe(schema.string()),
monitorId: schema.string(),
severity: schema.number(),
}),
params: uptimeDurationAnomalyRuleParamsSchema,
},
defaultActionGroupId: DURATION_ANOMALY.id,
actionGroups: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { min } from 'lodash';
import moment from 'moment';

import datemath from '@kbn/datemath';
import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import { JsonObject } from '@kbn/utility-types';
import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
import { ALERT_REASON } from '@kbn/rule-data-utils';
import { ActionGroupIdsOf } from '@kbn/alerting-plugin/common';
import { uptimeMonitorStatusRuleParamsSchema } from '@kbn/response-ops-rule-params/uptime_monitor_status';
import {
alertsLocatorID,
AlertsLocatorParams,
Expand Down Expand Up @@ -294,45 +294,7 @@ export const statusCheckAlertFactory: UptimeAlertTypeFactory<ActionGroupIds> = (
defaultMessage: 'Uptime monitor status',
}),
validate: {
params: schema.object({
stackVersion: schema.maybe(schema.string()),
availability: schema.maybe(
schema.object({
range: schema.number(),
rangeUnit: schema.string(),
threshold: schema.string(),
})
),
// deprecated
filters: schema.maybe(
schema.oneOf([
// deprecated
schema.object({
'monitor.type': schema.maybe(schema.arrayOf(schema.string())),
'observer.geo.name': schema.maybe(schema.arrayOf(schema.string())),
tags: schema.maybe(schema.arrayOf(schema.string())),
'url.port': schema.maybe(schema.arrayOf(schema.string())),
}),
schema.string(),
])
),
locations: schema.maybe(schema.arrayOf(schema.string())),
numTimes: schema.number(),
search: schema.maybe(schema.string()),
shouldCheckStatus: schema.boolean(),
shouldCheckAvailability: schema.boolean(),
timerangeCount: schema.maybe(schema.number()),
timerangeUnit: schema.maybe(schema.string()),
// deprecated
timerange: schema.maybe(
schema.object({
from: schema.string(),
to: schema.string(),
})
),
version: schema.maybe(schema.number()),
isAutoGenerated: schema.maybe(schema.boolean()),
}),
params: uptimeMonitorStatusRuleParamsSchema,
},
defaultActionGroupId: MONITOR_STATUS.id,
actionGroups: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { DEFAULT_APP_CATEGORIES } from '@kbn/core/server';
import { AlertsClientError, 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,
Expand All @@ -20,6 +19,8 @@ import { LocatorPublic } from '@kbn/share-plugin/common';
import { ALERT_REASON, ALERT_UUID } from '@kbn/rule-data-utils';
import { asyncForEach } from '@kbn/std';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { uptimeTLSRuleParamsSchema } from '@kbn/response-ops-rule-params/uptime_tls';

import { uptimeRuleFieldMap } from '../../../../common/rules/uptime_rule_field_map';
import { formatFilterString } from './status_check';
import { UptimeAlertTypeFactory } from './types';
Expand Down Expand Up @@ -123,12 +124,7 @@ export const tlsAlertFactory: UptimeAlertTypeFactory<ActionGroupIds> = (
producer: 'uptime',
name: tlsTranslations.alertFactoryName,
validate: {
params: schema.object({
stackVersion: schema.maybe(schema.string()),
search: schema.maybe(schema.string()),
certExpirationThreshold: schema.maybe(schema.number()),
certAgeThreshold: schema.maybe(schema.number()),
}),
params: uptimeTLSRuleParamsSchema,
},
defaultActionGroupId: TLS.id,
actionGroups: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@kbn/deeplinks-observability",
"@kbn/ebt-tools",
"@kbn/core-rendering-browser",
"@kbn/response-ops-rule-params",
],
"exclude": ["target/**/*"]
}

0 comments on commit 31e59f0

Please sign in to comment.