Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] API integration tests - initial tests for bucket span estimator #52636

Merged
merged 3 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'));
});
}