Skip to content

Commit

Permalink
[ML] test for aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Jul 8, 2021
1 parent cf99518 commit 1e5e7f6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export default ({ getService }: FtrProviderContext) => {
});

after(async () => {
await ml.api.cleanMlIndices();
// delete all created ingest pipelines
await Promise.all(testModelIds.map((modelId) => ml.api.deleteIngestPipeline(modelId)));
await ml.api.cleanMlIndices();
});

it('returns trained model pipelines by id', async () => {
Expand Down
14 changes: 10 additions & 4 deletions x-pack/test/api_integration/apis/ml/trained_models/get_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ export default ({ getService }: FtrProviderContext) => {
before(async () => {
await ml.testResources.setKibanaTimeZoneToUTC();
testModelIds = await ml.api.createdTestTrainedModels('regression', 5, true);
await ml.api.createModelAlias('dfa_regression_model_n_0', 'dfa_regression_model_alias');
await ml.api.createIngestPipeline('dfa_regression_model_alias');
});

after(async () => {
await ml.api.cleanMlIndices();
// delete created ingest pipelines
await Promise.all(testModelIds.map((modelId) => ml.api.deleteIngestPipeline(modelId)));
await Promise.all(
['dfa_regression_model_alias', ...testModelIds].map((modelId) =>
ml.api.deleteIngestPipeline(modelId)
)
);
await ml.api.cleanMlIndices();
});

it('returns all trained models with associated pipelines', async () => {
it('returns all trained models with associated pipelines including aliases', async () => {
const { body } = await supertest
.get(`/api/ml/trained_models?with_pipelines=true`)
.auth(USER.ML_POWERUSER, ml.securityCommon.getPasswordForUser(USER.ML_POWERUSER))
Expand All @@ -38,7 +44,7 @@ export default ({ getService }: FtrProviderContext) => {
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);
expect(Object.keys(sampleModel.pipelines).length).to.eql(2);
});

it('returns models without pipeline in case user does not have required permission', async () => {
Expand Down
8 changes: 8 additions & 0 deletions x-pack/test/functional/services/ml/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,14 @@ export function MachineLearningAPIProvider({ getService }: FtrProviderContext) {
);
},

async createModelAlias(modelId: string, modelAlias: string) {
log.debug(`Creating alias for model "${modelId}"`);
await esSupertest
.put(`/_ml/trained_models/${modelId}/model_aliases/${modelAlias}`)
.expect(200);
log.debug('> Model alias created');
},

/**
* Creates ingest pipelines for trained model
* @param modelId
Expand Down

0 comments on commit 1e5e7f6

Please sign in to comment.