mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 629c602a67
)
# 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
This commit is contained in:
parent
b1e6fd3144
commit
6526772365
42 changed files with 329 additions and 441 deletions
|
@ -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<Aggregators, Aggregators.COUNT>;
|
||||
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;
|
||||
|
|
|
@ -4,15 +4,11 @@
|
|||
* 2.0; you may not use this file except in compliance with the Elastic License
|
||||
* 2.0.
|
||||
*/
|
||||
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 { Color } from '../../../../common/color_palette';
|
||||
import { shallow } from 'enzyme';
|
||||
import React from 'react';
|
||||
import { Comparator } from '../../../../common/alerting/metrics';
|
||||
import { Color } from '../../../../common/color_palette';
|
||||
import { ThresholdAnnotations } from './threshold_annotations';
|
||||
|
||||
jest.mock('@elastic/charts', () => {
|
||||
const original = jest.requireActual('@elastic/charts');
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -5,17 +5,14 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { mountWithIntl, shallowWithIntl, nextTick } from '@kbn/test/jest';
|
||||
import { mountWithIntl, nextTick, shallowWithIntl } 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';
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import { InventoryMetricConditions } from '../../../../server/lib/alerting/inventory_metric_threshold/types';
|
||||
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';
|
||||
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: () => ({
|
||||
|
|
|
@ -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 { 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 { containerMetricTypes } from '../../../../common/inventory_models/container/toolbar_items';
|
||||
import { podMetricTypes } from '../../../../common/inventory_models/pod/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 { rdsMetricTypes } from '../../../../common/inventory_models/aws_rds/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 {
|
||||
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 { 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 { ExpressionChart } from './expression_chart';
|
||||
import { MetricExpression } from './metric';
|
||||
import { NodeTypeExpression } from './node_type';
|
||||
import { InfraWaffleMapOptions } from '../../../lib/lib';
|
||||
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';
|
||||
const FILTER_TYPING_DEBOUNCE_MS = 500;
|
||||
export const QUERY_INVALID = Symbol('QUERY_INVALID');
|
||||
|
||||
export interface AlertContextMeta {
|
||||
options?: Partial<InfraWaffleMapOptions>;
|
||||
|
@ -85,7 +79,7 @@ type Props = Omit<
|
|||
{
|
||||
criteria: Criteria;
|
||||
nodeType: InventoryItemType;
|
||||
filterQuery?: string | symbol;
|
||||
filterQuery?: FilterQuery;
|
||||
filterQueryText?: string;
|
||||
sourceId: string;
|
||||
alertOnNoData?: boolean;
|
||||
|
|
|
@ -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 { MetricsExplorerAggregation, MetricsExplorerRow } from '../../../../common/http_api';
|
||||
import { InventoryItemType, SnapshotMetricType } from '../../../../common/inventory_models/types';
|
||||
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';
|
||||
import { useSnapshot } from '../../../pages/metrics/inventory_view/hooks/use_snaphot';
|
||||
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 { 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 { createInventoryMetricFormatter } from '../../../pages/metrics/inventory_view/lib/create_inventory_metric_formatter';
|
||||
|
||||
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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -5,21 +5,20 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { isNumber, isFinite } from 'lodash';
|
||||
import {
|
||||
EuiPopoverTitle,
|
||||
EuiFlexItem,
|
||||
EuiFlexGroup,
|
||||
EuiPopover,
|
||||
EuiSelect,
|
||||
EuiFieldNumber,
|
||||
EuiExpression,
|
||||
EuiFieldNumber,
|
||||
EuiFlexGroup,
|
||||
EuiFlexItem,
|
||||
EuiFormRow,
|
||||
EuiPopover,
|
||||
EuiPopoverTitle,
|
||||
EuiSelect,
|
||||
} 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,
|
||||
|
|
|
@ -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'];
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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: () => ({
|
||||
|
|
|
@ -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<AlertTypeParams & AlertParams, AlertContextMeta>,
|
||||
|
|
|
@ -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', () => ({
|
||||
|
|
|
@ -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: () => ({
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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[];
|
||||
|
|
|
@ -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<MetricsExplorerOptions>;
|
||||
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
);
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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,
|
||||
}
|
|
@ -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[];
|
||||
|
|
|
@ -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 { SnapshotMetricType } from '../../../../common/inventory_models/types';
|
||||
import { InfraBackendLibs } from '../../infra_types';
|
||||
import { METRIC_FORMATTERS } from '../../../../common/formatters/snapshot_metric_formats';
|
||||
import { AlertStates, InventoryMetricThresholdParams } from '../../../../common/alerting/metrics';
|
||||
import { createFormatter } from '../../../../common/formatters';
|
||||
import { InventoryMetricThresholdParams } from '../../../../common/alerting/metrics';
|
||||
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 {
|
||||
buildErrorAlertReason,
|
||||
buildFiredAlertReason,
|
||||
buildInvalidQueryAlertReason,
|
||||
buildNoDataAlertReason,
|
||||
// buildRecoveredAlertReason,
|
||||
stateToAlertMessage,
|
||||
buildInvalidQueryAlertReason,
|
||||
} from '../common/messages';
|
||||
import { evaluateCondition } from './evaluate_condition';
|
||||
|
||||
|
|
|
@ -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 {
|
||||
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 {
|
||||
alertStateActionVariableDescription,
|
||||
groupActionVariableDescription,
|
||||
metricActionVariableDescription,
|
||||
reasonActionVariableDescription,
|
||||
thresholdActionVariableDescription,
|
||||
timestampActionVariableDescription,
|
||||
valueActionVariableDescription,
|
||||
} from '../common/messages';
|
||||
import { oneOfLiterals, validateIsStringElasticsearchJSONFilter } from '../common/utils';
|
||||
import {
|
||||
createInventoryMetricThresholdExecutor,
|
||||
FIRED_ACTIONS,
|
||||
FIRED_ACTIONS_ID,
|
||||
WARNING_ACTIONS,
|
||||
} from './inventory_metric_threshold_executor';
|
||||
import { METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID, Comparator } from './types';
|
||||
import { InfraBackendLibs } from '../../infra_types';
|
||||
import { oneOfLiterals, validateIsStringElasticsearchJSONFilter } from '../common/utils';
|
||||
import {
|
||||
groupActionVariableDescription,
|
||||
alertStateActionVariableDescription,
|
||||
reasonActionVariableDescription,
|
||||
timestampActionVariableDescription,
|
||||
valueActionVariableDescription,
|
||||
metricActionVariableDescription,
|
||||
thresholdActionVariableDescription,
|
||||
} from '../common/messages';
|
||||
import {
|
||||
SnapshotMetricTypeKeys,
|
||||
SnapshotMetricType,
|
||||
InventoryItemType,
|
||||
} from '../../../../common/inventory_models/types';
|
||||
import {
|
||||
SNAPSHOT_CUSTOM_AGGREGATIONS,
|
||||
SnapshotCustomAggregation,
|
||||
} from '../../../../common/http_api/snapshot_api';
|
||||
|
||||
const condition = schema.object({
|
||||
threshold: schema.arrayOf(schema.number()),
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import moment from 'moment';
|
||||
import { Aggregators } from '../types';
|
||||
import { Aggregators } from '../../../../../common/alerting/metrics';
|
||||
|
||||
export const createTimerange = (
|
||||
interval: number,
|
||||
|
|
|
@ -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 }> };
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -5,30 +5,30 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { createMetricThresholdExecutor, FIRED_ACTIONS } from './metric_threshold_executor';
|
||||
import * as mocks from './test_mocks';
|
||||
// import { RecoveredActionGroup } from '../../../../../alerting/common';
|
||||
import {
|
||||
alertsMock,
|
||||
AlertServicesMock,
|
||||
AlertInstanceMock,
|
||||
} 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 { RecoveredActionGroup } from '../../../../../alerting/common';
|
||||
import {
|
||||
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 {
|
||||
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;
|
||||
|
|
|
@ -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<string, any>;
|
||||
export type MetricThresholdRuleTypeState = RuleTypeState & {
|
||||
|
|
|
@ -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 { InfraBackendLibs } from '../../infra_types';
|
||||
import {
|
||||
alertStateActionVariableDescription,
|
||||
groupActionVariableDescription,
|
||||
metricActionVariableDescription,
|
||||
reasonActionVariableDescription,
|
||||
thresholdActionVariableDescription,
|
||||
timestampActionVariableDescription,
|
||||
valueActionVariableDescription,
|
||||
} from '../common/messages';
|
||||
import { oneOfLiterals, validateIsStringElasticsearchJSONFilter } from '../common/utils';
|
||||
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,
|
||||
reasonActionVariableDescription,
|
||||
timestampActionVariableDescription,
|
||||
valueActionVariableDescription,
|
||||
metricActionVariableDescription,
|
||||
thresholdActionVariableDescription,
|
||||
} from '../common/messages';
|
||||
|
||||
type MetricThresholdAllowedActionGroups = ActionGroupIdsOf<
|
||||
typeof FIRED_ACTIONS | typeof WARNING_ACTIONS
|
||||
|
|
|
@ -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<Aggregators, Aggregators.COUNT>;
|
||||
metric: string;
|
||||
}
|
||||
|
||||
export interface CountMetricExpressionParams extends BaseMetricExpressionParams {
|
||||
aggType: Aggregators.COUNT;
|
||||
metric: never;
|
||||
}
|
||||
|
||||
export type MetricExpressionParams = NonCountMetricExpressionParams | CountMetricExpressionParams;
|
|
@ -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');
|
||||
|
|
|
@ -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'];
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue