Skip to content

Commit

Permalink
Add support for between comparator
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed Feb 26, 2020
1 parent 54441b5 commit 7990079
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,14 @@ async function getMetric(
}

const comparatorMap = {
[Comparator.GT]: (a: number, b: number) => a > b,
[Comparator.LT]: (a: number, b: number) => a < b,
[Comparator.GT_OR_EQ]: (a: number, b: number) => a >= b,
[Comparator.LT_OR_EQ]: (a: number, b: number) => a <= b,
[Comparator.BETWEEN]: (value: number, [a, b]: number[]) =>
value >= Math.min(a, b) && value <= Math.max(a, b),
// `threshold` is always an array of numbers in case the BETWEEN comparator is
// used; all other compartors will just destructure the first value in the array
[Comparator.GT]: (a: number, [b]: number[]) => a > b,
[Comparator.LT]: (a: number, [b]: number[]) => a < b,
[Comparator.GT_OR_EQ]: (a: number, [b]: number[]) => a >= b,
[Comparator.LT_OR_EQ]: (a: number, [b]: number[]) => a <= b,
};

export async function registerMetricThresholdAlertType(alertingPlugin: PluginSetupContract) {
Expand All @@ -91,7 +95,7 @@ export async function registerMetricThresholdAlertType(alertingPlugin: PluginSet
name: 'Metric Alert - Threshold',
validate: {
params: schema.object({
threshold: schema.number(),
threshold: schema.arrayOf(schema.number()),
comparator: schema.string(),
aggType: schema.string(),
metric: schema.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum Comparator {
LT = '<',
GT_OR_EQ = '>=',
LT_OR_EQ = '<=',
BETWEEN = 'between',
}

export enum AlertStates {
Expand All @@ -28,6 +29,6 @@ export interface MetricThresholdAlertTypeParams {
timeSize: number;
timeUnit: TimeUnit;
indexPattern: string;
threshold: number;
threshold: number[];
comparator: Comparator;
}

0 comments on commit 7990079

Please sign in to comment.