-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] calculate model memory limit api integration tests
- Loading branch information
Showing
2 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
x-pack/test/api_integration/apis/ml/calculate_model_memory_limit.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,124 @@ | ||
/* | ||
* 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 3 metrics, 3 influencers, split by city', | ||
requestBody: { | ||
indexPattern: 'ecommerce', | ||
splitFieldName: 'geoip.city_name', | ||
query: { bool: { must: [{ match_all: {} }], filter: [], must_not: [] } }, | ||
fieldNames: ['products.base_price', 'taxful_total_price', 'products.discount_amount'], | ||
influencerNames: ['geoip.city_name', 'customer_gender', 'customer_full_name.keyword'], | ||
timeFieldName: 'order_date', | ||
earliestMs: 1560297859000, | ||
latestMs: 1562975136000, | ||
}, | ||
expected: { | ||
responseCode: 200, | ||
responseBody: { modelMemoryLimit: '14MB' }, | ||
}, | ||
}, | ||
{ | ||
testTitleSuffix: 'with 4 metrics, 4 influencers, split by customer_id', | ||
requestBody: { | ||
indexPattern: 'ecommerce', | ||
splitFieldName: 'customer_id', | ||
query: { bool: { must: [{ match_all: {} }], filter: [], must_not: [] } }, | ||
fieldNames: [ | ||
'geoip.country_iso_code', | ||
'taxless_total_price', | ||
'taxful_total_price', | ||
'products.discount_amount', | ||
], | ||
influencerNames: [ | ||
'customer_id', | ||
'geoip.country_iso_code', | ||
'products.discount_percentage', | ||
'products.discount_amount', | ||
], | ||
timeFieldName: 'order_date', | ||
earliestMs: 1560297859000, | ||
latestMs: 1562975136000, | ||
}, | ||
expected: { | ||
responseCode: 200, | ||
responseBody: { modelMemoryLimit: '23MB' }, | ||
}, | ||
}, | ||
{ | ||
testTitleSuffix: | ||
'with 4 metrics, 4 influencers, split by customer_id and filtering by country code', | ||
requestBody: { | ||
indexPattern: 'ecommerce', | ||
splitFieldName: 'customer_id', | ||
query: { | ||
bool: { | ||
filter: { | ||
term: { | ||
'geoip.country_iso_code': 'US', | ||
}, | ||
}, | ||
}, | ||
}, | ||
fieldNames: [ | ||
'geoip.country_iso_code', | ||
'taxless_total_price', | ||
'taxful_total_price', | ||
'products.discount_amount', | ||
], | ||
influencerNames: [ | ||
'customer_id', | ||
'geoip.country_iso_code', | ||
'products.discount_percentage', | ||
'products.discount_amount', | ||
], | ||
timeFieldName: 'order_date', | ||
earliestMs: 1560297859000, | ||
latestMs: 1562975136000, | ||
}, | ||
expected: { | ||
responseCode: 200, | ||
responseBody: { modelMemoryLimit: '14MB' }, | ||
}, | ||
}, | ||
]; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default ({ getService }: FtrProviderContext) => { | ||
const esArchiver = getService('esArchiver'); | ||
const supertest = getService('supertest'); | ||
|
||
describe('calculate model memory limit', () => { | ||
before(async () => { | ||
await esArchiver.load('ml/ecommerce'); | ||
}); | ||
|
||
after(async () => { | ||
await esArchiver.unload('ml/ecommerce'); | ||
}); | ||
|
||
for (const testData of testDataList) { | ||
it(`calculates the model memory limit ${testData.testTitleSuffix}`, async () => { | ||
const { body } = await supertest | ||
.post('/api/ml/validate/calculate_model_memory_limit') | ||
.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