-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
adding support for >=, <=, and between for threshold alerts #35614
Changes from 4 commits
8814483
191a79d
34d61bc
33a03d5
a5da001
cfe3536
36aba49
854b1f8
8c7f443
f5300e3
774f6c2
227d762
e4e7aae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
import { COMPARATORS } from '../../../common/constants'; | ||
|
||
export interface Comparator { | ||
text: string; | ||
value: string; | ||
requiredValues: number; | ||
} | ||
export const comparators: { [key: string]: Comparator } = { | ||
[COMPARATORS.GREATER_THAN]: { | ||
text: i18n.translate('xpack.watcher.thresholdWatchExpression.comparators.isAboveLabel', { | ||
defaultMessage: 'Is above', | ||
}), | ||
value: COMPARATORS.GREATER_THAN, | ||
requiredValues: 1, | ||
}, | ||
[COMPARATORS.GREATER_THAN_OR_EQUALS]: { | ||
text: i18n.translate( | ||
'xpack.watcher.thresholdWatchExpression.comparators.isAboveOrEqualsLabel', | ||
{ | ||
defaultMessage: 'Is above or equals', | ||
} | ||
), | ||
value: COMPARATORS.GREATER_THAN_OR_EQUALS, | ||
requiredValues: 1, | ||
}, | ||
[COMPARATORS.LESS_THAN]: { | ||
text: i18n.translate('xpack.watcher.thresholdWatchExpression.comparators.isBelowLabel', { | ||
defaultMessage: 'Is below', | ||
}), | ||
value: COMPARATORS.LESS_THAN, | ||
requiredValues: 1, | ||
}, | ||
[COMPARATORS.LESS_THAN_OR_EQUALS]: { | ||
text: i18n.translate( | ||
'xpack.watcher.thresholdWatchExpression.comparators.isBelowOrEqualsLabel', | ||
{ | ||
defaultMessage: 'Is below or equals', | ||
} | ||
), | ||
value: COMPARATORS.LESS_THAN_OR_EQUALS, | ||
requiredValues: 1, | ||
}, | ||
[COMPARATORS.BETWEEN]: { | ||
text: i18n.translate( | ||
'xpack.watcher.thresholdWatchExpression.comparators.isBelowOrEqualsLabel', | ||
{ | ||
defaultMessage: 'Is between', | ||
} | ||
), | ||
value: COMPARATORS.BETWEEN, | ||
requiredValues: 2, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import { getTimeUnitsLabel } from 'plugins/watcher/lib/get_time_units_label'; | |
import { i18n } from '@kbn/i18n'; | ||
import { aggTypes } from './agg_types'; | ||
import { groupByTypes } from './group_by_types'; | ||
import { comparators } from './comparators'; | ||
const DEFAULT_VALUES = { | ||
AGG_TYPE: 'count', | ||
TERM_SIZE: 5, | ||
|
@@ -19,7 +20,7 @@ const DEFAULT_VALUES = { | |
TIME_WINDOW_UNIT: 'm', | ||
TRIGGER_INTERVAL_SIZE: 1, | ||
TRIGGER_INTERVAL_UNIT: 'm', | ||
THRESHOLD: 1000, | ||
THRESHOLD: [1000, 5000], | ||
GROUP_BY: 'all', | ||
}; | ||
|
||
|
@@ -102,7 +103,6 @@ export class ThresholdWatch extends BaseWatch { | |
aggField: [], | ||
termSize: [], | ||
termField: [], | ||
threshold: [], | ||
timeWindowSize: [], | ||
}; | ||
validationResult.errors = errors; | ||
|
@@ -176,15 +176,29 @@ export class ThresholdWatch extends BaseWatch { | |
); | ||
} | ||
} | ||
if (!this.threshold) { | ||
errors.threshold.push( | ||
i18n.translate( | ||
|
||
Array.from(Array(comparators[this.thresholdComparator].requiredValues)).forEach((value, i) => { | ||
const key = `threshold${i}`; | ||
errors[key] = []; | ||
if (!this.threshold[i]) { | ||
errors[key].push(i18n.translate( | ||
'xpack.watcher.thresholdWatchExpression.thresholdLevel.valueIsRequiredValidationMessage', | ||
{ | ||
defaultMessage: 'A value is required.', | ||
} | ||
) | ||
); | ||
)); | ||
} | ||
}); | ||
if (this.thresholdComparator === 'between' && this.threshold[0] && this.threshold[1] && !(this.threshold[1] > this.threshold[0])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you use the constant for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup fixed |
||
errors.threshold1.push(i18n.translate( | ||
'xpack.watcher.thresholdWatchExpression.thresholdLevel.secondValueMustBeGreaterMessage', | ||
{ | ||
defaultMessage: 'This value must be greater than {lowerBound}.', | ||
values: { | ||
lowerBound: this.threshold[0] | ||
} | ||
} | ||
)); | ||
} | ||
if (!this.timeWindowSize) { | ||
errors.timeWindowSize.push( | ||
|
@@ -212,7 +226,7 @@ export class ThresholdWatch extends BaseWatch { | |
thresholdComparator: this.thresholdComparator, | ||
timeWindowSize: this.timeWindowSize, | ||
timeWindowUnit: this.timeWindowUnit, | ||
threshold: this.threshold, | ||
threshold: comparators[this.thresholdComparator].requiredValues > 1 ? this.threshold : this.threshold[0], | ||
}); | ||
|
||
return result; | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dupe key - probably should be
isInBetweenLabel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup fixed