Skip to content

Commit

Permalink
[ML] AIOps: Enable Change point detection tests (elastic#177324)
Browse files Browse the repository at this point in the history
## Summary

Closes elastic#172984 

Enables Change point detection functional tests 


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
  • Loading branch information
darnautov authored and fkanout committed Mar 4, 2024
1 parent 74b4f05 commit 76adb7b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
31 changes: 18 additions & 13 deletions x-pack/test/functional/apps/aiops/change_point_detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
// aiops lives in the ML UI so we need some related services.
const ml = getService('ml');

// Failing ES Promotion: https://github.com/elastic/kibana/issues/172984
describe.skip('change point detection', async function () {
describe('change point detection', async function () {
before(async () => {
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/ecommerce');
await ml.testResources.createDataViewIfNeeded('ft_ecommerce', 'order_date');
Expand All @@ -43,10 +42,11 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await aiops.changePointDetectionPage.selectMetricField(0, 'products.discount_amount');
const result = await aiops.changePointDetectionPage.getTable(0).parseTable();
expect(result.length).to.eql(1);
expect(parseInt(result[0].pValue, 10)).to.eql(0);
expect(Number(result[0].pValue)).to.be.lessThan(1);
expect(result[0].type).to.eql('distribution_change');

await elasticChart.waitForRenderComplete('aiopChangePointPreviewChart > xyVisChart');
await ml.testExecution.logTestStep('Check the change point chart is rendered');
await elasticChart.waitForRenderComplete('aiopChangePointPreviewChart > xyVisChart', 5000);
const chartState = await elasticChart.getChartDebugData(
'aiopChangePointPreviewChart > xyVisChart',
0,
Expand All @@ -64,29 +64,34 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
await aiops.changePointDetectionPage.clickUseFullDataButton();
await aiops.changePointDetectionPage.selectMetricField(0, 'products.discount_amount');
await aiops.changePointDetectionPage.selectSplitField(0, 'geoip.city_name');
await aiops.changePointDetectionPage.getTable(0).waitForTableToLoad();
const result = await aiops.changePointDetectionPage.getTable(0).parseTable();

const tableService = aiops.changePointDetectionPage.getTable(0);
await tableService.waitForTableToLoad();
const result = await tableService.parseTable();
// the aggregation may return different results (+-1)
expect(result.length).to.be.above(4);
// assert asc sorting by p_value is applied
expect(parseFloat(result[0].pValue)).to.be.lessThan(parseFloat(result[3].pValue));
});

it('allows change point selection for detailed view', async () => {
await aiops.changePointDetectionPage.getTable(0).selectAllRows();
const tableService = aiops.changePointDetectionPage.getTable(0);

await tableService.selectAllRows();
await aiops.changePointDetectionPage.viewSelected();
await aiops.changePointDetectionPage.assertDetailedView(5);
await aiops.changePointDetectionPage.closeFlyout();
// deselect
await aiops.changePointDetectionPage.getTable(0).selectAllRows();
await tableService.selectAllRows();
});

it('supports a quick filter actions', async () => {
await aiops.changePointDetectionPage
.getTable(0)
.invokeAction(0, 'aiopsChangePointFilterForValue');
await aiops.changePointDetectionPage.getTable(0).waitForTableToLoad();
const resultFor = await aiops.changePointDetectionPage.getTable(0).parseTable();
const tableService = aiops.changePointDetectionPage.getTable(0);
await tableService.invokeAction(0, 'aiopsChangePointFilterForValue', async () => {
await aiops.changePointDetectionPage.assertFiltersApplied();
await tableService.waitForTableToStartLoading();
});
const resultFor = await tableService.parseTable();
expect(resultFor.length).to.eql(1);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ export function ChangePointDetectionPageProvider(
await this.completeSaveToDashboardForm({ createNew: true });
},

async assertFiltersApplied() {
await retry.tryForTime(30 * 1000, async () => {
await testSubjects.existOrFail('filter-items-group');
});
},

getTable(index: number) {
return tableService.getServiceInstance(
'ChangePointResultsTable',
Expand Down
9 changes: 8 additions & 1 deletion x-pack/test/functional/services/ml/common_table_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ export function MlTableServiceProvider({ getPageObject, getService }: FtrProvide
});
}

public async invokeAction(rowIndex: number, actionSubject: string) {
public async invokeAction(
rowIndex: number,
actionSubject: string,
postActionCallback: () => Promise<void>
) {
const rows = await testSubjects.findAll(
`${this.parentSubj ? `${this.parentSubj} > ` : ''}~${this.tableTestSubj} > ~${
this.tableRowSubj
Expand All @@ -159,6 +163,9 @@ export function MlTableServiceProvider({ getPageObject, getService }: FtrProvide

await retry.tryForTime(5000, async () => {
await actionButton.click();
if (postActionCallback) {
await postActionCallback();
}
await this.waitForTableToLoad();
});
}
Expand Down

0 comments on commit 76adb7b

Please sign in to comment.