Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
adcoelho committed Dec 17, 2024
1 parent 3a6d27a commit 8c11159
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 74 deletions.
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';
74 changes: 74 additions & 0 deletions packages/response-ops/rule_params/synthetics_monitor_status/v1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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 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 StatusRuleParamsSchema = 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 StatusRuleParams = TypeOf<typeof StatusRuleParamsSchema>;
export type TimeWindow = TypeOf<typeof TimeWindowSchema>;
export type StatusRuleCondition = TypeOf<typeof StatusRuleConditionSchema>;
5 changes: 4 additions & 1 deletion packages/response-ops/rule_params/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
*/

import { TypeOf, schema } from '@kbn/config-schema';
import { StatusRuleParamsSchema as StatusRuleParamsSchemaV1 } from './synthetics_monitor_status/v1';

export const ruleParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()), {
const defaultRuleParamsSchema = schema.recordOf(schema.string(), schema.maybe(schema.any()), {
meta: { description: 'The parameters for the rule.' },
});

export const ruleParamsSchema = schema.oneOf([StatusRuleParamsSchemaV1, defaultRuleParamsSchema]);

export const ruleParamsSchemaWithDefaultValue = schema.recordOf(
schema.string(),
schema.maybe(schema.any()),
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/latest';
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 @@ -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/latest';
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/latest';
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/latest';
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 { StatusRuleParams } from '@kbn/response-ops-rule-params/synthetics_monitor_status/latest';
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 @@ -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 { StatusRuleParams } from '@kbn/response-ops-rule-params/synthetics_monitor_status/latest';
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 @@ -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 { StatusRuleParams } from '@kbn/response-ops-rule-params/synthetics_monitor_status/latest';
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 @@ -23,7 +23,10 @@ import {
PublicAlertsClient,
RecoveredAlertData,
} from '@kbn/alerting-plugin/server/alerts_client/types';
import { StatusRuleParams, TimeWindow } from '../../common/rules/status_rule';
import {
StatusRuleParams,
TimeWindow,
} from '@kbn/response-ops-rule-params/synthetics_monitor_status/latest';
import { syntheticsRuleFieldMap } from '../../common/rules/synthetics_rule_field_map';
import { combineFiltersAndUserSearch, stringifyKueries } from '../../common/lib';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import moment from 'moment';
import { i18n } from '@kbn/i18n';
import { ALERT_REASON } from '@kbn/rule-data-utils';
import { StatusRuleParams } from '@kbn/response-ops-rule-params/synthetics_monitor_status/latest';
import { AlertStatusMetaData } from '../../../common/runtime_types/alert_rules/common';
import { getConditionType, StatusRuleParams } from '../../../common/rules/status_rule';
import { getConditionType } from '../../../common/rules/status_rule';
import { AND_LABEL, getTimeUnitLabel } from '../common';
import { ALERT_REASON_MSG } from '../action_variables';
import { MonitorSummaryStatusRule } from './types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { GetViewInAppRelativeUrlFnOpts, AlertsClientError } from '@kbn/alerting-
import { observabilityPaths } from '@kbn/observability-plugin/common';
import apm from 'elastic-apm-node';
import { SYNTHETICS_ALERT_RULE_TYPES } from '@kbn/rule-data-utils';
import { StatusRuleParamsSchema } from '@kbn/response-ops-rule-params/synthetics_monitor_status/latest';
import { AlertOverviewStatus } from '../../../common/runtime_types/alert_rules/common';
import { StatusRuleExecutorOptions } from './types';
import { syntheticsRuleFieldMap } from '../../../common/rules/synthetics_rule_field_map';
import { SyntheticsPluginsSetupDependencies, SyntheticsServerSetup } from '../../types';
import { StatusRuleExecutor } from './status_rule_executor';
import { StatusRulePramsSchema } from '../../../common/rules/status_rule';
import { MONITOR_STATUS } from '../../../common/constants/synthetics_alerts';
import {
setRecoveredAlertsContext,
Expand Down Expand Up @@ -44,7 +44,7 @@ export const registerSyntheticsStatusCheckRule = (
producer: 'uptime',
name: STATUS_RULE_NAME,
validate: {
params: StatusRulePramsSchema,
params: StatusRuleParamsSchema,
},
defaultActionGroupId: MONITOR_STATUS.id,
actionGroups: [MONITOR_STATUS],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { fromKueryExpression, toElasticsearchQuery } from '@kbn/es-query';
import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/types';
import { StatusRuleParams } from '../../../../common/rules/status_rule';
import { StatusRuleParams } from '@kbn/response-ops-rule-params/synthetics_monitor_status/latest';
import { SyntheticsEsClient } from '../../../lib';
import {
FINAL_SUMMARY_FILTER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import { Logger } from '@kbn/core/server';
import { intersection, isEmpty, uniq } from 'lodash';
import { getAlertDetailsUrl } from '@kbn/observability-plugin/common';
import { StatusRuleParams } from '@kbn/response-ops-rule-params/synthetics_monitor_status/latest';
import {
AlertOverviewStatus,
AlertStatusConfigs,
Expand Down Expand Up @@ -41,7 +42,7 @@ import {
getAllMonitors,
processMonitors,
} from '../../saved_objects/synthetics_monitor/get_all_monitors';
import { getConditionType, StatusRuleParams } from '../../../common/rules/status_rule';
import { getConditionType } from '../../../common/rules/status_rule';
import { ConfigKey, EncryptedSyntheticsMonitorAttributes } from '../../../common/runtime_types';
import { SyntheticsMonitorClient } from '../../synthetics_service/synthetics_monitor/synthetics_monitor_client';
import { monitorAttributes } from '../../../common/types/saved_objects';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
AlertInstanceContext as AlertContext,
RuleExecutorOptions,
} from '@kbn/alerting-plugin/server';
import { StatusRuleParams } from '../../../common/rules/status_rule';
import { StatusRuleParams } from '@kbn/response-ops-rule-params/synthetics_monitor_status/latest';
import { MONITOR_STATUS } from '../../../common/constants/synthetics_alerts';
import {
SyntheticsCommonState,
Expand Down

0 comments on commit 8c11159

Please sign in to comment.