|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +import expect from '@kbn/expect'; |
| 8 | + |
| 9 | +import { FtrProviderContext } from '../../ftr_provider_context'; |
| 10 | + |
| 11 | +const COMMON_HEADERS = { |
| 12 | + 'kbn-xsrf': 'some-xsrf-token', |
| 13 | +}; |
| 14 | + |
| 15 | +const testDataList = [ |
| 16 | + { |
| 17 | + testTitleSuffix: 'with 1 field, 1 agg, no split', |
| 18 | + requestBody: { |
| 19 | + aggTypes: ['avg'], |
| 20 | + duration: { start: 1560297859000, end: 1562975136000 }, |
| 21 | + fields: ['taxless_total_price'], |
| 22 | + index: 'ecommerce', |
| 23 | + query: { bool: { must: [{ match_all: {} }] } }, |
| 24 | + timeField: 'order_date', |
| 25 | + }, |
| 26 | + expected: { |
| 27 | + responseCode: 200, |
| 28 | + responseBody: { name: '15m', ms: 900000 }, |
| 29 | + }, |
| 30 | + }, |
| 31 | + { |
| 32 | + testTitleSuffix: 'with 2 fields, 2 aggs, no split', |
| 33 | + requestBody: { |
| 34 | + aggTypes: ['avg', 'sum'], |
| 35 | + duration: { start: 1560297859000, end: 1562975136000 }, |
| 36 | + fields: ['products.base_price', 'products.base_unit_price'], |
| 37 | + index: 'ecommerce', |
| 38 | + query: { bool: { must: [{ match_all: {} }] } }, |
| 39 | + timeField: 'order_date', |
| 40 | + }, |
| 41 | + expected: { |
| 42 | + responseCode: 200, |
| 43 | + responseBody: { name: '30m', ms: 1800000 }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + { |
| 47 | + testTitleSuffix: 'with 1 field, 1 agg, 1 split with cardinality 46', |
| 48 | + requestBody: { |
| 49 | + aggTypes: ['avg'], |
| 50 | + duration: { start: 1560297859000, end: 1562975136000 }, |
| 51 | + fields: ['taxless_total_price'], |
| 52 | + index: 'ecommerce', |
| 53 | + query: { bool: { must: [{ match_all: {} }] } }, |
| 54 | + splitField: 'customer_first_name.keyword', |
| 55 | + timeField: 'order_date', |
| 56 | + }, |
| 57 | + expected: { |
| 58 | + responseCode: 200, |
| 59 | + responseBody: { name: '3h', ms: 10800000 }, |
| 60 | + }, |
| 61 | + }, |
| 62 | +]; |
| 63 | + |
| 64 | +// eslint-disable-next-line import/no-default-export |
| 65 | +export default ({ getService }: FtrProviderContext) => { |
| 66 | + const esArchiver = getService('esArchiver'); |
| 67 | + const supertest = getService('supertest'); |
| 68 | + |
| 69 | + describe('bucket span estimator', () => { |
| 70 | + before(async () => { |
| 71 | + await esArchiver.load('ml/ecommerce'); |
| 72 | + }); |
| 73 | + |
| 74 | + after(async () => { |
| 75 | + await esArchiver.unload('ml/ecommerce'); |
| 76 | + }); |
| 77 | + |
| 78 | + for (const testData of testDataList) { |
| 79 | + it(`estimates the bucket span ${testData.testTitleSuffix}`, async () => { |
| 80 | + const { body } = await supertest |
| 81 | + .post('/api/ml/validate/estimate_bucket_span') |
| 82 | + .set(COMMON_HEADERS) |
| 83 | + .send(testData.requestBody) |
| 84 | + .expect(testData.expected.responseCode); |
| 85 | + |
| 86 | + expect(body).to.eql(testData.expected.responseBody); |
| 87 | + }); |
| 88 | + } |
| 89 | + }); |
| 90 | +}; |
0 commit comments