-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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 tests for ml/modules/jobs_exist/{moduleId} #142378
Merged
jgowdyelastic
merged 8 commits into
elastic:main
from
jgowdyelastic:adding-api-tests-for-modules-jobs-exists-endpoint
Oct 3, 2022
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
36c5be4
[ML] Api tests for ml/modules/jobs_exist/{moduleId}
jgowdyelastic d669283
fixing title
jgowdyelastic 5839fab
fixing delete index pattern function
jgowdyelastic 860c420
Merge branch 'main' into adding-api-tests-for-modules-jobs-exists-end…
jgowdyelastic 351ff39
Merge branch 'main' into adding-api-tests-for-modules-jobs-exists-end…
jgowdyelastic d562319
Merge branch 'main' into adding-api-tests-for-modules-jobs-exists-end…
kibanamachine 788f2f6
Merge branch 'main' into adding-api-tests-for-modules-jobs-exists-end…
jgowdyelastic 00129e1
fixing test
jgowdyelastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
119 changes: 119 additions & 0 deletions
119
x-pack/test/api_integration/apis/ml/modules/jobs_exist.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,119 @@ | ||
/* | ||
* 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 { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { USER } from '../../../../functional/services/ml/security_common'; | ||
import { COMMON_REQUEST_HEADERS } from '../../../../functional/services/ml/common_api'; | ||
|
||
export default ({ getService }: FtrProviderContext) => { | ||
const esArchiver = getService('esArchiver'); | ||
const supertest = getService('supertestWithoutAuth'); | ||
const ml = getService('ml'); | ||
|
||
const idSpace1 = 'space1'; | ||
const sourceDataArchive = 'x-pack/test/functional/es_archives/ml/module_sample_logs'; | ||
const moduleInfo = { | ||
moduleId: 'sample_data_weblogs', | ||
jobIds: ['low_request_rate', 'response_code_rates', 'url_scanning'], | ||
dataView: { name: 'ft_module_sample_logs', timeField: '@timestamp' }, | ||
}; | ||
|
||
async function runRequest(moduleId: string, expectedStatusCode: number, user: USER) { | ||
const { body, status } = await supertest | ||
.get(`/api/ml/modules/jobs_exist/${moduleId}`) | ||
.auth(user, ml.securityCommon.getPasswordForUser(user)) | ||
.set(COMMON_REQUEST_HEADERS); | ||
|
||
ml.api.assertResponseStatusCode(expectedStatusCode, status, body); | ||
return body; | ||
} | ||
|
||
describe('GET ml/modules/jobs_exist/{moduleId}', function () { | ||
before(async () => { | ||
await ml.testResources.setKibanaTimeZoneToUTC(); | ||
await esArchiver.loadIfNeeded(sourceDataArchive); | ||
// create data view in default space | ||
await ml.testResources.createIndexPatternIfNeeded( | ||
moduleInfo.dataView.name, | ||
moduleInfo.dataView.timeField | ||
); | ||
// create data view in idSpace1 | ||
await ml.testResources.createIndexPatternIfNeeded( | ||
moduleInfo.dataView.name, | ||
moduleInfo.dataView.timeField, | ||
idSpace1 | ||
); | ||
}); | ||
|
||
afterEach(async () => { | ||
await ml.api.cleanMlIndices(); | ||
}); | ||
|
||
after(async () => { | ||
// delete all data views in all spaces | ||
await ml.testResources.deleteIndexPatternByTitle(moduleInfo.dataView.name); | ||
await ml.testResources.deleteIndexPatternByTitle(moduleInfo.dataView.name, idSpace1); | ||
}); | ||
|
||
it('should find jobs installed by module without prefix', async () => { | ||
const prefix = ''; | ||
await ml.api.setupModule(moduleInfo.moduleId, { | ||
prefix, | ||
indexPatternName: moduleInfo.dataView.name, | ||
startDatafeed: false, | ||
estimateModelMemory: false, | ||
}); | ||
const { jobsExist, jobs } = await runRequest(moduleInfo.moduleId, 200, USER.ML_POWERUSER); | ||
|
||
const expectedJobIds = moduleInfo.jobIds.map((j) => ({ id: `${prefix}${j}` })); | ||
expect(jobsExist).to.eql(true, 'Expected jobsExist to be true'); | ||
expect(jobs).to.eql(expectedJobIds, `Expected jobs to be ${expectedJobIds}`); | ||
}); | ||
|
||
it('should find jobs installed by module with prefix', async () => { | ||
const prefix = 'pf1_'; | ||
await ml.api.setupModule(moduleInfo.moduleId, { | ||
prefix, | ||
indexPatternName: moduleInfo.dataView.name, | ||
startDatafeed: false, | ||
estimateModelMemory: false, | ||
}); | ||
const { jobsExist, jobs } = await runRequest(moduleInfo.moduleId, 200, USER.ML_POWERUSER); | ||
|
||
const expectedJobIds = moduleInfo.jobIds.map((j) => ({ id: `${prefix}${j}` })); | ||
expect(jobsExist).to.eql(true, 'Expected jobsExist to be true'); | ||
expect(jobs).to.eql(expectedJobIds, `Expected jobs to be ${expectedJobIds}`); | ||
}); | ||
|
||
it('should not find jobs installed into a different space', async () => { | ||
const prefix = 'pf1_'; | ||
await ml.api.setupModule( | ||
moduleInfo.moduleId, | ||
{ | ||
prefix, | ||
indexPatternName: moduleInfo.dataView.name, | ||
startDatafeed: false, | ||
estimateModelMemory: false, | ||
}, | ||
idSpace1 | ||
); | ||
const { jobsExist, jobs } = await runRequest(moduleInfo.moduleId, 200, USER.ML_POWERUSER); | ||
|
||
expect(jobsExist).to.eql(false, 'Expected jobsExist to be false'); | ||
expect(jobs).to.eql(undefined, `Expected jobs to be undefined`); | ||
}); | ||
|
||
it("should not find jobs for module which hasn't been installed", async () => { | ||
const { jobsExist, jobs } = await runRequest('apache_ecs', 200, USER.ML_POWERUSER); | ||
|
||
expect(jobsExist).to.eql(false, 'Expected jobsExist to be false'); | ||
expect(jobs).to.eql(undefined, `Expected jobs to be undefined`); | ||
}); | ||
}); | ||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the changes in this file are to pass the space name around for the functions used by this test