Skip to content
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 tests for anomaly embeddables migrations #116520

Merged
merged 8 commits into from
Nov 3, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const testDataList = [
panelTitle: `ML anomaly charts for ${JOB_CONFIG.job_id}`,
jobConfig: JOB_CONFIG,
datafeedConfig: DATAFEED_CONFIG,
dashboardTitle: `ML anomaly charts for fq_multi_1_ae ${Date.now()}`,
expected: {
influencers: [
{
Expand All @@ -59,7 +60,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const ml = getService('ml');
const PageObjects = getPageObjects(['common', 'timePicker', 'dashboard']);

describe('anomaly charts', function () {
describe('anomaly charts in dashboard', function () {
this.tags(['mlqa']);

before(async () => {
Expand All @@ -69,6 +70,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await ml.securityUI.loginAsMlPowerUser();
});

after(async () => {
await ml.api.cleanMlIndices();
});

for (const testData of testDataList) {
describe(testData.suiteSuffix, function () {
before(async () => {
Expand All @@ -79,12 +84,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.common.navigateToApp('dashboard');
});

after(async () => {
await ml.api.cleanMlIndices();
});

it('can open job selection flyout', async () => {
await PageObjects.dashboard.clickCreateDashboardPrompt();
await PageObjects.dashboard.clickNewDashboard();
await ml.dashboardEmbeddables.assertDashboardIsEmpty();
await ml.dashboardEmbeddables.openJobSelectionFlyout();
});
Expand All @@ -109,8 +110,52 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.timePicker.pauseAutoRefresh();
await ml.dashboardEmbeddables.assertAnomalyChartsSeverityThresholdControlExists();
await ml.dashboardEmbeddables.assertAnomalyChartsExists();
await PageObjects.dashboard.saveDashboard(testData.dashboardTitle);
});
});
}

describe('supports migrations', function () {
const panelTitle = `Saved ML anomaly charts for fq_multi_1_ae`;
const dashboardSavedObject = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth moving the saved object configs and then looping through each item in the list, making sure it can be loaded successfully. Then for 8.0, a 7.16 config can be added with minimal changes to the code required.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here eee3561

attributes: {
title: `ML anomaly charts 7.15 dashboard ${Date.now()}`,
description: '',
panelsJSON: `[{"version":"7.15.2","type":"ml_anomaly_charts","gridData":{"x":0,"y":0,"w":36,"h":20,"i":"ffcdb1ed-0079-41ee-8dda-3f6c138182ab"},"panelIndex":"ffcdb1ed-0079-41ee-8dda-3f6c138182ab","embeddableConfig":{"jobIds":["fq_multi_1_ae"],"maxSeriesToPlot":6,"severityThreshold":0,"enhancements":{}},"title":"${panelTitle}"}]`,
optionsJSON: '{"useMargins":true,"syncColors":false,"hidePanelTitles":false}',
timeRestore: true,
timeTo: '2016-02-11T00:00:00.000Z',
timeFrom: '2016-02-07T00:00:00.000Z',
refreshInterval: {
pause: true,
value: 0,
},
kibanaSavedObjectMeta: {
searchSourceJSON: '{"query":{"query":"","language":"kuery"},"filter":[]}',
},
},
coreMigrationVersion: '7.15.2',
};

before(async () => {
await ml.testResources.createDashboardSavedObject(
dashboardSavedObject.attributes.title,
dashboardSavedObject
);
await PageObjects.common.navigateToApp('dashboard');
});

it('loads saved dashboard from version 7.15', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the coreMigrationVersion from the saved object config be used in the test title?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here eee3561

await PageObjects.dashboard.loadSavedDashboard(dashboardSavedObject.attributes.title);
await ml.dashboardEmbeddables.assertDashboardPanelExists(panelTitle);
await PageObjects.timePicker.setAbsoluteRange(
'Feb 7, 2016 @ 00:00:00.000',
'Feb 11, 2016 @ 00:00:00.000'
);
await PageObjects.timePicker.pauseAutoRefresh();
await ml.dashboardEmbeddables.assertAnomalyChartsSeverityThresholdControlExists();
await ml.dashboardEmbeddables.assertAnomalyChartsExists();
});
});
});
}
13 changes: 13 additions & 0 deletions x-pack/test/functional/services/ml/test_resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ export function MachineLearningTestResourcesProvider({ getService }: FtrProvider
return createResponse.id;
},

async createDashboardSavedObject(title: string, body: object): Promise<string> {
log.debug(`Creating dashboard with title '${title}'`);

const createResponse = await supertest
.post(`/api/saved_objects/${SavedObjectType.DASHBOARD}`)
.set(COMMON_REQUEST_HEADERS)
.send(body)
.then((res: any) => res.body);

log.debug(` > Created with id '${createResponse.id}'`);
return createResponse.id;
},

async createIndexPatternIfNeeded(title: string, timeFieldName?: string): Promise<string> {
const indexPatternId = await this.getIndexPatternId(title);
if (indexPatternId !== undefined) {
Expand Down