-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Add integration tests for trained_models
API
#104819
Merged
darnautov
merged 14 commits into
elastic:master
from
darnautov:ml-97982-trained-models-api-tests
Jul 9, 2021
Merged
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fab89f5
[ML] api integration tests for get trained models endpoint
darnautov 76923f6
[ML] delete ingest pipelines after tests execution
darnautov 85a71fe
[ML] deleteIngestPipeline method
darnautov 8572f7b
[ML] test for unauthorized user
darnautov 4771092
[ML] tests for model stats
darnautov 55e2e69
[ML] delete trained model tests
darnautov e13787b
[ML] fix typo
darnautov af01884
[ML] fix expect package path
darnautov cf99518
[ML] get model pipelines tests
darnautov 1e5e7f6
[ML] test for aliases
darnautov 88c805d
Merge remote-tracking branch 'upstream/master' into ml-97982-trained-…
darnautov eb7f505
[ML] add tests for a 404 response
darnautov 407294a
[ML] fix typo
darnautov 59b3cc6
[ML] fix typo
darnautov 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
66 changes: 66 additions & 0 deletions
66
x-pack/test/api_integration/apis/ml/trained_models/get_models.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,66 @@ | ||
/* | ||
* 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 supertest = getService('supertestWithoutAuth'); | ||
const ml = getService('ml'); | ||
|
||
describe('GET trained_models', () => { | ||
let testModelIds: string[] = []; | ||
|
||
before(async () => { | ||
await ml.testResources.setKibanaTimeZoneToUTC(); | ||
testModelIds = await ml.api.createdTestTrainedModels('regression', 5, true); | ||
}); | ||
|
||
after(async () => { | ||
await ml.api.cleanMlIndices(); | ||
// delete created ingest pipelines | ||
await Promise.all(testModelIds.map((modelId) => ml.api.deleteIngestPipeline(modelId))); | ||
}); | ||
|
||
it('returns all trained models with associated pipelined', async () => { | ||
const { body } = await supertest | ||
.get(`/api/ml/trained_models?with_pipelines=true`) | ||
.auth(USER.ML_POWERUSER, ml.securityCommon.getPasswordForUser(USER.ML_POWERUSER)) | ||
.set(COMMON_REQUEST_HEADERS) | ||
.expect(200); | ||
// Created models + system model | ||
expect(body.length).to.eql(6); | ||
|
||
const sampleModel = body.find((v: any) => v.model_id === 'dfa_regression_model_n_0'); | ||
expect(Object.keys(sampleModel.pipelines).length).to.eql(1); | ||
}); | ||
|
||
it('returns models without pipeline in case user does not have required permission', async () => { | ||
const { body } = await supertest | ||
.get(`/api/ml/trained_models?with_pipelines=true`) | ||
.auth(USER.ML_VIEWER, ml.securityCommon.getPasswordForUser(USER.ML_VIEWER)) | ||
.set(COMMON_REQUEST_HEADERS) | ||
.expect(200); | ||
// Created models + system model | ||
expect(body.length).to.eql(6); | ||
const sampleModel = body.find((v: any) => v.model_id === 'dfa_regression_model_n_0'); | ||
expect(sampleModel.pipelines).to.eql(undefined); | ||
}); | ||
|
||
it('returns trained model by id', async () => { | ||
peteharverson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { body } = await supertest | ||
.get(`/api/ml/trained_models/dfa_regression_model_n_1`) | ||
.auth(USER.ML_VIEWER, ml.securityCommon.getPasswordForUser(USER.ML_VIEWER)) | ||
.set(COMMON_REQUEST_HEADERS) | ||
.expect(200); | ||
expect(body.length).to.eql(1); | ||
expect(body[0].model_id).to.eql('dfa_regression_model_n_1'); | ||
}); | ||
}); | ||
}; |
14 changes: 14 additions & 0 deletions
14
x-pack/test/api_integration/apis/ml/trained_models/index.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,14 @@ | ||
/* | ||
* 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 { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
export default function ({ loadTestFile }: FtrProviderContext) { | ||
describe('trained models', function () { | ||
loadTestFile(require.resolve('./get_models')); | ||
}); | ||
} |
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.
Typo - should just be
pipelines
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.
fixed in e13787b