Skip to content

Commit

Permalink
[ResponseOps][Rules] Move synthetic rule types' params to @kbn/respon…
Browse files Browse the repository at this point in the history
…se-ops-rule-params (#204582)

Connected with #195187

## Summary

- Moved params of synthetic status monitor rule type to
`/response-ops/rule_params/synthetics_monitor_status/`
- Moved params of TLS rule type to
`/response-ops/rule_params/synthetics_tls/`

I created a follow-up issue to handle the places where io-ts is used for
params validation in `observability/plugins/synthetics`. #205207

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
adcoelho and kibanamachine authored Jan 3, 2025
1 parent 9215df9 commit 98cc4b1
Show file tree
Hide file tree
Showing 31 changed files with 204 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -2865,7 +2865,6 @@ src/platform/packages/private/kbn-ui-shared-deps-npm @elastic/kibana-operations
src/platform/packages/private/kbn-ui-shared-deps-src @elastic/kibana-operations
src/platform/packages/private/kbn-unsaved-changes-badge @elastic/kibana-data-discovery
src/platform/packages/private/react/kibana_context/root @elastic/appex-sharedux
src/platform/packages/private/response-ops/rule_params @elastic/response-ops
src/platform/packages/private/serverless/project_switcher @elastic/appex-sharedux
src/platform/packages/private/serverless/settings/common @elastic/appex-sharedux @elastic/kibana-management
src/platform/packages/private/serverless/types @elastic/appex-sharedux
Expand Down Expand Up @@ -3062,6 +3061,7 @@ src/platform/packages/shared/shared-ux/prompt/no_data_views/types @elastic/appex
src/platform/packages/shared/shared-ux/prompt/not_found @elastic/appex-sharedux
src/platform/packages/shared/shared-ux/router/impl @elastic/appex-sharedux
src/platform/packages/shared/shared-ux/storybook/mock @elastic/appex-sharedux
src/platform/packages/shared/response-ops/rule_params @elastic/response-ops
src/platform/plugins/private/advanced_settings @elastic/appex-sharedux @elastic/kibana-management
src/platform/plugins/private/event_annotation @elastic/kibana-visualizations
src/platform/plugins/private/event_annotation_listing @elastic/kibana-visualizations
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { syntheticsMonitorStatusRuleParamsSchema } from './latest';
export { syntheticsMonitorStatusRuleParamsSchema as syntheticsMonitorStatusRuleParamsSchemaV1 } from './v1';

export type { SyntheticsMonitorStatusRuleParams } from './latest';
export type { SyntheticsMonitorStatusRuleParams as SyntheticsMonitorStatusRuleParamsV1 } from './v1';

export type { TimeWindow } from './latest';
export type { TimeWindow as TimeWindowV1 } from './v1';

export type { StatusRuleCondition } from './latest';
export type { StatusRuleCondition as StatusRuleConditionV1 } 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,76 @@
/*
* 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';

const TimeWindowSchema = schema.object({
unit: schema.oneOf(
[schema.literal('s'), schema.literal('m'), schema.literal('h'), schema.literal('d')],
{
defaultValue: 'm',
}
),
size: schema.number({
defaultValue: 5,
}),
});

const NumberOfChecksSchema = schema.object({
numberOfChecks: schema.number({
defaultValue: 5,
min: 1,
max: 100,
}),
});

const StatusRuleConditionSchema = schema.object({
groupBy: schema.maybe(
schema.string({
defaultValue: 'locationId',
})
),
downThreshold: schema.maybe(
schema.number({
defaultValue: 3,
})
),
locationsThreshold: schema.maybe(
schema.number({
defaultValue: 1,
})
),
window: schema.oneOf([
schema.object({
time: TimeWindowSchema,
}),
NumberOfChecksSchema,
]),
includeRetests: schema.maybe(schema.boolean()),
});

export const syntheticsMonitorStatusRuleParamsSchema = schema.object(
{
condition: schema.maybe(StatusRuleConditionSchema),
monitorIds: schema.maybe(schema.arrayOf(schema.string())),
locations: schema.maybe(schema.arrayOf(schema.string())),
tags: schema.maybe(schema.arrayOf(schema.string())),
monitorTypes: schema.maybe(schema.arrayOf(schema.string())),
projects: schema.maybe(schema.arrayOf(schema.string())),
kqlQuery: schema.maybe(schema.string()),
},
{
meta: { description: 'The parameters for the rule.' },
}
);

export type SyntheticsMonitorStatusRuleParams = TypeOf<
typeof syntheticsMonitorStatusRuleParamsSchema
>;
export type TimeWindow = TypeOf<typeof TimeWindowSchema>;
export type StatusRuleCondition = TypeOf<typeof StatusRuleConditionSchema>;
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 { tlsRuleParamsSchema } from './latest';
export { tlsRuleParamsSchema as tlsRuleParamsSchemaV1 } from './v1';

export type { TLSRuleParams } from './latest';
export type { TLSRuleParams as TLSRuleParamsV1 } 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,23 @@
/*
* 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 tlsRuleParamsSchema = schema.object(
{
search: schema.maybe(schema.string()),
certExpirationThreshold: schema.maybe(schema.number()),
certAgeThreshold: schema.maybe(schema.number()),
},
{
meta: { description: 'The parameters for the rule.' },
}
);

export type TLSRuleParams = TypeOf<typeof tlsRuleParamsSchema>;
4 changes: 2 additions & 2 deletions x-pack/platform/plugins/shared/alerting/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
"@kbn/zod",
"@kbn/core-saved-objects-base-server-internal",
"@kbn/core-security-server-mocks",
"@kbn/response-ops-rule-params",
"@kbn/core-http-server-utils"
"@kbn/core-http-server-utils",
"@kbn/response-ops-rule-params"
],
"exclude": [
"target/**/*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,12 @@
* 2.0.
*/

import { schema, TypeOf } from '@kbn/config-schema';
import {
StatusRuleCondition,
TimeWindow,
} from '@kbn/response-ops-rule-params/synthetics_monitor_status';
import { isEmpty } from 'lodash';

export const TimeWindowSchema = schema.object({
unit: schema.oneOf(
[schema.literal('s'), schema.literal('m'), schema.literal('h'), schema.literal('d')],
{
defaultValue: 'm',
}
),
size: schema.number({
defaultValue: 5,
}),
});

export const NumberOfChecksSchema = schema.object({
numberOfChecks: schema.number({
defaultValue: 5,
min: 1,
max: 100,
}),
});

export const StatusRuleConditionSchema = schema.object({
groupBy: schema.maybe(
schema.string({
defaultValue: 'locationId',
})
),
downThreshold: schema.maybe(
schema.number({
defaultValue: 3,
})
),
locationsThreshold: schema.maybe(
schema.number({
defaultValue: 1,
})
),
window: schema.oneOf([
schema.object({
time: TimeWindowSchema,
}),
NumberOfChecksSchema,
]),
includeRetests: schema.maybe(schema.boolean()),
});

export const StatusRulePramsSchema = schema.object({
condition: schema.maybe(StatusRuleConditionSchema),
monitorIds: schema.maybe(schema.arrayOf(schema.string())),
locations: schema.maybe(schema.arrayOf(schema.string())),
tags: schema.maybe(schema.arrayOf(schema.string())),
monitorTypes: schema.maybe(schema.arrayOf(schema.string())),
projects: schema.maybe(schema.arrayOf(schema.string())),
kqlQuery: schema.maybe(schema.string()),
});

export type TimeWindow = TypeOf<typeof TimeWindowSchema>;
export type StatusRuleParams = TypeOf<typeof StatusRulePramsSchema>;
export type StatusRuleCondition = TypeOf<typeof StatusRuleConditionSchema>;

export const getConditionType = (condition?: StatusRuleCondition) => {
let numberOfChecks = 1;
let timeWindow: TimeWindow = { unit: 'm', size: 1 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@

import * as t from 'io-ts';

// This should be replaced by TLSParams from @kbn/response-ops-rule-params
export const TLSParamsType = t.partial({
search: t.string,
certAgeThreshold: t.number,
certExpirationThreshold: t.number,
});

export type TLSParams = t.TypeOf<typeof TLSParamsType>;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React, { useCallback } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFieldNumber, EuiPopoverTitle } from '@elastic/eui';
import { StatusRuleCondition } from '../../../../../../common/rules/status_rule';
import { StatusRuleCondition } from '@kbn/response-ops-rule-params/synthetics_monitor_status';
import { PopoverExpression } from './popover_expression';
import { StatusRuleParamsProps } from '../status_rule_ui';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { ForLastExpression, TIME_UNITS } from '@kbn/triggers-actions-ui-plugin/p
import React, { useCallback } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFieldNumber, EuiPopoverTitle } from '@elastic/eui';
import { TimeWindow } from '@kbn/response-ops-rule-params/synthetics_monitor_status';
import { PopoverExpression } from './popover_expression';
import { getConditionType, TimeWindow } from '../../../../../../common/rules/status_rule';
import { getConditionType } from '../../../../../../common/rules/status_rule';
import { StatusRuleParamsProps } from '../status_rule_ui';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import { EuiExpression, EuiPopover, EuiPopoverTitle, EuiSelectable } from '@elastic/eui';
import React, { useEffect, useState } from 'react';
import { i18n } from '@kbn/i18n';
import { getConditionType, StatusRuleCondition } from '../../../../../../common/rules/status_rule';
import { StatusRuleCondition } from '@kbn/response-ops-rule-params/synthetics_monitor_status';
import { getConditionType } from '../../../../../../common/rules/status_rule';
import { StatusRuleParamsProps } from '../status_rule_ui';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import React, { useCallback } from 'react';
import { RuleTypeParamsExpressionProps } from '@kbn/triggers-actions-ui-plugin/public';
import { Filter } from '@kbn/es-query';
import { EuiSpacer } from '@elastic/eui';
import { SyntheticsMonitorStatusRuleParams as StatusRuleParams } from '@kbn/response-ops-rule-params/synthetics_monitor_status';
import { FieldFilters } from './common/field_filters';
import { AlertSearchBar } from './query_bar';
import { StatusRuleExpression } from './status_rule_expression';
import { StatusRuleParams } from '../../../../../common/rules/status_rule';

export type StatusRuleParamsProps = RuleTypeParamsExpressionProps<StatusRuleParams>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import { useDispatch, useSelector } from 'react-redux';
import React, { useEffect } from 'react';
import { RuleTypeParamsExpressionProps } from '@kbn/triggers-actions-ui-plugin/public';
import type { TLSRuleParams } from '@kbn/response-ops-rule-params/synthetics_tls';
import { AlertTlsComponent } from './alert_tls';
import { getDynamicSettingsAction, selectDynamicSettings } from '../../state/settings';
import { TLSParams } from '../../../../../common/runtime_types/alerts/tls';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../../../common/constants';

export const TLSRuleComponent: React.FC<{
ruleParams: RuleTypeParamsExpressionProps<TLSParams>['ruleParams'];
setRuleParams: RuleTypeParamsExpressionProps<TLSParams>['setRuleParams'];
ruleParams: RuleTypeParamsExpressionProps<TLSRuleParams>['ruleParams'];
setRuleParams: RuleTypeParamsExpressionProps<TLSRuleParams>['setRuleParams'];
}> = ({ ruleParams, setRuleParams }) => {
const dispatch = useDispatch();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { RuleTypeParamsExpressionProps } from '@kbn/triggers-actions-ui-plugin/p
import { EuiSpacer, EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { isEmpty } from 'lodash';
import { SyntheticsMonitorStatusRuleParams as StatusRuleParams } from '@kbn/response-ops-rule-params/synthetics_monitor_status';
import { StatusRuleComponent } from '../../../components/alerts/status_rule_ui';
import { kibanaService } from '../../../../../utils/kibana_service';
import { ClientPluginsStart } from '../../../../../plugin';
import { store } from '../../../state';
import type { StatusRuleParams } from '../../../../../../common/rules/status_rule';

interface Props {
coreStart: CoreStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ import { Provider as ReduxProvider } from 'react-redux';
import { CoreStart } from '@kbn/core/public';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import type { RuleTypeParamsExpressionProps } from '@kbn/triggers-actions-ui-plugin/public';
import type { TLSRuleParams } from '@kbn/response-ops-rule-params/synthetics_tls';
import { TLSRuleComponent } from '../../../components/alerts/tls_rule_ui';
import { ClientPluginsStart } from '../../../../../plugin';
import { TLSParams } from '../../../../../../common/runtime_types/alerts/tls';
import { kibanaService } from '../../../../../utils/kibana_service';
import { store } from '../../../state';

interface Props {
coreStart: CoreStart;
plugins: ClientPluginsStart;
ruleParams: RuleTypeParamsExpressionProps<TLSParams>['ruleParams'];
setRuleParams: RuleTypeParamsExpressionProps<TLSParams>['setRuleParams'];
ruleParams: RuleTypeParamsExpressionProps<TLSRuleParams>['ruleParams'];
setRuleParams: RuleTypeParamsExpressionProps<TLSRuleParams>['setRuleParams'];
}

// eslint-disable-next-line import/no-default-export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { ALERT_REASON, SYNTHETICS_ALERT_RULE_TYPES } from '@kbn/rule-data-utils'

import type { ObservabilityRuleTypeModel } from '@kbn/observability-plugin/public';
import type { RuleTypeParamsExpressionProps } from '@kbn/triggers-actions-ui-plugin/public';
import { SyntheticsMonitorStatusRuleParams as StatusRuleParams } from '@kbn/response-ops-rule-params/synthetics_monitor_status';
import { getSyntheticsErrorRouteFromMonitorId } from '../../../../../common/utils/get_synthetics_monitor_url';
import { STATE_ID } from '../../../../../common/field_names';
import { SyntheticsMonitorStatusTranslations } from '../../../../../common/rules/synthetics/translations';
import type { StatusRuleParams } from '../../../../../common/rules/status_rule';
import type { AlertTypeInitializer } from './types';

const { defaultActionMessage, defaultRecoveryMessage, description } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { ALERT_REASON, SYNTHETICS_ALERT_RULE_TYPES } from '@kbn/rule-data-utils'
import { ObservabilityRuleTypeModel } from '@kbn/observability-plugin/public';
import type { RuleTypeParamsExpressionProps } from '@kbn/triggers-actions-ui-plugin/public';
import { ValidationResult } from '@kbn/triggers-actions-ui-plugin/public';
import type { TLSRuleParams } from '@kbn/response-ops-rule-params/synthetics_tls';
import { TlsTranslations } from '../../../../../common/rules/synthetics/translations';
import { CERTIFICATES_ROUTE } from '../../../../../common/constants/ui';
import type { TLSParams } from '../../../../../common/runtime_types/alerts/tls';

import type { AlertTypeInitializer } from './types';

Expand All @@ -30,7 +30,7 @@ export const initTlsAlertType: AlertTypeInitializer = ({
documentationUrl(docLinks) {
return `${docLinks.links.observability.syntheticsAlerting}`;
},
ruleParamsExpression: (params: RuleTypeParamsExpressionProps<TLSParams>) => (
ruleParamsExpression: (params: RuleTypeParamsExpressionProps<TLSRuleParams>) => (
<TLSAlert
coreStart={core}
plugins={plugins}
Expand Down
Loading

0 comments on commit 98cc4b1

Please sign in to comment.