Skip to content

Commit 248904e

Browse files
authored
[ML] API integration tests - initial tests for bucket span estimator (#52636)
This PR adds basic API integration tests for the bucket span estimator.
1 parent aa31b53 commit 248904e

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

x-pack/test/api_integration/apis/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ export default function ({ loadTestFile }) {
2828
loadTestFile(require.resolve('./short_urls'));
2929
loadTestFile(require.resolve('./lens'));
3030
loadTestFile(require.resolve('./endpoint'));
31+
loadTestFile(require.resolve('./ml'));
3132
});
3233
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import expect from '@kbn/expect';
8+
9+
import { FtrProviderContext } from '../../ftr_provider_context';
10+
11+
const COMMON_HEADERS = {
12+
'kbn-xsrf': 'some-xsrf-token',
13+
};
14+
15+
const testDataList = [
16+
{
17+
testTitleSuffix: 'with 1 field, 1 agg, no split',
18+
requestBody: {
19+
aggTypes: ['avg'],
20+
duration: { start: 1560297859000, end: 1562975136000 },
21+
fields: ['taxless_total_price'],
22+
index: 'ecommerce',
23+
query: { bool: { must: [{ match_all: {} }] } },
24+
timeField: 'order_date',
25+
},
26+
expected: {
27+
responseCode: 200,
28+
responseBody: { name: '15m', ms: 900000 },
29+
},
30+
},
31+
{
32+
testTitleSuffix: 'with 2 fields, 2 aggs, no split',
33+
requestBody: {
34+
aggTypes: ['avg', 'sum'],
35+
duration: { start: 1560297859000, end: 1562975136000 },
36+
fields: ['products.base_price', 'products.base_unit_price'],
37+
index: 'ecommerce',
38+
query: { bool: { must: [{ match_all: {} }] } },
39+
timeField: 'order_date',
40+
},
41+
expected: {
42+
responseCode: 200,
43+
responseBody: { name: '30m', ms: 1800000 },
44+
},
45+
},
46+
{
47+
testTitleSuffix: 'with 1 field, 1 agg, 1 split with cardinality 46',
48+
requestBody: {
49+
aggTypes: ['avg'],
50+
duration: { start: 1560297859000, end: 1562975136000 },
51+
fields: ['taxless_total_price'],
52+
index: 'ecommerce',
53+
query: { bool: { must: [{ match_all: {} }] } },
54+
splitField: 'customer_first_name.keyword',
55+
timeField: 'order_date',
56+
},
57+
expected: {
58+
responseCode: 200,
59+
responseBody: { name: '3h', ms: 10800000 },
60+
},
61+
},
62+
];
63+
64+
// eslint-disable-next-line import/no-default-export
65+
export default ({ getService }: FtrProviderContext) => {
66+
const esArchiver = getService('esArchiver');
67+
const supertest = getService('supertest');
68+
69+
describe('bucket span estimator', () => {
70+
before(async () => {
71+
await esArchiver.load('ml/ecommerce');
72+
});
73+
74+
after(async () => {
75+
await esArchiver.unload('ml/ecommerce');
76+
});
77+
78+
for (const testData of testDataList) {
79+
it(`estimates the bucket span ${testData.testTitleSuffix}`, async () => {
80+
const { body } = await supertest
81+
.post('/api/ml/validate/estimate_bucket_span')
82+
.set(COMMON_HEADERS)
83+
.send(testData.requestBody)
84+
.expect(testData.expected.responseCode);
85+
86+
expect(body).to.eql(testData.expected.responseBody);
87+
});
88+
}
89+
});
90+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { FtrProviderContext } from '../../ftr_provider_context';
8+
9+
export default function({ loadTestFile }: FtrProviderContext) {
10+
describe('Machine Learning', function() {
11+
this.tags(['mlqa']);
12+
13+
loadTestFile(require.resolve('./bucket_span_estimator'));
14+
});
15+
}

0 commit comments

Comments
 (0)