Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Metrics UI] Add preview feature for metric threshold alerts #67684

Merged
merged 29 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
046a043
Add alert preview backend for threshold
Zacqary May 27, 2020
afa14e7
Merge remote-tracking branch 'upstream/master' into 65830-alert-preview
Zacqary May 27, 2020
fb59bce
Merge remote-tracking branch 'upstream/master' into 65830-alert-preview
Zacqary May 28, 2020
d06ed28
Get frontend and backend working
Zacqary May 28, 2020
5a35520
i18n fix
Zacqary May 28, 2020
a09e7f5
Add hook for inventory preview
Zacqary May 29, 2020
59e9bcd
Merge remote-tracking branch 'upstream/master' into 65830-alert-preview
Zacqary Jun 1, 2020
83516a2
Merge branch 'master' into 65830-alert-preview
elasticmachine Jun 1, 2020
8dd5dd9
Remove breaking Boom import
Zacqary Jun 1, 2020
48861b1
Merge branch '65830-alert-preview' of github.com:Zacqary/kibana into …
Zacqary Jun 1, 2020
31c2708
Merge remote-tracking branch 'upstream/master' into 65830-alert-preview
Zacqary Jun 4, 2020
e7406ef
Fix module import
Zacqary Jun 4, 2020
2e908fc
Move types to common folder, rename metric query file
Zacqary Jun 5, 2020
73400ea
Add too many buckets error r handler
Zacqary Jun 5, 2020
0e4732f
Switch to evaluating based on the alert interval
Zacqary Jun 5, 2020
925d01d
Add interval prompt to not enough data message
Zacqary Jun 5, 2020
7e3a20a
Merge remote-tracking branch 'upstream/master' into 65830-alert-preview
Zacqary Jun 8, 2020
a04ddde
Fix type check
Zacqary Jun 8, 2020
6896892
Add recursive handling of too many buckets
Zacqary Jun 8, 2020
b804e5c
Update comment
Zacqary Jun 8, 2020
db10b8d
Avoid re-fetching groups every iteration
Zacqary Jun 8, 2020
2993450
Merge remote-tracking branch 'upstream/master' into 65830-alert-preview
Zacqary Jun 8, 2020
2bbe889
Fix i18n
Zacqary Jun 9, 2020
84385f1
Merge remote-tracking branch 'upstream/master' into 65830-alert-preview
Zacqary Jun 9, 2020
04b5eee
Merge remote-tracking branch 'upstream/master' into 65830-alert-preview
Zacqary Jun 10, 2020
d3b8bab
Merge branch 'master' into 65830-alert-preview
elasticmachine Jun 11, 2020
a22e6b8
Clean up interpolation and apply useCallbacks
Zacqary Jun 15, 2020
1de9ca6
Merge remote-tracking branch 'upstream/master' into 65830-alert-preview
Zacqary Jun 15, 2020
8dd4219
Merge branch '65830-alert-preview' of github.com:Zacqary/kibana into …
Zacqary Jun 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions x-pack/plugins/infra/common/alerting/metrics/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export * from './types';
export const INFRA_ALERT_PREVIEW_PATH = '/api/infra/alerting/preview';

export const TOO_MANY_BUCKETS_PREVIEW_EXCEPTION = 'TOO_MANY_BUCKETS_PREVIEW_EXCEPTION';
export interface TooManyBucketsPreviewExceptionMetadata {
TOO_MANY_BUCKETS_PREVIEW_EXCEPTION: any;
maxBuckets: number;
}
export const isTooManyBucketsPreviewException = (
value: any
): value is TooManyBucketsPreviewExceptionMetadata =>
Boolean(value && value.TOO_MANY_BUCKETS_PREVIEW_EXCEPTION);
82 changes: 82 additions & 0 deletions x-pack/plugins/infra/common/alerting/metrics/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import * as rt from 'io-ts';

// 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 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',
}

// Alert Preview API
const baseAlertRequestParamsRT = rt.intersection([
rt.partial({
filterQuery: rt.union([rt.string, rt.undefined]),
sourceId: rt.string,
}),
rt.type({
lookback: rt.union([rt.literal('h'), rt.literal('d'), rt.literal('w'), rt.literal('M')]),
criteria: rt.array(rt.any),
alertInterval: rt.string,
}),
]);

const metricThresholdAlertPreviewRequestParamsRT = rt.intersection([
baseAlertRequestParamsRT,
rt.partial({
groupBy: rt.union([rt.string, rt.array(rt.string), rt.undefined]),
}),
rt.type({
alertType: rt.literal(METRIC_THRESHOLD_ALERT_TYPE_ID),
}),
]);
export type MetricThresholdAlertPreviewRequestParams = rt.TypeOf<
typeof metricThresholdAlertPreviewRequestParamsRT
>;

const inventoryAlertPreviewRequestParamsRT = rt.intersection([
baseAlertRequestParamsRT,
rt.type({
nodeType: rt.string,
alertType: rt.literal(METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID),
}),
]);

export const alertPreviewRequestParamsRT = rt.union([
metricThresholdAlertPreviewRequestParamsRT,
inventoryAlertPreviewRequestParamsRT,
]);

export const alertPreviewSuccessResponsePayloadRT = rt.type({
numberOfGroups: rt.number,
resultTotals: rt.type({
fired: rt.number,
noData: rt.number,
error: rt.number,
tooManyBuckets: rt.number,
}),
});
Loading