From 46fdc217c1eda4e0448b37811743f0f978ed011f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20St=C3=BCrmer?= Date: Wed, 26 Jan 2022 16:30:14 +0100 Subject: [PATCH] [Infra UI] Avoid eager async imports in metric alert registrations (#123285) Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 629c602a67e090c1c5a7e7cbb61206d511f0845a) # Conflicts: # x-pack/plugins/infra/public/alerting/inventory/components/expression.tsx # x-pack/plugins/infra/public/alerting/inventory/components/metric.tsx # x-pack/plugins/infra/public/alerting/metric_anomaly/components/expression.tsx # x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.tsx # x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_row.tsx # x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/evaluate_condition.ts # x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/lib/calculate_from_based_on_metric.ts # x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/evaluate_rule.ts # x-pack/plugins/infra/server/lib/alerting/metric_threshold/register_metric_threshold_rule_type.ts # x-pack/test/api_integration/apis/metrics_ui/inventory_threshold_alert.ts --- .../infra/common/alerting/metrics/types.ts | 40 +++++++++- .../threshold_annotations.test.tsx | 10 +-- .../threshold_annotations.tsx | 10 +-- .../inventory/components/expression.test.tsx | 13 ++-- .../inventory/components/expression.tsx | 76 +++++++++---------- .../inventory/components/expression_chart.tsx | 26 +++---- .../alerting/inventory/components/metric.tsx | 28 +++---- .../inventory/components/validation.tsx | 13 ++-- .../infra/public/alerting/inventory/index.ts | 9 +-- .../expression_editor/threshold.tsx | 19 +++-- .../metric_anomaly/components/expression.tsx | 33 ++++---- .../metric_anomaly/components/validation.tsx | 3 +- .../components/expression.test.tsx | 7 +- .../components/expression.tsx | 38 +++++----- .../components/expression_chart.test.tsx | 11 ++- .../components/expression_row.test.tsx | 7 +- .../components/expression_row.tsx | 34 ++++----- .../components/validation.tsx | 13 ++-- .../public/alerting/metric_threshold/index.ts | 9 +-- .../public/alerting/metric_threshold/types.ts | 9 +-- x-pack/plugins/infra/public/plugin.ts | 9 +-- x-pack/plugins/infra/server/features.ts | 8 +- .../server/lib/alerting/common/messages.ts | 2 +- .../infra/server/lib/alerting/common/types.ts | 35 --------- .../evaluate_condition.ts | 17 +++-- .../inventory_metric_threshold_executor.ts | 17 ++--- ...er_inventory_metric_threshold_rule_type.ts | 41 +++++----- .../inventory_metric_threshold/types.ts | 27 ------- .../metric_anomaly/metric_anomaly_executor.ts | 15 ++-- .../lib/create_percentile_aggregation.ts | 3 +- .../lib/create_timerange.test.ts | 4 +- .../metric_threshold/lib/create_timerange.ts | 2 +- .../metric_threshold/lib/evaluate_rule.ts | 14 ++-- .../metric_threshold/lib/metric_query.test.ts | 4 +- .../metric_threshold/lib/metric_query.ts | 4 +- .../metric_threshold_executor.test.ts | 24 +++--- .../metric_threshold_executor.ts | 18 ++--- .../register_metric_threshold_rule_type.ts | 20 ++--- .../lib/alerting/metric_threshold/types.ts | 46 ----------- .../metrics_ui/inventory_threshold_alert.ts | 6 +- .../apis/metrics_ui/metric_threshold_alert.ts | 16 ++-- .../apis/metrics_ui/metrics_alerting.ts | 4 +- 42 files changed, 316 insertions(+), 428 deletions(-) delete mode 100644 x-pack/plugins/infra/server/lib/alerting/common/types.ts delete mode 100644 x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/types.ts delete mode 100644 x-pack/plugins/infra/server/lib/alerting/metric_threshold/types.ts diff --git a/x-pack/plugins/infra/common/alerting/metrics/types.ts b/x-pack/plugins/infra/common/alerting/metrics/types.ts index 19812a7d375171..0216f63b8f85de 100644 --- a/x-pack/plugins/infra/common/alerting/metrics/types.ts +++ b/x-pack/plugins/infra/common/alerting/metrics/types.ts @@ -4,14 +4,12 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import * as rt from 'io-ts'; import { Unit } from '@elastic/datemath'; +import * as rt from 'io-ts'; +import { SnapshotCustomMetricInput } from '../../http_api'; import { ANOMALY_THRESHOLD } from '../../infra_ml'; import { InventoryItemType, SnapshotMetricType } from '../../inventory_models/types'; -import { SnapshotCustomMetricInput } from '../../http_api'; -// TODO: Have threshold and inventory alerts import these types from this file instead of from their -// local directories export const METRIC_THRESHOLD_ALERT_TYPE_ID = 'metrics.alert.threshold'; export const METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID = 'metrics.alert.inventory.threshold'; export const METRIC_ANOMALY_ALERT_TYPE_ID = 'metrics.alert.anomaly'; @@ -37,6 +35,14 @@ export enum Aggregators { P99 = 'p99', } +export enum AlertStates { + OK, + ALERT, + WARNING, + NO_DATA, + ERROR, +} + const metricAnomalyNodeTypeRT = rt.union([rt.literal('hosts'), rt.literal('k8s')]); const metricAnomalyMetricRT = rt.union([ rt.literal('memory_usage'), @@ -80,3 +86,29 @@ export interface InventoryMetricThresholdParams { sourceId?: string; alertOnNoData?: boolean; } + +interface BaseMetricExpressionParams { + timeSize: number; + timeUnit: Unit; + sourceId?: string; + threshold: number[]; + comparator: Comparator; + warningComparator?: Comparator; + warningThreshold?: number[]; +} + +export interface NonCountMetricExpressionParams extends BaseMetricExpressionParams { + aggType: Exclude; + metric: string; +} + +export interface CountMetricExpressionParams extends BaseMetricExpressionParams { + aggType: Aggregators.COUNT; + metric: never; +} + +export type MetricExpressionParams = NonCountMetricExpressionParams | CountMetricExpressionParams; + +export const QUERY_INVALID: unique symbol = Symbol('QUERY_INVALID'); + +export type FilterQuery = string | typeof QUERY_INVALID; diff --git a/x-pack/plugins/infra/public/alerting/common/criterion_preview_chart/threshold_annotations.test.tsx b/x-pack/plugins/infra/public/alerting/common/criterion_preview_chart/threshold_annotations.test.tsx index 306a623eed984d..be8e474b601142 100644 --- a/x-pack/plugins/infra/public/alerting/common/criterion_preview_chart/threshold_annotations.test.tsx +++ b/x-pack/plugins/infra/public/alerting/common/criterion_preview_chart/threshold_annotations.test.tsx @@ -4,15 +4,11 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ +import { shallow } from 'enzyme'; import React from 'react'; -import { ThresholdAnnotations } from './threshold_annotations'; -import { - Comparator, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../server/lib/alerting/metric_threshold/types'; -// import { Color } from 'x-pack/plugins/infra/common/color_palette'; +import { Comparator } from '../../../../common/alerting/metrics'; import { Color } from '../../../../common/color_palette'; -import { shallow } from 'enzyme'; +import { ThresholdAnnotations } from './threshold_annotations'; jest.mock('@elastic/charts', () => { const original = jest.requireActual('@elastic/charts'); diff --git a/x-pack/plugins/infra/public/alerting/common/criterion_preview_chart/threshold_annotations.tsx b/x-pack/plugins/infra/public/alerting/common/criterion_preview_chart/threshold_annotations.tsx index 397d355eaeb5a9..9400537bb9d7c7 100644 --- a/x-pack/plugins/infra/public/alerting/common/criterion_preview_chart/threshold_annotations.tsx +++ b/x-pack/plugins/infra/public/alerting/common/criterion_preview_chart/threshold_annotations.tsx @@ -4,14 +4,10 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import React from 'react'; +import { AnnotationDomainType, LineAnnotation, RectAnnotation } from '@elastic/charts'; import { first, last } from 'lodash'; -import { RectAnnotation, AnnotationDomainType, LineAnnotation } from '@elastic/charts'; - -import { - Comparator, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../server/lib/alerting/metric_threshold/types'; +import React from 'react'; +import { Comparator } from '../../../../common/alerting/metrics'; import { Color, colorTransformer } from '../../../../common/color_palette'; interface ThresholdAnnotationsProps { diff --git a/x-pack/plugins/infra/public/alerting/inventory/components/expression.test.tsx b/x-pack/plugins/infra/public/alerting/inventory/components/expression.test.tsx index b345e138accec7..2aabd6a074fed8 100644 --- a/x-pack/plugins/infra/public/alerting/inventory/components/expression.test.tsx +++ b/x-pack/plugins/infra/public/alerting/inventory/components/expression.test.tsx @@ -5,17 +5,14 @@ * 2.0. */ -import { mountWithIntl, shallowWithIntl, nextTick } from '@kbn/test/jest'; -// We are using this inside a `jest.mock` call. Jest requires dynamic dependencies to be prefixed with `mock` -import { coreMock as mockCoreMock } from 'src/core/public/mocks'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { InventoryMetricConditions } from '../../../../server/lib/alerting/inventory_metric_threshold/types'; +import { mountWithIntl, nextTick, shallowWithIntl } from '@kbn/test/jest'; import React from 'react'; -import { Expressions, AlertContextMeta, ExpressionRow, defaultExpression } from './expression'; import { act } from 'react-dom/test-utils'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { Comparator } from '../../../../server/lib/alerting/metric_threshold/types'; +// We are using this inside a `jest.mock` call. Jest requires dynamic dependencies to be prefixed with `mock` +import { coreMock as mockCoreMock } from 'src/core/public/mocks'; +import { Comparator, InventoryMetricConditions } from '../../../../common/alerting/metrics'; import { SnapshotCustomMetricInput } from '../../../../common/http_api/snapshot_api'; +import { AlertContextMeta, defaultExpression, ExpressionRow, Expressions } from './expression'; jest.mock('../../../containers/metrics_source/use_source_via_http', () => ({ useSourceViaHttp: () => ({ diff --git a/x-pack/plugins/infra/public/alerting/inventory/components/expression.tsx b/x-pack/plugins/infra/public/alerting/inventory/components/expression.tsx index 3b02691fd01558..99d6f07b8f1a4a 100644 --- a/x-pack/plugins/infra/public/alerting/inventory/components/expression.tsx +++ b/x-pack/plugins/infra/public/alerting/inventory/components/expression.tsx @@ -5,72 +5,66 @@ * 2.0. */ -import { debounce, omit } from 'lodash'; import { Unit } from '@elastic/datemath'; -import React, { useCallback, useMemo, useEffect, useState, ChangeEvent } from 'react'; -import { IFieldType } from 'src/plugins/data/public'; import { + EuiButtonEmpty, + EuiButtonIcon, + EuiCheckbox, + EuiFieldSearch, EuiFlexGroup, EuiFlexItem, - EuiButtonIcon, + EuiFormRow, + EuiHealth, + EuiIcon, EuiSpacer, EuiText, - EuiFormRow, - EuiButtonEmpty, - EuiFieldSearch, - EuiCheckbox, EuiToolTip, - EuiIcon, - EuiHealth, } from '@elastic/eui'; -import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; -import { toMetricOpt } from '../../../../common/snapshot_metric_i18n'; -import { - Comparator, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../server/lib/alerting/metric_threshold/types'; +import { FormattedMessage } from '@kbn/i18n-react'; +import { debounce, omit } from 'lodash'; +import React, { ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react'; +import { IFieldType } from 'src/plugins/data/public'; import { euiStyled } from '../../../../../../../src/plugins/kibana_react/common'; import { - ThresholdExpression, - ForLastExpression, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../../triggers_actions_ui/public/common'; -import { - IErrorObject, AlertTypeParamsExpressionProps, + IErrorObject, } from '../../../../../triggers_actions_ui/public'; -import { MetricsExplorerKueryBar } from '../../../pages/metrics/metrics_explorer/components/kuery_bar'; -import { useSourceViaHttp } from '../../../containers/metrics_source/use_source_via_http'; -import { sqsMetricTypes } from '../../../../common/inventory_models/aws_sqs/toolbar_items'; +import { ForLastExpression, ThresholdExpression } from '../../../../../triggers_actions_ui/public'; +import { + Comparator, + InventoryMetricConditions, + FilterQuery, + QUERY_INVALID, +} from '../../../../common/alerting/metrics'; +import { + SnapshotCustomMetricInput, + SnapshotCustomMetricInputRT, +} from '../../../../common/http_api/snapshot_api'; +import { findInventoryModel } from '../../../../common/inventory_models'; import { ec2MetricTypes } from '../../../../common/inventory_models/aws_ec2/toolbar_items'; -import { s3MetricTypes } from '../../../../common/inventory_models/aws_s3/toolbar_items'; import { rdsMetricTypes } from '../../../../common/inventory_models/aws_rds/toolbar_items'; -import { hostMetricTypes } from '../../../../common/inventory_models/host/toolbar_items'; +import { s3MetricTypes } from '../../../../common/inventory_models/aws_s3/toolbar_items'; +import { sqsMetricTypes } from '../../../../common/inventory_models/aws_sqs/toolbar_items'; import { containerMetricTypes } from '../../../../common/inventory_models/container/toolbar_items'; +import { hostMetricTypes } from '../../../../common/inventory_models/host/toolbar_items'; import { podMetricTypes } from '../../../../common/inventory_models/pod/toolbar_items'; -import { findInventoryModel } from '../../../../common/inventory_models'; import { InventoryItemType, SnapshotMetricType, SnapshotMetricTypeRT, } from '../../../../common/inventory_models/types'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { InventoryMetricConditions } from '../../../../server/lib/alerting/inventory_metric_threshold/types'; -import { MetricExpression } from './metric'; -import { NodeTypeExpression } from './node_type'; +import { toMetricOpt } from '../../../../common/snapshot_metric_i18n'; +import { useSourceViaHttp } from '../../../containers/metrics_source/use_source_via_http'; +import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; import { InfraWaffleMapOptions } from '../../../lib/lib'; +import { MetricsExplorerKueryBar } from '../../../pages/metrics/metrics_explorer/components/kuery_bar'; import { convertKueryToElasticSearchQuery } from '../../../utils/kuery'; -import { - SnapshotCustomMetricInput, - SnapshotCustomMetricInputRT, -} from '../../../../common/http_api/snapshot_api'; - -import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; - import { ExpressionChart } from './expression_chart'; +import { MetricExpression } from './metric'; +import { NodeTypeExpression } from './node_type'; + const FILTER_TYPING_DEBOUNCE_MS = 500; -export const QUERY_INVALID = Symbol('QUERY_INVALID'); export interface AlertContextMeta { options?: Partial; @@ -85,7 +79,7 @@ type Props = Omit< { criteria: Criteria; nodeType: InventoryItemType; - filterQuery?: string | symbol; + filterQuery?: FilterQuery; filterQueryText?: string; sourceId: string; alertOnNoData?: boolean; diff --git a/x-pack/plugins/infra/public/alerting/inventory/components/expression_chart.tsx b/x-pack/plugins/infra/public/alerting/inventory/components/expression_chart.tsx index a83aa2ec12676c..4902a2d309b202 100644 --- a/x-pack/plugins/infra/public/alerting/inventory/components/expression_chart.tsx +++ b/x-pack/plugins/infra/public/alerting/inventory/components/expression_chart.tsx @@ -4,35 +4,33 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import React, { useMemo, useCallback } from 'react'; import { Axis, Chart, niceTimeFormatter, Position, Settings } from '@elastic/charts'; -import { first, last } from 'lodash'; -import moment from 'moment'; import { EuiText } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; +import { first, last } from 'lodash'; +import moment from 'moment'; +import React, { useCallback, useMemo } from 'react'; +import { InventoryMetricConditions } from '../../../../common/alerting/metrics'; import { Color } from '../../../../common/color_palette'; -import { MetricsExplorerRow, MetricsExplorerAggregation } from '../../../../common/http_api'; -import { MetricExplorerSeriesChart } from '../../../pages/metrics/metrics_explorer/components/series_chart'; -import { MetricsExplorerChartType } from '../../../pages/metrics/metrics_explorer/hooks/use_metrics_explorer_options'; -import { calculateDomain } from '../../../pages/metrics/metrics_explorer/components/helpers/calculate_domain'; -import { getMetricId } from '../../../pages/metrics/metrics_explorer/components/helpers/get_metric_id'; +import { MetricsExplorerAggregation, MetricsExplorerRow } from '../../../../common/http_api'; +import { InventoryItemType, SnapshotMetricType } from '../../../../common/inventory_models/types'; import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { InventoryMetricConditions } from '../../../../server/lib/alerting/inventory_metric_threshold/types'; import { useSnapshot } from '../../../pages/metrics/inventory_view/hooks/use_snaphot'; -import { InventoryItemType, SnapshotMetricType } from '../../../../common/inventory_models/types'; +import { useWaffleOptionsContext } from '../../../pages/metrics/inventory_view/hooks/use_waffle_options'; import { createInventoryMetricFormatter } from '../../../pages/metrics/inventory_view/lib/create_inventory_metric_formatter'; - +import { calculateDomain } from '../../../pages/metrics/metrics_explorer/components/helpers/calculate_domain'; +import { getMetricId } from '../../../pages/metrics/metrics_explorer/components/helpers/get_metric_id'; +import { MetricExplorerSeriesChart } from '../../../pages/metrics/metrics_explorer/components/series_chart'; +import { MetricsExplorerChartType } from '../../../pages/metrics/metrics_explorer/hooks/use_metrics_explorer_options'; import { ChartContainer, + getChartTheme, LoadingState, NoDataState, TIME_LABELS, tooltipProps, - getChartTheme, } from '../../common/criterion_preview_chart/criterion_preview_chart'; import { ThresholdAnnotations } from '../../common/criterion_preview_chart/threshold_annotations'; -import { useWaffleOptionsContext } from '../../../pages/metrics/inventory_view/hooks/use_waffle_options'; interface Props { expression: InventoryMetricConditions; diff --git a/x-pack/plugins/infra/public/alerting/inventory/components/metric.tsx b/x-pack/plugins/infra/public/alerting/inventory/components/metric.tsx index 9b4086515edca9..0dcaed7de2d579 100644 --- a/x-pack/plugins/infra/public/alerting/inventory/components/metric.tsx +++ b/x-pack/plugins/infra/public/alerting/inventory/components/metric.tsx @@ -5,34 +5,34 @@ * 2.0. */ -import React, { useState, useCallback, useMemo } from 'react'; -import { i18n } from '@kbn/i18n'; -import { FormattedMessage } from '@kbn/i18n-react'; -import { debounce } from 'lodash'; import { + EuiButtonGroup, + EuiButtonIcon, + EuiComboBox, EuiExpression, - EuiPopover, + EuiFieldText, EuiFlexGroup, EuiFlexItem, EuiFormRow, - EuiComboBox, - EuiButtonGroup, - EuiSpacer, + EuiPopover, + EuiPopoverTitle, EuiSelect, + EuiSpacer, EuiText, - EuiFieldText, } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n-react'; +import { debounce } from 'lodash'; +import React, { useCallback, useMemo, useState } from 'react'; import { IFieldType } from 'src/plugins/data/public'; -import { EuiPopoverTitle, EuiButtonIcon } from '@elastic/eui'; +import { IErrorObject } from '../../../../../triggers_actions_ui/public'; import { getCustomMetricLabel } from '../../../../common/formatters/get_custom_metric_label'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { IErrorObject } from '../../../../../triggers_actions_ui/public/types'; import { + SnapshotCustomAggregation, + SnapshotCustomAggregationRT, SnapshotCustomMetricInput, SnapshotCustomMetricInputRT, - SnapshotCustomAggregation, SNAPSHOT_CUSTOM_AGGREGATIONS, - SnapshotCustomAggregationRT, } from '../../../../common/http_api/snapshot_api'; interface Props { diff --git a/x-pack/plugins/infra/public/alerting/inventory/components/validation.tsx b/x-pack/plugins/infra/public/alerting/inventory/components/validation.tsx index 561bb39c6dce72..e093ea789cf795 100644 --- a/x-pack/plugins/infra/public/alerting/inventory/components/validation.tsx +++ b/x-pack/plugins/infra/public/alerting/inventory/components/validation.tsx @@ -6,21 +6,20 @@ */ import { i18n } from '@kbn/i18n'; +import type { ValidationResult } from '../../../../../triggers_actions_ui/public'; import { - InventoryMetricConditions, Comparator, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../server/lib/alerting/inventory_metric_threshold/types'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { ValidationResult } from '../../../../../triggers_actions_ui/public/types'; -import { QUERY_INVALID } from './expression'; + FilterQuery, + InventoryMetricConditions, + QUERY_INVALID, +} from '../../../../common/alerting/metrics'; export function validateMetricThreshold({ criteria, filterQuery, }: { criteria: InventoryMetricConditions[]; - filterQuery?: string | symbol; + filterQuery?: FilterQuery; }): ValidationResult { const validationResult = { errors: {} }; const errors: { diff --git a/x-pack/plugins/infra/public/alerting/inventory/index.ts b/x-pack/plugins/infra/public/alerting/inventory/index.ts index 4a724694bbad88..2d38d7afbd8d09 100644 --- a/x-pack/plugins/infra/public/alerting/inventory/index.ts +++ b/x-pack/plugins/infra/public/alerting/inventory/index.ts @@ -7,15 +7,12 @@ import { i18n } from '@kbn/i18n'; import React from 'react'; +import { AlertTypeParams as RuleTypeParams } from '../../../../alerting/common'; +import { ObservabilityRuleTypeModel } from '../../../../observability/public'; import { InventoryMetricConditions, METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../server/lib/alerting/inventory_metric_threshold/types'; - -import { ObservabilityRuleTypeModel } from '../../../../observability/public'; - -import { AlertTypeParams as RuleTypeParams } from '../../../../alerting/common'; +} from '../../../common/alerting/metrics'; import { validateMetricThreshold } from './components/validation'; import { formatReason } from './rule_data_formatters'; diff --git a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/threshold.tsx b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/threshold.tsx index fdc60daceb7156..6b3023123cd8c1 100644 --- a/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/threshold.tsx +++ b/x-pack/plugins/infra/public/alerting/log_threshold/components/expression_editor/threshold.tsx @@ -5,21 +5,20 @@ * 2.0. */ -import React, { useState } from 'react'; -import { i18n } from '@kbn/i18n'; -import { isNumber, isFinite } from 'lodash'; import { - EuiPopoverTitle, - EuiFlexItem, + EuiExpression, + EuiFieldNumber, EuiFlexGroup, + EuiFlexItem, + EuiFormRow, EuiPopover, + EuiPopoverTitle, EuiSelect, - EuiFieldNumber, - EuiExpression, - EuiFormRow, } from '@elastic/eui'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { IErrorObject } from '../../../../../../triggers_actions_ui/public/types'; +import { i18n } from '@kbn/i18n'; +import { isFinite, isNumber } from 'lodash'; +import React, { useState } from 'react'; +import { IErrorObject } from '../../../../../../triggers_actions_ui/public'; import { Comparator, ComparatorToi18nMap, diff --git a/x-pack/plugins/infra/public/alerting/metric_anomaly/components/expression.tsx b/x-pack/plugins/infra/public/alerting/metric_anomaly/components/expression.tsx index ca38f98534db39..9436dd55542796 100644 --- a/x-pack/plugins/infra/public/alerting/metric_anomaly/components/expression.tsx +++ b/x-pack/plugins/infra/public/alerting/metric_anomaly/components/expression.tsx @@ -5,34 +5,29 @@ * 2.0. */ -import React, { useCallback, useState, useMemo, useEffect } from 'react'; -import { EuiFlexGroup, EuiSpacer, EuiText, EuiLoadingContent } from '@elastic/eui'; -import { FormattedMessage } from '@kbn/i18n-react'; +import { EuiFlexGroup, EuiLoadingContent, EuiSpacer, EuiText } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { useInfraMLCapabilities } from '../../../containers/ml/infra_ml_capabilities'; -import { SubscriptionSplashPrompt } from '../../../components/subscription_splash_content'; -import { MetricAnomalyParams } from '../../../../common/alerting/metrics'; +import { FormattedMessage } from '@kbn/i18n-react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { euiStyled, EuiThemeProvider } from '../../../../../../../src/plugins/kibana_react/common'; -import { - WhenExpression, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../../triggers_actions_ui/public/common'; import { AlertTypeParams, AlertTypeParamsExpressionProps, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../../triggers_actions_ui/public/types'; -import { useSourceViaHttp } from '../../../containers/metrics_source/use_source_via_http'; + WhenExpression, +} from '../../../../../triggers_actions_ui/public'; +import { MetricAnomalyParams } from '../../../../common/alerting/metrics'; +import { ANOMALY_THRESHOLD } from '../../../../common/infra_ml'; import { findInventoryModel } from '../../../../common/inventory_models'; import { InventoryItemType, SnapshotMetricType } from '../../../../common/inventory_models/types'; -import { NodeTypeExpression } from './node_type'; -import { SeverityThresholdExpression } from './severity_threshold'; -import { InfraWaffleMapOptions } from '../../../lib/lib'; -import { ANOMALY_THRESHOLD } from '../../../../common/infra_ml'; - -import { InfluencerFilter } from './influencer_filter'; +import { SubscriptionSplashPrompt } from '../../../components/subscription_splash_content'; +import { useSourceViaHttp } from '../../../containers/metrics_source/use_source_via_http'; +import { useInfraMLCapabilities } from '../../../containers/ml/infra_ml_capabilities'; import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; import { useActiveKibanaSpace } from '../../../hooks/use_kibana_space'; +import { InfraWaffleMapOptions } from '../../../lib/lib'; +import { InfluencerFilter } from './influencer_filter'; +import { NodeTypeExpression } from './node_type'; +import { SeverityThresholdExpression } from './severity_threshold'; export interface AlertContextMeta { metric?: InfraWaffleMapOptions['metric']; diff --git a/x-pack/plugins/infra/public/alerting/metric_anomaly/components/validation.tsx b/x-pack/plugins/infra/public/alerting/metric_anomaly/components/validation.tsx index 8e254fb2b67a8b..a4eda632b2fdd8 100644 --- a/x-pack/plugins/infra/public/alerting/metric_anomaly/components/validation.tsx +++ b/x-pack/plugins/infra/public/alerting/metric_anomaly/components/validation.tsx @@ -6,8 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { ValidationResult } from '../../../../../triggers_actions_ui/public/types'; +import type { ValidationResult } from '../../../../../triggers_actions_ui/public'; export function validateMetricAnomaly({ hasInfraMLCapabilities, diff --git a/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.test.tsx b/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.test.tsx index 667f5c061ce485..7a508e0c77e317 100644 --- a/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.test.tsx +++ b/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.test.tsx @@ -6,14 +6,13 @@ */ import { mountWithIntl, nextTick } from '@kbn/test/jest'; +import React from 'react'; +import { act } from 'react-dom/test-utils'; // We are using this inside a `jest.mock` call. Jest requires dynamic dependencies to be prefixed with `mock` import { coreMock as mockCoreMock } from 'src/core/public/mocks'; +import { Comparator } from '../../../../common/alerting/metrics'; import { MetricsExplorerMetric } from '../../../../common/http_api/metrics_explorer'; -import React from 'react'; import { Expressions } from './expression'; -import { act } from 'react-dom/test-utils'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { Comparator } from '../../../../server/lib/alerting/metric_threshold/types'; jest.mock('../../../containers/metrics_source/use_source_via_http', () => ({ useSourceViaHttp: () => ({ diff --git a/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.tsx b/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.tsx index 6488e5664103bf..59466d7ada15c5 100644 --- a/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.tsx +++ b/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression.tsx @@ -5,44 +5,42 @@ * 2.0. */ -import { debounce } from 'lodash'; import { Unit } from '@elastic/datemath'; -import React, { ChangeEvent, useCallback, useMemo, useEffect, useState } from 'react'; import { - EuiSpacer, - EuiText, - EuiFormRow, + EuiAccordion, EuiButtonEmpty, EuiCheckbox, - EuiToolTip, - EuiIcon, EuiFieldSearch, - EuiAccordion, - EuiPanel, + EuiFormRow, + EuiIcon, EuiLink, + EuiPanel, + EuiSpacer, + EuiText, + EuiToolTip, } from '@elastic/eui'; -import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; -import { Comparator, Aggregators } from '../../../../common/alerting/metrics'; -import { ForLastExpression } from '../../../../../triggers_actions_ui/public'; +import { FormattedMessage } from '@kbn/i18n-react'; +import { debounce } from 'lodash'; +import React, { ChangeEvent, useCallback, useEffect, useMemo, useState } from 'react'; import { - IErrorObject, AlertTypeParams, AlertTypeParamsExpressionProps, + ForLastExpression, + IErrorObject, } from '../../../../../triggers_actions_ui/public'; +import { Aggregators, Comparator, QUERY_INVALID } from '../../../../common/alerting/metrics'; +import { useSourceViaHttp } from '../../../containers/metrics_source/use_source_via_http'; +import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; +import { MetricsExplorerGroupBy } from '../../../pages/metrics/metrics_explorer/components/group_by'; import { MetricsExplorerKueryBar } from '../../../pages/metrics/metrics_explorer/components/kuery_bar'; import { MetricsExplorerOptions } from '../../../pages/metrics/metrics_explorer/hooks/use_metrics_explorer_options'; -import { MetricsExplorerGroupBy } from '../../../pages/metrics/metrics_explorer/components/group_by'; -import { useSourceViaHttp } from '../../../containers/metrics_source/use_source_via_http'; import { convertKueryToElasticSearchQuery } from '../../../utils/kuery'; - -import { ExpressionRow } from './expression_row'; -import { MetricExpression, AlertParams, AlertContextMeta } from '../types'; +import { AlertContextMeta, AlertParams, MetricExpression } from '../types'; import { ExpressionChart } from './expression_chart'; -import { useKibanaContextForPlugin } from '../../../hooks/use_kibana'; +import { ExpressionRow } from './expression_row'; const FILTER_TYPING_DEBOUNCE_MS = 500; -export const QUERY_INVALID = Symbol('QUERY_INVALID'); type Props = Omit< AlertTypeParamsExpressionProps, diff --git a/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_chart.test.tsx b/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_chart.test.tsx index c2c1fa719bb95b..f7e3201bbf2c92 100644 --- a/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_chart.test.tsx +++ b/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_chart.test.tsx @@ -5,17 +5,16 @@ * 2.0. */ +import { DataViewBase } from '@kbn/es-query'; import { mountWithIntl, nextTick } from '@kbn/test/jest'; +import React from 'react'; +import { act } from 'react-dom/test-utils'; // We are using this inside a `jest.mock` call. Jest requires dynamic dependencies to be prefixed with `mock` import { coreMock as mockCoreMock } from 'src/core/public/mocks'; -import { MetricExpression } from '../types'; -import { DataViewBase } from '@kbn/es-query'; +import { Aggregators, Comparator } from '../../../../common/alerting/metrics'; import { MetricsSourceConfiguration } from '../../../../common/metrics_sources'; -import React from 'react'; +import { MetricExpression } from '../types'; import { ExpressionChart } from './expression_chart'; -import { act } from 'react-dom/test-utils'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { Aggregators, Comparator } from '../../../../server/lib/alerting/metric_threshold/types'; const mockStartServices = mockCoreMock.createStart(); jest.mock('../../../hooks/use_kibana', () => ({ diff --git a/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_row.test.tsx b/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_row.test.tsx index 90f75e6a940220..b21e7de28156e1 100644 --- a/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_row.test.tsx +++ b/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_row.test.tsx @@ -6,12 +6,11 @@ */ import { mountWithIntl, nextTick } from '@kbn/test/jest'; -import { MetricExpression } from '../types'; import React from 'react'; -import { ExpressionRow } from './expression_row'; import { act } from 'react-dom/test-utils'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { Comparator } from '../../../../server/lib/alerting/metric_threshold/types'; +import { Comparator } from '../../../../common/alerting/metrics'; +import { MetricExpression } from '../types'; +import { ExpressionRow } from './expression_row'; jest.mock('../../../containers/metrics_source/use_source_via_http', () => ({ useSourceViaHttp: () => ({ diff --git a/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_row.tsx b/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_row.tsx index a0640b8d5f74b2..17c1bbf68cc3b8 100644 --- a/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_row.tsx +++ b/x-pack/plugins/infra/public/alerting/metric_threshold/components/expression_row.tsx @@ -4,35 +4,33 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { omit } from 'lodash'; -import React, { useCallback, useState, useMemo } from 'react'; -import { i18n } from '@kbn/i18n'; -import { FormattedMessage } from '@kbn/i18n-react'; + import { + EuiButtonEmpty, + EuiButtonIcon, EuiFlexGroup, EuiFlexItem, - EuiButtonIcon, + EuiHealth, + EuiLink, EuiSpacer, EuiText, - EuiLink, - EuiHealth, - EuiButtonEmpty, } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n-react'; +import { omit } from 'lodash'; +import React, { useCallback, useMemo, useState } from 'react'; import { IFieldType } from 'src/plugins/data/public'; -import { pctToDecimal, decimalToPct } from '../../../../common/utils/corrected_percent_convert'; +import { euiStyled } from '../../../../../../../src/plugins/kibana_react/common'; import { - WhenExpression, + builtInComparators, + IErrorObject, OfExpression, ThresholdExpression, + WhenExpression, } from '../../../../../triggers_actions_ui/public'; -import { euiStyled } from '../../../../../../../src/plugins/kibana_react/common'; -import { IErrorObject } from '../../../../../triggers_actions_ui/public'; -import { MetricExpression, AGGREGATION_TYPES } from '../types'; -import { - Comparator, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../server/lib/alerting/metric_threshold/types'; -import { builtInComparators } from '../../../../../triggers_actions_ui/public'; +import { Comparator } from '../../../../common/alerting/metrics'; +import { decimalToPct, pctToDecimal } from '../../../../common/utils/corrected_percent_convert'; +import { AGGREGATION_TYPES, MetricExpression } from '../types'; const customComparators = { ...builtInComparators, diff --git a/x-pack/plugins/infra/public/alerting/metric_threshold/components/validation.tsx b/x-pack/plugins/infra/public/alerting/metric_threshold/components/validation.tsx index 8df313aa1627a4..8634c3686087ff 100644 --- a/x-pack/plugins/infra/public/alerting/metric_threshold/components/validation.tsx +++ b/x-pack/plugins/infra/public/alerting/metric_threshold/components/validation.tsx @@ -6,21 +6,20 @@ */ import { i18n } from '@kbn/i18n'; +import { ValidationResult } from '../../../../../triggers_actions_ui/public'; import { - MetricExpressionParams, Comparator, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../../server/lib/alerting/metric_threshold/types'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { ValidationResult } from '../../../../../triggers_actions_ui/public/types'; -import { QUERY_INVALID } from './expression'; + FilterQuery, + MetricExpressionParams, + QUERY_INVALID, +} from '../../../../common/alerting/metrics'; export function validateMetricThreshold({ criteria, filterQuery, }: { criteria: MetricExpressionParams[]; - filterQuery?: string | symbol; + filterQuery?: FilterQuery; }): ValidationResult { const validationResult = { errors: {} }; const errors: { diff --git a/x-pack/plugins/infra/public/alerting/metric_threshold/index.ts b/x-pack/plugins/infra/public/alerting/metric_threshold/index.ts index d45d090e0ec929..6ece554972a782 100644 --- a/x-pack/plugins/infra/public/alerting/metric_threshold/index.ts +++ b/x-pack/plugins/infra/public/alerting/metric_threshold/index.ts @@ -7,15 +7,14 @@ import { i18n } from '@kbn/i18n'; import React from 'react'; -import { ObservabilityRuleTypeModel } from '../../../../observability/public'; -import { validateMetricThreshold } from './components/validation'; -import { formatReason } from './rule_data_formatters'; import { AlertTypeParams as RuleTypeParams } from '../../../../alerting/common'; +import { ObservabilityRuleTypeModel } from '../../../../observability/public'; import { MetricExpressionParams, METRIC_THRESHOLD_ALERT_TYPE_ID, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../server/lib/alerting/metric_threshold/types'; +} from '../../../common/alerting/metrics'; +import { validateMetricThreshold } from './components/validation'; +import { formatReason } from './rule_data_formatters'; interface MetricThresholdRuleTypeParams extends RuleTypeParams { criteria: MetricExpressionParams[]; diff --git a/x-pack/plugins/infra/public/alerting/metric_threshold/types.ts b/x-pack/plugins/infra/public/alerting/metric_threshold/types.ts index 0d1c85087f33d9..a88dd1d4548b8d 100644 --- a/x-pack/plugins/infra/public/alerting/metric_threshold/types.ts +++ b/x-pack/plugins/infra/public/alerting/metric_threshold/types.ts @@ -5,12 +5,9 @@ * 2.0. */ -import { - MetricExpressionParams, - // eslint-disable-next-line @kbn/eslint/no-restricted-paths -} from '../../../server/lib/alerting/metric_threshold/types'; -import { MetricsExplorerOptions } from '../../pages/metrics/metrics_explorer/hooks/use_metrics_explorer_options'; +import { FilterQuery, MetricExpressionParams } from '../../../common/alerting/metrics'; import { MetricsExplorerSeries } from '../../../common/http_api/metrics_explorer'; +import { MetricsExplorerOptions } from '../../pages/metrics/metrics_explorer/hooks/use_metrics_explorer_options'; export interface AlertContextMeta { currentOptions?: Partial; @@ -57,7 +54,7 @@ export interface ExpressionChartData { export interface AlertParams { criteria: MetricExpression[]; groupBy?: string | string[]; - filterQuery?: string | symbol; + filterQuery?: FilterQuery; sourceId: string; filterQueryText?: string; alertOnNoData?: boolean; diff --git a/x-pack/plugins/infra/public/plugin.ts b/x-pack/plugins/infra/public/plugin.ts index bc3aff9f016372..1eb016f5829392 100644 --- a/x-pack/plugins/infra/public/plugin.ts +++ b/x-pack/plugins/infra/public/plugin.ts @@ -10,6 +10,9 @@ import { AppMountParameters, PluginInitializerContext } from 'kibana/public'; import { from } from 'rxjs'; import { map } from 'rxjs/operators'; import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/public'; +import { createInventoryMetricRuleType } from './alerting/inventory'; +import { createLogThresholdRuleType } from './alerting/log_threshold'; +import { createMetricThresholdRuleType } from './alerting/metric_threshold'; import { LOG_STREAM_EMBEDDABLE } from './components/log_stream/log_stream_embeddable'; import { LogStreamEmbeddableFactoryDefinition } from './components/log_stream/log_stream_embeddable_factory'; import { createMetricsFetchData, createMetricsHasData } from './metrics_overview_fetchers'; @@ -26,15 +29,11 @@ import { getLogsHasDataFetcher, getLogsOverviewDataFetcher } from './utils/logs_ export class Plugin implements InfraClientPluginClass { constructor(_context: PluginInitializerContext) {} - async setup(core: InfraClientCoreSetup, pluginsSetup: InfraClientSetupDeps) { + setup(core: InfraClientCoreSetup, pluginsSetup: InfraClientSetupDeps) { if (pluginsSetup.home) { registerFeatures(pluginsSetup.home); } - const { createInventoryMetricRuleType } = await import('./alerting/inventory'); - const { createLogThresholdRuleType } = await import('./alerting/log_threshold'); - const { createMetricThresholdRuleType } = await import('./alerting/metric_threshold'); - pluginsSetup.observability.observabilityRuleTypeRegistry.register( createInventoryMetricRuleType() ); diff --git a/x-pack/plugins/infra/server/features.ts b/x-pack/plugins/infra/server/features.ts index 361565c3672c54..3e7ede11f7e9d3 100644 --- a/x-pack/plugins/infra/server/features.ts +++ b/x-pack/plugins/infra/server/features.ts @@ -6,10 +6,12 @@ */ import { i18n } from '@kbn/i18n'; -import { LOG_DOCUMENT_COUNT_RULE_TYPE_ID } from '../common/alerting/logs/log_threshold/types'; -import { METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID } from './lib/alerting/inventory_metric_threshold/types'; -import { METRIC_THRESHOLD_ALERT_TYPE_ID } from './lib/alerting/metric_threshold/types'; import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/server'; +import { LOG_DOCUMENT_COUNT_RULE_TYPE_ID } from '../common/alerting/logs/log_threshold/types'; +import { + METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID, + METRIC_THRESHOLD_ALERT_TYPE_ID, +} from '../common/alerting/metrics'; import { LOGS_FEATURE_ID, METRICS_FEATURE_ID } from '../common/constants'; export const METRICS_FEATURE = { diff --git a/x-pack/plugins/infra/server/lib/alerting/common/messages.ts b/x-pack/plugins/infra/server/lib/alerting/common/messages.ts index 0a3b41190a0883..d92670a4eb5f61 100644 --- a/x-pack/plugins/infra/server/lib/alerting/common/messages.ts +++ b/x-pack/plugins/infra/server/lib/alerting/common/messages.ts @@ -6,7 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -import { Comparator, AlertStates } from './types'; +import { AlertStates, Comparator } from '../../../../common/alerting/metrics'; export const DOCUMENT_COUNT_I18N = i18n.translate( 'xpack.infra.metrics.alerting.threshold.documentCount', diff --git a/x-pack/plugins/infra/server/lib/alerting/common/types.ts b/x-pack/plugins/infra/server/lib/alerting/common/types.ts deleted file mode 100644 index 1d038cace14fe1..00000000000000 --- a/x-pack/plugins/infra/server/lib/alerting/common/types.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 enum Comparator { - GT = '>', - LT = '<', - GT_OR_EQ = '>=', - LT_OR_EQ = '<=', - BETWEEN = 'between', - OUTSIDE_RANGE = 'outside', -} - -export enum Aggregators { - COUNT = 'count', - AVERAGE = 'avg', - SUM = 'sum', - MIN = 'min', - MAX = 'max', - RATE = 'rate', - CARDINALITY = 'cardinality', - P95 = 'p95', - P99 = 'p99', -} - -export enum AlertStates { - OK, - ALERT, - WARNING, - NO_DATA, - ERROR, -} diff --git a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/evaluate_condition.ts b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/evaluate_condition.ts index 9cefb0cf102105..b4c4cb1e495d58 100644 --- a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/evaluate_condition.ts +++ b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/evaluate_condition.ts @@ -5,25 +5,26 @@ * 2.0. */ -import moment from 'moment'; import { ElasticsearchClient } from 'kibana/server'; -import { mapValues, last, first } from 'lodash'; +import { first, last, mapValues } from 'lodash'; +import moment from 'moment'; import { + Comparator, + InventoryMetricConditions, isTooManyBucketsPreviewException, TOO_MANY_BUCKETS_PREVIEW_EXCEPTION, } from '../../../../common/alerting/metrics'; -import { InfraDatabaseSearchResponse, CallWithRequestParams } from '../../adapters/framework'; -import { Comparator, InventoryMetricConditions } from './types'; -import { InventoryItemType, SnapshotMetricType } from '../../../../common/inventory_models/types'; import { InfraTimerangeInput, - SnapshotRequest, SnapshotCustomMetricInput, + SnapshotRequest, } from '../../../../common/http_api'; -import { InfraSource } from '../../sources'; -import { UNGROUPED_FACTORY_KEY } from '../common/utils'; +import { InventoryItemType, SnapshotMetricType } from '../../../../common/inventory_models/types'; import { getNodes } from '../../../routes/snapshot/lib/get_nodes'; import { LogQueryFields } from '../../../services/log_queries/get_log_query_fields'; +import { CallWithRequestParams, InfraDatabaseSearchResponse } from '../../adapters/framework'; +import { InfraSource } from '../../sources'; +import { UNGROUPED_FACTORY_KEY } from '../common/utils'; type ConditionResult = InventoryMetricConditions & { shouldFire: boolean[]; diff --git a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts index 9ffde130b93179..87bfe122f679d9 100644 --- a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/inventory_metric_threshold_executor.ts @@ -7,14 +7,11 @@ import { i18n } from '@kbn/i18n'; import { ALERT_REASON, ALERT_RULE_PARAMETERS } from '@kbn/rule-data-utils'; -import moment from 'moment'; import { first, get, last } from 'lodash'; -import { getCustomMetricLabel } from '../../../../common/formatters/get_custom_metric_label'; -import { toMetricOpt } from '../../../../common/snapshot_metric_i18n'; -import { AlertStates } from './types'; +import moment from 'moment'; import { - ActionGroupIdsOf, ActionGroup, + ActionGroupIdsOf, AlertInstanceContext as AlertContext, AlertInstanceState as AlertState, RecoveredActionGroup, @@ -23,18 +20,20 @@ import { AlertInstance as Alert, AlertTypeState as RuleTypeState, } from '../../../../../alerting/server'; +import { AlertStates, InventoryMetricThresholdParams } from '../../../../common/alerting/metrics'; +import { createFormatter } from '../../../../common/formatters'; +import { getCustomMetricLabel } from '../../../../common/formatters/get_custom_metric_label'; +import { METRIC_FORMATTERS } from '../../../../common/formatters/snapshot_metric_formats'; import { SnapshotMetricType } from '../../../../common/inventory_models/types'; +import { toMetricOpt } from '../../../../common/snapshot_metric_i18n'; import { InfraBackendLibs } from '../../infra_types'; -import { METRIC_FORMATTERS } from '../../../../common/formatters/snapshot_metric_formats'; -import { createFormatter } from '../../../../common/formatters'; -import { InventoryMetricThresholdParams } from '../../../../common/alerting/metrics'; import { buildErrorAlertReason, buildFiredAlertReason, + buildInvalidQueryAlertReason, buildNoDataAlertReason, // buildRecoveredAlertReason, stateToAlertMessage, - buildInvalidQueryAlertReason, } from '../common/messages'; import { evaluateCondition } from './evaluate_condition'; diff --git a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/register_inventory_metric_threshold_rule_type.ts b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/register_inventory_metric_threshold_rule_type.ts index 9776d1ab669154..ac68a0df706fb4 100644 --- a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/register_inventory_metric_threshold_rule_type.ts +++ b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/register_inventory_metric_threshold_rule_type.ts @@ -5,37 +5,40 @@ * 2.0. */ -import { schema, Type } from '@kbn/config-schema'; import { Unit } from '@elastic/datemath'; +import { schema, Type } from '@kbn/config-schema'; import { i18n } from '@kbn/i18n'; import { PluginSetupContract } from '../../../../../alerting/server'; import { - createInventoryMetricThresholdExecutor, - FIRED_ACTIONS, - FIRED_ACTIONS_ID, - WARNING_ACTIONS, -} from './inventory_metric_threshold_executor'; -import { METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID, Comparator } from './types'; + Comparator, + METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID, +} from '../../../../common/alerting/metrics'; +import { + SnapshotCustomAggregation, + SNAPSHOT_CUSTOM_AGGREGATIONS, +} from '../../../../common/http_api/snapshot_api'; +import { + InventoryItemType, + SnapshotMetricType, + SnapshotMetricTypeKeys, +} from '../../../../common/inventory_models/types'; import { InfraBackendLibs } from '../../infra_types'; -import { oneOfLiterals, validateIsStringElasticsearchJSONFilter } from '../common/utils'; import { - groupActionVariableDescription, alertStateActionVariableDescription, + groupActionVariableDescription, + metricActionVariableDescription, reasonActionVariableDescription, + thresholdActionVariableDescription, timestampActionVariableDescription, valueActionVariableDescription, - metricActionVariableDescription, - thresholdActionVariableDescription, } from '../common/messages'; +import { oneOfLiterals, validateIsStringElasticsearchJSONFilter } from '../common/utils'; import { - SnapshotMetricTypeKeys, - SnapshotMetricType, - InventoryItemType, -} from '../../../../common/inventory_models/types'; -import { - SNAPSHOT_CUSTOM_AGGREGATIONS, - SnapshotCustomAggregation, -} from '../../../../common/http_api/snapshot_api'; + createInventoryMetricThresholdExecutor, + FIRED_ACTIONS, + FIRED_ACTIONS_ID, + WARNING_ACTIONS, +} from './inventory_metric_threshold_executor'; const condition = schema.object({ threshold: schema.arrayOf(schema.number()), diff --git a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/types.ts b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/types.ts deleted file mode 100644 index 829f34d42ee039..00000000000000 --- a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/types.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 { Unit } from '@elastic/datemath'; -import { SnapshotCustomMetricInput } from '../../../../common/http_api/snapshot_api'; -import { SnapshotMetricType } from '../../../../common/inventory_models/types'; -import { Comparator, AlertStates, Aggregators } from '../common/types'; - -export { Comparator, AlertStates, Aggregators }; - -export const METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID = 'metrics.alert.inventory.threshold'; - -export interface InventoryMetricConditions { - metric: SnapshotMetricType; - timeSize: number; - timeUnit: Unit; - sourceId?: string; - threshold: number[]; - comparator: Comparator; - customMetric?: SnapshotCustomMetricInput; - warningThreshold?: number[]; - warningComparator?: Comparator; -} diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_anomaly/metric_anomaly_executor.ts b/x-pack/plugins/infra/server/lib/alerting/metric_anomaly/metric_anomaly_executor.ts index a0eac87ed161eb..f762d694a59e70 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_anomaly/metric_anomaly_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_anomaly/metric_anomaly_executor.ts @@ -6,27 +6,26 @@ */ import { i18n } from '@kbn/i18n'; +import { KibanaRequest } from 'kibana/server'; import { first } from 'lodash'; import moment from 'moment'; -import { KibanaRequest } from 'kibana/server'; -import { stateToAlertMessage } from '../common/messages'; -import { MetricAnomalyParams } from '../../../../common/alerting/metrics'; -import { MappedAnomalyHit } from '../../infra_ml'; -import { AlertStates } from '../common/types'; import { ActionGroup, AlertInstanceContext as AlertContext, AlertInstanceState as AlertState, } from '../../../../../alerting/common'; import { AlertExecutorOptions as RuleExecutorOptions } from '../../../../../alerting/server'; -import { getIntervalInSeconds } from '../../../utils/get_interval_in_seconds'; -import { MetricAnomalyAllowedActionGroups } from './register_metric_anomaly_rule_type'; import { MlPluginSetup } from '../../../../../ml/server'; +import { AlertStates, MetricAnomalyParams } from '../../../../common/alerting/metrics'; +import { getIntervalInSeconds } from '../../../utils/get_interval_in_seconds'; +import { MappedAnomalyHit } from '../../infra_ml'; import { InfraBackendLibs } from '../../infra_types'; +import { stateToAlertMessage } from '../common/messages'; import { evaluateCondition } from './evaluate_condition'; +import { MetricAnomalyAllowedActionGroups } from './register_metric_anomaly_rule_type'; export const createMetricAnomalyExecutor = - (libs: InfraBackendLibs, ml?: MlPluginSetup) => + (_libs: InfraBackendLibs, ml?: MlPluginSetup) => async ({ services, params, diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/create_percentile_aggregation.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/create_percentile_aggregation.ts index 92219e733da5d9..35111c1a69b2f1 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/create_percentile_aggregation.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/create_percentile_aggregation.ts @@ -5,7 +5,8 @@ * 2.0. */ -import { Aggregators } from '../types'; +import { Aggregators } from '../../../../../common/alerting/metrics'; + export const createPercentileAggregation = ( type: Aggregators.P95 | Aggregators.P99, field: string diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/create_timerange.test.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/create_timerange.test.ts index 5640a1d9284360..bf365d7e89bcac 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/create_timerange.test.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/create_timerange.test.ts @@ -5,9 +5,9 @@ * 2.0. */ -import { createTimerange } from './create_timerange'; -import { Aggregators } from '../types'; import moment from 'moment'; +import { Aggregators } from '../../../../../common/alerting/metrics'; +import { createTimerange } from './create_timerange'; describe('createTimerange(interval, aggType, timeframe)', () => { describe('without timeframe', () => { diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/create_timerange.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/create_timerange.ts index cca63aca14d097..03c407e8afe377 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/create_timerange.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/create_timerange.ts @@ -6,7 +6,7 @@ */ import moment from 'moment'; -import { Aggregators } from '../types'; +import { Aggregators } from '../../../../../common/alerting/metrics'; export const createTimerange = ( interval: number, diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/evaluate_rule.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/evaluate_rule.ts index 47727314cc64f9..0906ad48713f10 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/evaluate_rule.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/evaluate_rule.ts @@ -5,23 +5,25 @@ * 2.0. */ -import moment from 'moment'; import { ElasticsearchClient } from 'kibana/server'; -import { mapValues, first, last, isNaN, isNumber, isObject, has } from 'lodash'; +import { first, has, isNaN, isNumber, isObject, last, mapValues } from 'lodash'; +import moment from 'moment'; import { + Aggregators, + Comparator, isTooManyBucketsPreviewException, + MetricExpressionParams, TOO_MANY_BUCKETS_PREVIEW_EXCEPTION, } from '../../../../../common/alerting/metrics'; -import { getIntervalInSeconds } from '../../../../utils/get_interval_in_seconds'; import { InfraSource } from '../../../../../common/source_configuration/source_configuration'; -import { InfraDatabaseSearchResponse } from '../../../adapters/framework/adapter_types'; import { createAfterKeyHandler } from '../../../../utils/create_afterkey_handler'; import { getAllCompositeData } from '../../../../utils/get_all_composite_data'; +import { getIntervalInSeconds } from '../../../../utils/get_interval_in_seconds'; +import { InfraDatabaseSearchResponse } from '../../../adapters/framework/adapter_types'; import { DOCUMENT_COUNT_I18N } from '../../common/messages'; import { UNGROUPED_FACTORY_KEY } from '../../common/utils'; -import { MetricExpressionParams, Comparator, Aggregators } from '../types'; -import { getElasticsearchMetricQuery } from './metric_query'; import { createTimerange } from './create_timerange'; +import { getElasticsearchMetricQuery } from './metric_query'; interface AggregationWithoutIntervals { aggregatedValue: { value: number; values?: Array<{ key: number; value: number }> }; diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.test.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.test.ts index 463365b6449d0f..4fbdf72a7429cf 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.test.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.test.ts @@ -5,9 +5,9 @@ * 2.0. */ -import { MetricExpressionParams } from '../types'; -import { getElasticsearchMetricQuery } from './metric_query'; import moment from 'moment'; +import { MetricExpressionParams } from '../../../../../common/alerting/metrics'; +import { getElasticsearchMetricQuery } from './metric_query'; describe("The Metric Threshold Alert's getElasticsearchMetricQuery", () => { const expressionParams = { diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.ts index 588b77250e6a64..56c9d5d14d0141 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query.ts @@ -5,11 +5,11 @@ * 2.0. */ +import { Aggregators, MetricExpressionParams } from '../../../../../common/alerting/metrics'; import { TIMESTAMP_FIELD } from '../../../../../common/constants'; import { networkTraffic } from '../../../../../common/inventory_models/shared/metrics/snapshot/network_traffic'; -import { MetricExpressionParams, Aggregators } from '../types'; -import { createPercentileAggregation } from './create_percentile_aggregation'; import { calculateDateHistogramOffset } from '../../../metrics/lib/calculate_date_histogram_offset'; +import { createPercentileAggregation } from './create_percentile_aggregation'; const COMPOSITE_RESULTS_PER_PAGE = 100; diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts index 5a75b18e47590c..b59ca5245db982 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.test.ts @@ -5,30 +5,30 @@ * 2.0. */ -import { createMetricThresholdExecutor, FIRED_ACTIONS } from './metric_threshold_executor'; -import * as mocks from './test_mocks'; +// eslint-disable-next-line @kbn/eslint/no-restricted-paths +import { elasticsearchClientMock } from 'src/core/server/elasticsearch/client/mocks'; +import { + AlertInstanceContext as AlertContext, + AlertInstanceState as AlertState, +} from '../../../../../alerting/server'; // import { RecoveredActionGroup } from '../../../../../alerting/common'; import { - alertsMock, - AlertServicesMock, AlertInstanceMock, + AlertServicesMock, + alertsMock, } from '../../../../../alerting/server/mocks'; import { LifecycleAlertServices } from '../../../../../rule_registry/server'; import { ruleRegistryMocks } from '../../../../../rule_registry/server/mocks'; import { createLifecycleRuleExecutorMock } from '../../../../../rule_registry/server/utils/create_lifecycle_rule_executor_mock'; -import { InfraSources } from '../../sources'; -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { elasticsearchClientMock } from 'src/core/server/elasticsearch/client/mocks'; -import { - AlertInstanceContext as AlertContext, - AlertInstanceState as AlertState, -} from '../../../../../alerting/server'; import { Aggregators, Comparator, CountMetricExpressionParams, NonCountMetricExpressionParams, -} from './types'; +} from '../../../../common/alerting/metrics'; +import { InfraSources } from '../../sources'; +import { createMetricThresholdExecutor, FIRED_ACTIONS } from './metric_threshold_executor'; +import * as mocks from './test_mocks'; interface AlertTestInstance { instance: AlertInstanceMock; diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts index 810055fc1771a6..371e75451c5792 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/metric_threshold_executor.ts @@ -5,33 +5,33 @@ * 2.0. */ -import { first, last, isEqual } from 'lodash'; import { i18n } from '@kbn/i18n'; -import moment from 'moment'; import { ALERT_REASON } from '@kbn/rule-data-utils'; +import { first, isEqual, last } from 'lodash'; +import moment from 'moment'; import { ActionGroupIdsOf, - RecoveredActionGroup, - AlertInstanceState as AlertState, AlertInstanceContext as AlertContext, + AlertInstanceState as AlertState, + RecoveredActionGroup, } from '../../../../../alerting/common'; import { - AlertTypeState as RuleTypeState, AlertInstance as Alert, + AlertTypeState as RuleTypeState, } from '../../../../../alerting/server'; +import { AlertStates, Comparator } from '../../../../common/alerting/metrics'; +import { createFormatter } from '../../../../common/formatters'; import { InfraBackendLibs } from '../../infra_types'; import { buildErrorAlertReason, buildFiredAlertReason, + buildInvalidQueryAlertReason, buildNoDataAlertReason, // buildRecoveredAlertReason, stateToAlertMessage, - buildInvalidQueryAlertReason, } from '../common/messages'; import { UNGROUPED_FACTORY_KEY } from '../common/utils'; -import { createFormatter } from '../../../../common/formatters'; -import { AlertStates, Comparator } from './types'; -import { evaluateRule, EvaluatedRuleParams } from './lib/evaluate_rule'; +import { EvaluatedRuleParams, evaluateRule } from './lib/evaluate_rule'; export type MetricThresholdRuleParams = Record; export type MetricThresholdRuleTypeState = RuleTypeState & { diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/register_metric_threshold_rule_type.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/register_metric_threshold_rule_type.ts index 0a67dbdc3190f4..4f1d4fd8cc26d0 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/register_metric_threshold_rule_type.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/register_metric_threshold_rule_type.ts @@ -9,24 +9,24 @@ import { schema } from '@kbn/config-schema'; import { i18n } from '@kbn/i18n'; import { ActionGroupIdsOf } from '../../../../../alerting/common'; import { AlertType, PluginSetupContract } from '../../../../../alerting/server'; +import { Comparator, METRIC_THRESHOLD_ALERT_TYPE_ID } from '../../../../common/alerting/metrics'; import { METRIC_EXPLORER_AGGREGATIONS } from '../../../../common/http_api'; -import { - createMetricThresholdExecutor, - FIRED_ACTIONS, - WARNING_ACTIONS, -} from './metric_threshold_executor'; -import { METRIC_THRESHOLD_ALERT_TYPE_ID, Comparator } from './types'; import { InfraBackendLibs } from '../../infra_types'; -import { oneOfLiterals, validateIsStringElasticsearchJSONFilter } from '../common/utils'; import { - groupActionVariableDescription, alertStateActionVariableDescription, + groupActionVariableDescription, + metricActionVariableDescription, reasonActionVariableDescription, + thresholdActionVariableDescription, timestampActionVariableDescription, valueActionVariableDescription, - metricActionVariableDescription, - thresholdActionVariableDescription, } from '../common/messages'; +import { oneOfLiterals, validateIsStringElasticsearchJSONFilter } from '../common/utils'; +import { + createMetricThresholdExecutor, + FIRED_ACTIONS, + WARNING_ACTIONS, +} from './metric_threshold_executor'; type MetricThresholdAllowedActionGroups = ActionGroupIdsOf< typeof FIRED_ACTIONS | typeof WARNING_ACTIONS diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/types.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/types.ts deleted file mode 100644 index 101be1f77b9d0a..00000000000000 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/types.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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 { Unit } from '@elastic/datemath'; -import { Comparator, AlertStates } from '../common/types'; - -export { Comparator, AlertStates }; -export const METRIC_THRESHOLD_ALERT_TYPE_ID = 'metrics.alert.threshold'; - -export enum Aggregators { - COUNT = 'count', - AVERAGE = 'avg', - SUM = 'sum', - MIN = 'min', - MAX = 'max', - RATE = 'rate', - CARDINALITY = 'cardinality', - P95 = 'p95', - P99 = 'p99', -} - -interface BaseMetricExpressionParams { - timeSize: number; - timeUnit: Unit; - sourceId?: string; - threshold: number[]; - comparator: Comparator; - warningComparator?: Comparator; - warningThreshold?: number[]; -} - -export interface NonCountMetricExpressionParams extends BaseMetricExpressionParams { - aggType: Exclude; - metric: string; -} - -export interface CountMetricExpressionParams extends BaseMetricExpressionParams { - aggType: Aggregators.COUNT; - metric: never; -} - -export type MetricExpressionParams = NonCountMetricExpressionParams | CountMetricExpressionParams; diff --git a/x-pack/test/api_integration/apis/metrics_ui/inventory_threshold_alert.ts b/x-pack/test/api_integration/apis/metrics_ui/inventory_threshold_alert.ts index a6e0ce1bc628f7..18fa4507eaf4f0 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/inventory_threshold_alert.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/inventory_threshold_alert.ts @@ -10,12 +10,12 @@ import { convertToKibanaClient } from '@kbn/test'; import { Comparator, InventoryMetricConditions, -} from '../../../../plugins/infra/server/lib/alerting/inventory_metric_threshold/types'; +} from '../../../../plugins/infra/common/alerting/metrics'; +import { InventoryItemType } from '../../../../plugins/infra/common/inventory_models/types'; +import { evaluateCondition } from '../../../../plugins/infra/server/lib/alerting/inventory_metric_threshold/evaluate_condition'; import { InfraSource } from '../../../../plugins/infra/server/lib/sources'; import { FtrProviderContext } from '../../ftr_provider_context'; import { DATES } from './constants'; -import { evaluateCondition } from '../../../../plugins/infra/server/lib/alerting/inventory_metric_threshold/evaluate_condition'; -import { InventoryItemType } from '../../../../plugins/infra/common/inventory_models/types'; export default function ({ getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); diff --git a/x-pack/test/api_integration/apis/metrics_ui/metric_threshold_alert.ts b/x-pack/test/api_integration/apis/metrics_ui/metric_threshold_alert.ts index ecefef2fe930c4..337d31a0a51b04 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/metric_threshold_alert.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/metric_threshold_alert.ts @@ -7,18 +7,18 @@ import expect from '@kbn/expect'; import { convertToKibanaClient } from '@kbn/test'; -import { InfraSource } from '../../../../plugins/infra/common/source_configuration/source_configuration'; -import { FtrProviderContext } from '../../ftr_provider_context'; -import { - evaluateRule, - EvaluatedRuleParams, -} from '../../../../plugins/infra/server/lib/alerting/metric_threshold/lib/evaluate_rule'; import { Aggregators, + Comparator, CountMetricExpressionParams, NonCountMetricExpressionParams, -} from '../../../../plugins/infra/server/lib/alerting/metric_threshold/types'; -import { Comparator } from '../../../../plugins/infra/server/lib/alerting/common/types'; +} from '../../../../plugins/infra/common/alerting/metrics'; +import { InfraSource } from '../../../../plugins/infra/common/source_configuration/source_configuration'; +import { + EvaluatedRuleParams, + evaluateRule, +} from '../../../../plugins/infra/server/lib/alerting/metric_threshold/lib/evaluate_rule'; +import { FtrProviderContext } from '../../ftr_provider_context'; import { DATES } from './constants'; const { gauge, rate } = DATES['alert-test-data']; diff --git a/x-pack/test/api_integration/apis/metrics_ui/metrics_alerting.ts b/x-pack/test/api_integration/apis/metrics_ui/metrics_alerting.ts index eb8888a613dc3c..d441c59b24a20f 100644 --- a/x-pack/test/api_integration/apis/metrics_ui/metrics_alerting.ts +++ b/x-pack/test/api_integration/apis/metrics_ui/metrics_alerting.ts @@ -7,10 +7,10 @@ import expect from '@kbn/expect'; import moment from 'moment'; +import { MetricExpressionParams } from '../../../../plugins/infra/common/alerting/metrics'; import { getElasticsearchMetricQuery } from '../../../../plugins/infra/server/lib/alerting/metric_threshold/lib/metric_query'; -import { MetricExpressionParams } from '../../../../plugins/infra/server/lib/alerting/metric_threshold/types'; - import { FtrProviderContext } from '../../ftr_provider_context'; + export default function ({ getService }: FtrProviderContext) { const client = getService('es'); const index = 'test-index';