Skip to content

Commit

Permalink
[7.9] [Metrics UI] Fix evaluating rate-aggregated alerts when there's…
Browse files Browse the repository at this point in the history
… no normalized value (elastic#73545) (elastic#73884)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
Zacqary and elasticmachine authored Jul 31, 2020
1 parent 6ca87f5 commit 5386c04
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,13 @@ export const evaluateAlert = (
currentValue: Array.isArray(points) ? last(points)?.value : NaN,
timestamp: Array.isArray(points) ? last(points)?.key : NaN,
shouldFire: Array.isArray(points)
? points.map((point) => comparisonFunction(point.value, threshold))
? points.map(
(point) =>
typeof point.value === 'number' && comparisonFunction(point.value, threshold)
)
: [false],
isNoData: points === null,
isError: isNaN(points),
isNoData: (Array.isArray(points) ? last(points)?.value : points) === null,
isError: isNaN(Array.isArray(points) ? last(points)?.value : points),
};
});
})
Expand Down Expand Up @@ -172,7 +175,7 @@ const getValuesFromAggregations = (
}
return buckets.map((bucket) => ({
key: bucket.key_as_string,
value: bucket.aggregatedValue.value,
value: bucket.aggregatedValue?.value ?? null,
}));
} catch (e) {
return NaN; // Error state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,31 @@ describe('The metric threshold alert type', () => {
});
});

describe("querying a rate-aggregated metric that hasn't reported data", () => {
const instanceID = '*';
const execute = () =>
executor({
services,
params: {
criteria: [
{
...baseCriterion,
comparator: Comparator.GT,
threshold: 1,
metric: 'test.metric.3',
aggType: 'rate',
},
],
alertOnNoData: true,
},
});
test('sends a No Data alert', async () => {
await execute();
expect(mostRecentAction(instanceID).id).toBe(FIRED_ACTIONS.id);
expect(getState(instanceID).alertState).toBe(AlertStates.NO_DATA);
});
});

// describe('querying a metric that later recovers', () => {
// const instanceID = '*';
// const execute = (threshold: number[]) =>
Expand Down Expand Up @@ -401,7 +426,9 @@ services.callCluster.mockImplementation(async (_: string, { body, index }: any)
if (metric === 'test.metric.2') {
return mocks.alternateMetricResponse;
} else if (metric === 'test.metric.3') {
return mocks.emptyMetricResponse;
return body.aggs.aggregatedIntervals.aggregations.aggregatedValue_max
? mocks.emptyRateResponse
: mocks.emptyMetricResponse;
}
return mocks.basicMetricResponse;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ export const emptyMetricResponse = {
},
};

export const emptyRateResponse = {
aggregations: {
aggregatedIntervals: {
buckets: [
{
doc_count: 2,
aggregatedValue_max: { value: null },
},
],
},
},
};

export const basicCompositeResponse = {
aggregations: {
groupings: {
Expand Down

0 comments on commit 5386c04

Please sign in to comment.