From d5f58754bc32f3f6bd7389191aef99e72160311d Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Mon, 9 Dec 2019 15:46:48 +0100 Subject: [PATCH 1/2] Initial bucket span estimator API test --- x-pack/test/api_integration/apis/index.js | 1 + .../apis/ml/bucket_span_estimator.ts | 61 +++++++++++++++++++ x-pack/test/api_integration/apis/ml/index.ts | 15 +++++ 3 files changed, 77 insertions(+) create mode 100644 x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts create mode 100644 x-pack/test/api_integration/apis/ml/index.ts diff --git a/x-pack/test/api_integration/apis/index.js b/x-pack/test/api_integration/apis/index.js index ddf2c9a13ff67f..5f7945559e7beb 100644 --- a/x-pack/test/api_integration/apis/index.js +++ b/x-pack/test/api_integration/apis/index.js @@ -29,5 +29,6 @@ export default function ({ loadTestFile }) { loadTestFile(require.resolve('./lens')); loadTestFile(require.resolve('./licensing')); loadTestFile(require.resolve('./endpoint')); + loadTestFile(require.resolve('./ml')); }); } diff --git a/x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts b/x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts new file mode 100644 index 00000000000000..817f85a353783f --- /dev/null +++ b/x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts @@ -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 expect from '@kbn/expect'; + +import { FtrProviderContext } from '../../ftr_provider_context'; + +const COMMON_HEADERS = { + 'kbn-xsrf': 'some-xsrf-token', +}; + +// eslint-disable-next-line import/no-default-export +export default ({ getService }: FtrProviderContext) => { + const esArchiver = getService('esArchiver'); + const supertest = getService('supertest'); + + describe('bucket span estimator', () => { + before(async () => { + await esArchiver.load('ml/ecommerce'); + }); + + after(async () => { + await esArchiver.unload('ml/ecommerce'); + }); + + it('estimates the bucket span', async () => { + const { body } = await supertest + .post('/api/ml/validate/estimate_bucket_span') + .set(COMMON_HEADERS) + .send({ + aggTypes: ['avg'], + duration: { + start: 1560297859000, + end: 1562975136000, + }, + fields: ['taxless_total_price'], + index: 'ecommerce', + query: { + bool: { + must: [ + { + match_all: {}, + }, + ], + }, + }, + splitField: 'customer_first_name.keyword', + timeField: 'order_date', + }) + .expect(200); + + expect(body).to.eql({ + name: '3h', + ms: 10800000, + }); + }); + }); +}; diff --git a/x-pack/test/api_integration/apis/ml/index.ts b/x-pack/test/api_integration/apis/ml/index.ts new file mode 100644 index 00000000000000..2e0521e2b82737 --- /dev/null +++ b/x-pack/test/api_integration/apis/ml/index.ts @@ -0,0 +1,15 @@ +/* + * 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 { FtrProviderContext } from '../../ftr_provider_context'; + +export default function({ loadTestFile }: FtrProviderContext) { + describe('Machine Learning', function() { + this.tags(['mlqa']); + + loadTestFile(require.resolve('./bucket_span_estimator')); + }); +} From 767caa07da089037f6678b35176a03c2c110dbaa Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Tue, 10 Dec 2019 13:24:34 +0100 Subject: [PATCH 2/2] Add more bucket span estimator tests --- .../apis/ml/bucket_span_estimator.ts | 89 ++++++++++++------- 1 file changed, 59 insertions(+), 30 deletions(-) diff --git a/x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts b/x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts index 817f85a353783f..b5e5168621584d 100644 --- a/x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts +++ b/x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts @@ -12,6 +12,55 @@ const COMMON_HEADERS = { 'kbn-xsrf': 'some-xsrf-token', }; +const testDataList = [ + { + testTitleSuffix: 'with 1 field, 1 agg, no split', + requestBody: { + aggTypes: ['avg'], + duration: { start: 1560297859000, end: 1562975136000 }, + fields: ['taxless_total_price'], + index: 'ecommerce', + query: { bool: { must: [{ match_all: {} }] } }, + timeField: 'order_date', + }, + expected: { + responseCode: 200, + responseBody: { name: '15m', ms: 900000 }, + }, + }, + { + testTitleSuffix: 'with 2 fields, 2 aggs, no split', + requestBody: { + aggTypes: ['avg', 'sum'], + duration: { start: 1560297859000, end: 1562975136000 }, + fields: ['products.base_price', 'products.base_unit_price'], + index: 'ecommerce', + query: { bool: { must: [{ match_all: {} }] } }, + timeField: 'order_date', + }, + expected: { + responseCode: 200, + responseBody: { name: '30m', ms: 1800000 }, + }, + }, + { + testTitleSuffix: 'with 1 field, 1 agg, 1 split with cardinality 46', + requestBody: { + aggTypes: ['avg'], + duration: { start: 1560297859000, end: 1562975136000 }, + fields: ['taxless_total_price'], + index: 'ecommerce', + query: { bool: { must: [{ match_all: {} }] } }, + splitField: 'customer_first_name.keyword', + timeField: 'order_date', + }, + expected: { + responseCode: 200, + responseBody: { name: '3h', ms: 10800000 }, + }, + }, +]; + // eslint-disable-next-line import/no-default-export export default ({ getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); @@ -26,36 +75,16 @@ export default ({ getService }: FtrProviderContext) => { await esArchiver.unload('ml/ecommerce'); }); - it('estimates the bucket span', async () => { - const { body } = await supertest - .post('/api/ml/validate/estimate_bucket_span') - .set(COMMON_HEADERS) - .send({ - aggTypes: ['avg'], - duration: { - start: 1560297859000, - end: 1562975136000, - }, - fields: ['taxless_total_price'], - index: 'ecommerce', - query: { - bool: { - must: [ - { - match_all: {}, - }, - ], - }, - }, - splitField: 'customer_first_name.keyword', - timeField: 'order_date', - }) - .expect(200); - - expect(body).to.eql({ - name: '3h', - ms: 10800000, + for (const testData of testDataList) { + it(`estimates the bucket span ${testData.testTitleSuffix}`, async () => { + const { body } = await supertest + .post('/api/ml/validate/estimate_bucket_span') + .set(COMMON_HEADERS) + .send(testData.requestBody) + .expect(testData.expected.responseCode); + + expect(body).to.eql(testData.expected.responseBody); }); - }); + } }); };