-
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.
- Loading branch information
1 parent
c89ca51
commit a346964
Showing
4 changed files
with
164 additions
and
4 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
153 changes: 153 additions & 0 deletions
153
x-pack/test/api_integration/apis/ml/job_validation/datafeed_preview_validation.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,153 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { estypes } from '@elastic/elasticsearch'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { USER } from '../../../../functional/services/ml/security_common'; | ||
import { COMMON_REQUEST_HEADERS } from '../../../../functional/services/ml/common_api'; | ||
|
||
const farequoteMappings: estypes.MappingTypeMapping = { | ||
properties: { | ||
'@timestamp': { | ||
type: 'date', | ||
}, | ||
airline: { | ||
type: 'keyword', | ||
}, | ||
responsetime: { | ||
type: 'float', | ||
}, | ||
}, | ||
}; | ||
|
||
function getBaseJobConfig() { | ||
return { | ||
job_id: 'test', | ||
description: '', | ||
analysis_config: { | ||
bucket_span: '15m', | ||
detectors: [ | ||
{ | ||
function: 'mean', | ||
field_name: 'responsetime', | ||
}, | ||
], | ||
influencers: [], | ||
}, | ||
analysis_limits: { | ||
model_memory_limit: '11MB', | ||
}, | ||
data_description: { | ||
time_field: '@timestamp', | ||
time_format: 'epoch_ms', | ||
}, | ||
model_plot_config: { | ||
enabled: false, | ||
annotations_enabled: false, | ||
}, | ||
model_snapshot_retention_days: 10, | ||
daily_model_snapshot_retention_after_days: 1, | ||
allow_lazy_open: false, | ||
datafeed_config: { | ||
query: { | ||
bool: { | ||
must: [ | ||
{ | ||
match_all: {}, | ||
}, | ||
], | ||
}, | ||
}, | ||
indices: ['ft_farequote'], | ||
scroll_size: 1000, | ||
delayed_data_check_config: { | ||
enabled: true, | ||
}, | ||
job_id: 'test', | ||
datafeed_id: 'datafeed-test', | ||
}, | ||
}; | ||
} | ||
|
||
export default ({ getService }: FtrProviderContext) => { | ||
const esArchiver = getService('esArchiver'); | ||
const supertest = getService('supertestWithoutAuth'); | ||
const ml = getService('ml'); | ||
|
||
describe('Validate datafeed preview', function () { | ||
before(async () => { | ||
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote'); | ||
await ml.testResources.setKibanaTimeZoneToUTC(); | ||
ml.api.createIndex('farequote_empty', farequoteMappings); | ||
}); | ||
|
||
after(async () => { | ||
await ml.api.cleanMlIndices(); | ||
await ml.api.deleteIndices('farequote_empty'); | ||
}); | ||
|
||
it(`should validate a job with documents`, async () => { | ||
const job = getBaseJobConfig(); | ||
|
||
const { body } = await supertest | ||
.post('/api/ml/validate/datafeed_preview') | ||
.auth(USER.ML_POWERUSER, ml.securityCommon.getPasswordForUser(USER.ML_POWERUSER)) | ||
.set(COMMON_REQUEST_HEADERS) | ||
.send({ job }) | ||
.expect(200); | ||
|
||
expect(body.valid).to.eql(true, `valid should be true, but got ${body.valid}`); | ||
expect(body.documentsFound).to.eql( | ||
true, | ||
`documentsFound should be true, but got ${body.documentsFound}` | ||
); | ||
}); | ||
|
||
it(`should fail to validate a job with documents`, async () => { | ||
const job = getBaseJobConfig(); | ||
job.analysis_config.detectors[0].field_name = 'no_such_field'; | ||
|
||
const { body } = await supertest | ||
.post('/api/ml/validate/datafeed_preview') | ||
.auth(USER.ML_POWERUSER, ml.securityCommon.getPasswordForUser(USER.ML_POWERUSER)) | ||
.set(COMMON_REQUEST_HEADERS) | ||
.send({ job }) | ||
.expect(200); | ||
|
||
expect(body.valid).to.eql(false, `valid should be false, but got ${body.valid}`); | ||
expect(body.documentsFound).to.eql( | ||
false, | ||
`documentsFound should be false, but got ${body.documentsFound}` | ||
); | ||
}); | ||
|
||
it(`should validate a job with no documents`, async () => { | ||
const job = getBaseJobConfig(); | ||
job.datafeed_config.indices = ['farequote_empty']; | ||
|
||
const { body } = await supertest | ||
.post('/api/ml/validate/datafeed_preview') | ||
.auth(USER.ML_POWERUSER, ml.securityCommon.getPasswordForUser(USER.ML_POWERUSER)) | ||
.set(COMMON_REQUEST_HEADERS) | ||
.send({ job }) | ||
.expect(200); | ||
|
||
expect(body.valid).to.eql(true, `valid should be true, but got ${body.valid}`); | ||
expect(body.documentsFound).to.eql( | ||
false, | ||
`documentsFound should be false, but got ${body.documentsFound}` | ||
); | ||
}); | ||
}); | ||
}; |
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
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