Skip to content

Commit

Permalink
[ML] API integration tests - initial tests for bucket span estimator (#…
Browse files Browse the repository at this point in the history
…52636)

This PR adds basic API integration tests for the bucket span estimator.
  • Loading branch information
pheyos authored Dec 11, 2019
1 parent aa31b53 commit 248904e
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions x-pack/test/api_integration/apis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ export default function ({ loadTestFile }) {
loadTestFile(require.resolve('./short_urls'));
loadTestFile(require.resolve('./lens'));
loadTestFile(require.resolve('./endpoint'));
loadTestFile(require.resolve('./ml'));
});
}
90 changes: 90 additions & 0 deletions x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* 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',
};

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');
const supertest = getService('supertest');

describe('bucket span estimator', () => {
before(async () => {
await esArchiver.load('ml/ecommerce');
});

after(async () => {
await esArchiver.unload('ml/ecommerce');
});

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);
});
}
});
};
15 changes: 15 additions & 0 deletions x-pack/test/api_integration/apis/ml/index.ts
Original file line number Diff line number Diff line change
@@ -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'));
});
}

0 comments on commit 248904e

Please sign in to comment.