-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] API integration tests - initial tests for bucket span estimator (#…
…52636) This PR adds basic API integration tests for the bucket span estimator.
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}); | ||
} |