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

[ResponseOps][Rules]Move uptime rule params to package #205238

Merged
merged 11 commits into from
Jan 3, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
module.exports = {
preset: '@kbn/test/jest_node',
rootDir: '../../../../../..',
roots: ['<rootDir>/src/platform/packages/private/response-ops/rule_params'],
roots: ['<rootDir>/src/platform/packages/shared/response-ops/rule_params'],
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"type": "shared-common",
"id": "@kbn/response-ops-rule-params",
"owner": [
"@elastic/response-ops"
],
"owner": ["@elastic/response-ops"],
"group": "platform",
"visibility": "private"
"visibility": "shared"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
],
"kbn_references": [
"@kbn/config-schema",
"@kbn/uptime-plugin"
]
}
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,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,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 @@ -6,7 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { ruleParamsSchemaV1 } from '@kbn/response-ops-rule-params';
import { ruleParamsSchemaV1 } from 'src/platform/packages/shared/response-ops/rule_params';
import { adHocRunStatus } from '../../../../constants';

export const statusSchema = schema.oneOf([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { ruleParamsSchemaWithDefaultValueV1 } from '@kbn/response-ops-rule-params';
import { ruleParamsSchemaWithDefaultValueV1 } from 'src/platform/packages/shared/response-ops/rule_params';
import { validateDurationV1, validateHoursV1, validateTimezoneV1 } from '../../../validation';
import { notifyWhenSchemaV1, alertDelaySchemaV1 } from '../../../response';
import { alertsFilterQuerySchemaV1 } from '../../../../alerts_filter_query';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { ruleParamsSchemaWithDefaultValueV1 } from '@kbn/response-ops-rule-params';
import { ruleParamsSchemaWithDefaultValueV1 } from 'src/platform/packages/shared/response-ops/rule_params';
import { validateDurationV1, validateHoursV1, validateTimezoneV1 } from '../../../validation';
import { notifyWhenSchemaV1, alertDelaySchemaV1 } from '../../../response';
import { alertsFilterQuerySchemaV1 } from '../../../../alerts_filter_query';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export type {
Monitoring as MonitoringV1,
} from './types/v1';

export { ruleParamsSchemaV1 } from '@kbn/response-ops-rule-params';
export { ruleParamsSchema } from '@kbn/response-ops-rule-params';
export { ruleParamsSchemaV1 } from 'src/platform/packages/shared/response-ops/rule_params';
export { ruleParamsSchema } from 'src/platform/packages/shared/response-ops/rule_params';

export type { RuleParamsV1 } from '@kbn/response-ops-rule-params';
export type { RuleParams } from '@kbn/response-ops-rule-params';
export type { RuleParamsV1 } from 'src/platform/packages/shared/response-ops/rule_params';
export type { RuleParams } from 'src/platform/packages/shared/response-ops/rule_params';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { ruleParamsSchemaV1 } from '@kbn/response-ops-rule-params';
import { ruleParamsSchemaV1 } from 'src/platform/packages/shared/response-ops/rule_params';
import { rRuleResponseSchemaV1 } from '../../../r_rule';
import { alertsFilterQuerySchemaV1 } from '../../../alerts_filter_query';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { TypeOf } from '@kbn/config-schema';
import { RuleParamsV1 } from '@kbn/response-ops-rule-params';
import { RuleParamsV1 } from 'src/platform/packages/shared/response-ops/rule_params';
import {
ruleResponseSchemaV1,
ruleSnoozeScheduleSchemaV1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { ruleParamsSchema } from '@kbn/response-ops-rule-params';
import { ruleParamsSchema } from 'src/platform/packages/shared/response-ops/rule_params';
import { adHocRunStatus } from '../../../../../common/constants';

export const statusSchema = schema.oneOf([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { ruleParamsSchemaWithDefaultValue } from '@kbn/response-ops-rule-params';
import { ruleParamsSchemaWithDefaultValue } from 'src/platform/packages/shared/response-ops/rule_params';
import { validateDuration } from '../../../validation';
import {
notifyWhenSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { ruleParamsSchemaWithDefaultValue } from '@kbn/response-ops-rule-params';
import { ruleParamsSchemaWithDefaultValue } from 'src/platform/packages/shared/response-ops/rule_params';
import { validateDuration } from '../../../validation';
import {
notifyWhenSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { schema } from '@kbn/config-schema';
import { ruleParamsSchema } from '@kbn/response-ops-rule-params';
import { ruleParamsSchema } from 'src/platform/packages/shared/response-ops/rule_params';
import {
ruleLastRunOutcomeValues,
ruleExecutionStatusValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { TypeOf } from '@kbn/config-schema';
import { ruleParamsSchema } from '@kbn/response-ops-rule-params';
import { ruleParamsSchema } from 'src/platform/packages/shared/response-ops/rule_params';
import {
ruleNotifyWhen,
ruleLastRunOutcomeValues,
Expand Down
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/latest';
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/latest';
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/latest';

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/core-rendering-browser",
"@kbn/charts-theme",
"@kbn/charts-plugin",
"@kbn/response-ops-rule-params",
],
"exclude": ["target/**/*"]
}