[Metrics UI] Add track_total_hits to Metric Threshold query to support alerts with over 10K documents (#115465)

* [Metrics UI] Add track_total_hits to Metric Threshold query

* Adding tests

* Making the esArchive smaller
This commit is contained in:
Chris Cowan 2021-10-20 10:19:44 -06:00 committed by GitHub
parent b12e21d9aa
commit 31fa0cb13b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 21819 additions and 3 deletions

View file

@ -120,6 +120,7 @@ export const getElasticsearchMetricQuery = (
const parsedFilterQuery = getParsedFilterQuery(filterQuery);
return {
track_total_hits: true,
query: {
bool: {
filter: [

View file

@ -39,4 +39,8 @@ export const DATES = {
max: 1609545900000, // '2021-01-02T00:05:00Z'
},
},
ten_thousand_plus: {
min: 1634604480001, // 2021-10-19T00:48:00.001Z
max: 1634604839997, // 2021-10-19T00:53:59.997Z
},
};

View file

@ -81,10 +81,95 @@ export default function ({ getService }: FtrProviderContext) {
};
describe('Metric Threshold Alerts Executor', () => {
before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/alerts_test_data'));
after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/alerts_test_data'));
describe('with 10K plus docs', () => {
before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/ten_thousand_plus'));
after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/ten_thousand_plus'));
describe('without group by', () => {
it('should alert on document count', async () => {
const params = {
...baseParams,
criteria: [
{
timeSize: 5,
timeUnit: 'm',
threshold: [10000],
comparator: Comparator.LT_OR_EQ,
aggType: Aggregators.COUNT,
} as CountMetricExpressionParams,
],
};
const config = {
...configuration,
metricAlias: 'filebeat-*',
};
const timeFrame = { end: DATES.ten_thousand_plus.max };
const results = await evaluateAlert(esClient, params, config, [], timeFrame);
expect(results).to.eql([
{
'*': {
timeSize: 5,
timeUnit: 'm',
threshold: [10000],
comparator: '<=',
aggType: 'count',
metric: 'Document count',
currentValue: 20895,
timestamp: '2021-10-19T00:48:59.997Z',
shouldFire: [false],
shouldWarn: [false],
isNoData: [false],
isError: false,
},
},
]);
});
});
describe('with group by', () => {
it('should alert on document count', async () => {
const params = {
...baseParams,
groupBy: ['event.category'],
criteria: [
{
timeSize: 5,
timeUnit: 'm',
threshold: [10000],
comparator: Comparator.LT_OR_EQ,
aggType: Aggregators.COUNT,
} as CountMetricExpressionParams,
],
};
const config = {
...configuration,
metricAlias: 'filebeat-*',
};
const timeFrame = { end: DATES.ten_thousand_plus.max };
const results = await evaluateAlert(esClient, params, config, [], timeFrame);
expect(results).to.eql([
{
web: {
timeSize: 5,
timeUnit: 'm',
threshold: [10000],
comparator: '<=',
aggType: 'count',
metric: 'Document count',
currentValue: 20895,
timestamp: '2021-10-19T00:48:59.997Z',
shouldFire: [false],
shouldWarn: [false],
isNoData: [false],
isError: false,
},
},
]);
});
});
});
describe('with gauge data', () => {
before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/alerts_test_data'));
after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/alerts_test_data'));
describe('without groupBy', () => {
it('should alert on document count', async () => {
const params = {
@ -285,6 +370,8 @@ export default function ({ getService }: FtrProviderContext) {
});
describe('with rate data', () => {
before(() => esArchiver.load('x-pack/test/functional/es_archives/infra/alerts_test_data'));
after(() => esArchiver.unload('x-pack/test/functional/es_archives/infra/alerts_test_data'));
describe('without groupBy', () => {
it('should alert on rate', async () => {
const params = {

File diff suppressed because it is too large Load diff