Skip to content

Commit

Permalink
[ML] init functional test for cloning analytics jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Mar 13, 2020
1 parent 5939ddc commit cac0b36
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export interface DataFrameAnalyticsConfig {
};
source: {
index: IndexName | IndexName[];
query?: any;
};
analysis: AnalysisConfig;
analyzed_fields: {
Expand All @@ -258,6 +259,7 @@ export interface DataFrameAnalyticsConfig {
model_memory_limit: string;
create_time: number;
version: string;
allow_lazy_start: boolean;
}

export enum REFRESH_ANALYTICS_LIST_STATE {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import expect from '@kbn/expect';
import { DataFrameAnalyticsConfig } from '../../../../../legacy/plugins/ml/public/application/data_frame_analytics/common';

import { FtrProviderContext } from '../../../ftr_provider_context';

export default function({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const ml = getService('ml');
describe('classification cloning', function() {
this.tags(['smoke', 'dima']);

const testDataList: Array<{
suiteTitle: string;
job: Partial<DataFrameAnalyticsConfig>;
}> = [
{
suiteTitle: 'classification job supported by the form',
job: {
id: 'bm_classification_job',
source: {
index: ['bank-marketing'],
query: {
match_all: {},
},
},
dest: {
index: 'dest_bank_1',
results_field: 'ml',
},
analysis: {
classification: {
dependent_variable: 'y',
training_percent: 2,
},
},
analyzed_fields: {
includes: [],
excludes: [],
},
model_memory_limit: '350mb',
allow_lazy_start: false,
},
},
];

before(async () => {
await esArchiver.load('ml/bm_classification');
// Create jobs for cloning
for (const testData of testDataList) {
await ml.api.createDataFrameAnalyticsJob(testData.job as DataFrameAnalyticsConfig);
}

await ml.securityUI.loginAsMlPowerUser();
});

after(async () => {
await ml.api.cleanMlIndices();
await esArchiver.unload('ml/bm_classification');
});

for (const testData of testDataList) {
describe(`${testData.suiteTitle}`, function() {
before(async () => {
await ml.navigation.navigateToMl();
await ml.navigation.navigateToDataFrameAnalytics();
await ml.dataFrameAnalyticsTable.waitForAnalyticsToLoad();
await ml.dataFrameAnalyticsTable.filterWithSearchString(testData.job.id as string);
});

after(async () => {
await ml.api.deleteIndices(testData.job.dest!.index);
});

it('should opens the flyout with a proper header', async () => {
await ml.dataFrameAnalyticsTable.cloneJob(testData.job.id as string);
expect(await ml.dataFrameAnalyticsCreation.getHeaderText()).to.be(
'Clone job from bm_classification_job'
);
});
});
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export default function({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./outlier_detection_creation'));
loadTestFile(require.resolve('./regression_creation'));
loadTestFile(require.resolve('./classification_creation'));
loadTestFile(require.resolve('./cloning'));
});
}
24 changes: 23 additions & 1 deletion x-pack/test/functional/services/machine_learning/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
*/
import expect from '@kbn/expect';
import { ProvidedType } from '@kbn/test/types/ftr';
import { DataFrameAnalyticsConfig } from '../../../../legacy/plugins/ml/public/application/data_frame_analytics/common';

import { FtrProviderContext } from '../../ftr_provider_context';

import { JOB_STATE, DATAFEED_STATE } from '../../../../legacy/plugins/ml/common/constants/states';
import { DATA_FRAME_TASK_STATE } from '../../../../legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/common';
import { Job, Datafeed } from '../../../..//legacy/plugins/ml/common/types/anomaly_detection_jobs';
import { Job, Datafeed } from '../../../../legacy/plugins/ml/common/types/anomaly_detection_jobs';

export type MlApi = ProvidedType<typeof MachineLearningAPIProvider>;

Expand Down Expand Up @@ -355,5 +356,26 @@ export function MachineLearningAPIProvider({ getService }: FtrProviderContext) {
await this.waitForDatafeedState(datafeedConfig.datafeed_id, DATAFEED_STATE.STOPPED);
await this.waitForJobState(jobConfig.job_id, JOB_STATE.CLOSED);
},

async getDataFrameAnalyticsJob(analyticsId: string) {
return await esSupertest.get(`/_ml/data_frame/analytics/${analyticsId}`).expect(200);
},

async createDataFrameAnalyticsJob(jobConfig: DataFrameAnalyticsConfig) {
const { id: analyticsId, ...analyticsConfig } = jobConfig;
log.debug(`Creating data frame analytic job with id '${analyticsId}'...`);
await esSupertest
.put(`/_ml/data_frame/analytics/${analyticsId}`)
.send(analyticsConfig)
.expect(200);

await retry.waitForWithTimeout(`'${analyticsId}' to be created`, 5 * 1000, async () => {
if (await this.getDataFrameAnalyticsJob(analyticsId)) {
return true;
} else {
throw new Error(`expected data frame analytics job '${analyticsId}' to be created`);
}
});
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,5 +331,9 @@ export function MachineLearningDataFrameAnalyticsCreationProvider(
await testSubjects.missingOrFail('mlAnalyticsCreateJobFlyout');
});
},

async getHeaderText() {
return await testSubjects.getVisibleText('mlDataFrameAnalyticsFlyoutHeaderTitle');
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';

export function MachineLearningDataFrameAnalyticsTableProvider({ getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const find = getService('find');

return new (class AnalyticsTable {
public async parseAnalyticsTable() {
Expand Down Expand Up @@ -108,5 +109,18 @@ export function MachineLearningDataFrameAnalyticsTableProvider({ getService }: F
const analyticsRow = rows.filter(row => row.id === analyticsId)[0];
expect(analyticsRow).to.eql(expectedRow);
}

public async openRowActions(analyticsId: string) {
await find.clickByCssSelector(
`[data-test-subj="mlAnalyticsTableRow row-${analyticsId}"] [data-test-subj=euiCollapsedItemActionsButton]`
);
await find.existsByCssSelector('.euiPanel', 20 * 1000);
}

public async cloneJob(analyticsId: string) {
await this.openRowActions(analyticsId);
await testSubjects.click(`mlAnalyticsJobCloneButton`);
await testSubjects.existOrFail('mlAnalyticsCreateJobFlyout');
}
})();
}

0 comments on commit cac0b36

Please sign in to comment.