Skip to content

Commit

Permalink
adds kibana sample data logs as another explain log rate spikes test …
Browse files Browse the repository at this point in the history
…case
  • Loading branch information
walterra committed Apr 19, 2023
1 parent 0a4a0a9 commit bbce6de
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 63 deletions.
132 changes: 73 additions & 59 deletions x-pack/test/functional/apps/aiops/explain_log_rate_spikes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type { FtrProviderContext } from '../../ftr_provider_context';
import { isTestDataExpectedWithSampleProbability, type TestData } from './types';
import { explainLogRateSpikesTestData } from './test_data';

export default function ({ getPageObject, getService }: FtrProviderContext) {
const headerPage = getPageObject('header');
export default function ({ getPageObjects, getService }: FtrProviderContext) {
const PageObjects = getPageObjects(['common', 'console', 'header', 'home', 'security']);
const elasticChart = getService('elasticChart');
const aiops = getService('aiops');

Expand Down Expand Up @@ -58,7 +58,7 @@ export default function ({ getPageObject, getService }: FtrProviderContext) {
await aiops.explainLogRateSpikesPage.assertSamplingProbabilityMissing();
}

await headerPage.waitUntilLoadingHasFinished();
await PageObjects.header.waitUntilLoadingHasFinished();

await ml.testExecution.logTestStep(
`${testData.suiteTitle} displays elements in the doc count panel correctly`
Expand All @@ -78,77 +78,78 @@ export default function ({ getPageObject, getService }: FtrProviderContext) {
await aiops.explainLogRateSpikesPage.clickDocumentCountChart(testData.chartClickCoordinates);
await aiops.explainLogRateSpikesPage.assertAnalysisSectionExists();

await ml.testExecution.logTestStep('displays the no results found prompt');
await aiops.explainLogRateSpikesPage.assertNoResultsFoundEmptyPromptExists();
if (testData.brushDeviationTargetTimestamp) {
await ml.testExecution.logTestStep('displays the no results found prompt');
await aiops.explainLogRateSpikesPage.assertNoResultsFoundEmptyPromptExists();

await ml.testExecution.logTestStep('adjusts the brushes to get analysis results');
await aiops.explainLogRateSpikesPage.assertRerunAnalysisButtonExists(false);
await ml.testExecution.logTestStep('adjusts the brushes to get analysis results');
await aiops.explainLogRateSpikesPage.assertRerunAnalysisButtonExists(false);

// Get the current width of the deviation brush for later comparison.
const brushSelectionWidthBefore = await aiops.explainLogRateSpikesPage.getBrushSelectionWidth(
'aiopsBrushDeviation'
);

// Get the px values for the timestamp we want to move the brush to.
const { targetPx, intervalPx } = await aiops.explainLogRateSpikesPage.getPxForTimestamp(
testData.brushDeviationTargetTimestamp
);

// Adjust the right brush handle
await aiops.explainLogRateSpikesPage.adjustBrushHandler(
'aiopsBrushDeviation',
'handle--e',
targetPx + intervalPx * testData.brushIntervalFactor
);
// Get the current width of the deviation brush for later comparison.
const brushSelectionWidthBefore =
await aiops.explainLogRateSpikesPage.getBrushSelectionWidth('aiopsBrushDeviation');

// Adjust the left brush handle
await aiops.explainLogRateSpikesPage.adjustBrushHandler(
'aiopsBrushDeviation',
'handle--w',
targetPx - intervalPx * (testData.brushIntervalFactor - 1)
);

if (testData.brushBaselineTargetTimestamp) {
// Get the px values for the timestamp we want to move the brush to.
const { targetPx: targetBaselinePx } =
await aiops.explainLogRateSpikesPage.getPxForTimestamp(
testData.brushBaselineTargetTimestamp
);
const { targetPx, intervalPx } = await aiops.explainLogRateSpikesPage.getPxForTimestamp(
testData.brushDeviationTargetTimestamp
);

// Adjust the right brush handle
await aiops.explainLogRateSpikesPage.adjustBrushHandler(
'aiopsBrushBaseline',
'aiopsBrushDeviation',
'handle--e',
targetBaselinePx + intervalPx * testData.brushIntervalFactor
targetPx + intervalPx * testData.brushIntervalFactor
);

// Adjust the left brush handle
await aiops.explainLogRateSpikesPage.adjustBrushHandler(
'aiopsBrushBaseline',
'aiopsBrushDeviation',
'handle--w',
targetBaselinePx - intervalPx * (testData.brushIntervalFactor - 1)
targetPx - intervalPx * (testData.brushIntervalFactor - 1)
);
}

// Get the new brush selection width for later comparison.
const brushSelectionWidthAfter = await aiops.explainLogRateSpikesPage.getBrushSelectionWidth(
'aiopsBrushDeviation'
);
if (testData.brushBaselineTargetTimestamp) {
// Get the px values for the timestamp we want to move the brush to.
const { targetPx: targetBaselinePx } =
await aiops.explainLogRateSpikesPage.getPxForTimestamp(
testData.brushBaselineTargetTimestamp
);

// Adjust the right brush handle
await aiops.explainLogRateSpikesPage.adjustBrushHandler(
'aiopsBrushBaseline',
'handle--e',
targetBaselinePx + intervalPx * testData.brushIntervalFactor
);

// Assert the adjusted brush: The selection width should have changed and
// we test if the selection is smaller than two bucket intervals.
// Finally, the adjusted brush should trigger
// a warning on the "Rerun analysis" button.
expect(brushSelectionWidthBefore).not.to.be(brushSelectionWidthAfter);
expect(brushSelectionWidthAfter).not.to.be.greaterThan(
intervalPx * 2 * testData.brushIntervalFactor
);
// Adjust the left brush handle
await aiops.explainLogRateSpikesPage.adjustBrushHandler(
'aiopsBrushBaseline',
'handle--w',
targetBaselinePx - intervalPx * (testData.brushIntervalFactor - 1)
);
}

await aiops.explainLogRateSpikesPage.assertRerunAnalysisButtonExists(true);
// Get the new brush selection width for later comparison.
const brushSelectionWidthAfter =
await aiops.explainLogRateSpikesPage.getBrushSelectionWidth('aiopsBrushDeviation');

// Assert the adjusted brush: The selection width should have changed and
// we test if the selection is smaller than two bucket intervals.
// Finally, the adjusted brush should trigger
// a warning on the "Rerun analysis" button.
expect(brushSelectionWidthBefore).not.to.be(brushSelectionWidthAfter);
expect(brushSelectionWidthAfter).not.to.be.greaterThan(
intervalPx * 2 * testData.brushIntervalFactor
);

await aiops.explainLogRateSpikesPage.assertRerunAnalysisButtonExists(true);

await ml.testExecution.logTestStep('rerun the analysis with adjusted settings');
await ml.testExecution.logTestStep('rerun the analysis with adjusted settings');

await aiops.explainLogRateSpikesPage.clickRerunAnalysisButton(true);
}

await aiops.explainLogRateSpikesPage.clickRerunAnalysisButton(true);
await aiops.explainLogRateSpikesPage.assertProgressTitle('Progress: 100% — Done.');

// The group switch should be disabled by default
Expand Down Expand Up @@ -178,14 +179,14 @@ export default function ({ getPageObject, getService }: FtrProviderContext) {
);
}

// Assert the field selector that allows to costumize grouping
await ml.testExecution.logTestStep('open the field filter');
await aiops.explainLogRateSpikesPage.assertFieldFilterPopoverButtonExists(false);
await aiops.explainLogRateSpikesPage.clickFieldFilterPopoverButton(true);
await aiops.explainLogRateSpikesPage.assertFieldSelectorFieldNameList(
testData.expected.fieldSelectorPopover
);

// Filter fields
await ml.testExecution.logTestStep('filter fields');
await aiops.explainLogRateSpikesPage.setFieldSelectorSearch(testData.fieldSelectorSearch);
await aiops.explainLogRateSpikesPage.assertFieldSelectorFieldNameList([
testData.fieldSelectorSearch,
Expand All @@ -196,6 +197,7 @@ export default function ({ getPageObject, getService }: FtrProviderContext) {
);

if (testData.fieldSelectorApplyAvailable) {
await ml.testExecution.logTestStep('regroup results');
await aiops.explainLogRateSpikesPage.clickFieldFilterApplyButton();

if (!isTestDataExpectedWithSampleProbability(testData.expected)) {
Expand All @@ -222,13 +224,25 @@ export default function ({ getPageObject, getService }: FtrProviderContext) {

await ml.testResources.setKibanaTimeZoneToUTC();

await ml.securityUI.loginAsMlPowerUser();
if (testData.dataGenerator === 'kibana_sample_data_logs') {
await PageObjects.security.login('elastic', 'changeme', {
expectSuccess: true,
});

await PageObjects.common.navigateToUrl('home', '/tutorial_directory/sampleData', {
useActualUrl: true,
});
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.home.addSampleDataSet('logs');
await PageObjects.header.waitUntilLoadingHasFinished();
} else {
await ml.securityUI.loginAsMlPowerUser();
}
});

after(async () => {
await elasticChart.setNewChartUiDebugFlag(false);
await ml.testResources.deleteIndexPatternByTitle(testData.sourceIndexOrSavedSearch);

await aiops.explainLogRateSpikesDataGenerator.removeGeneratedData(testData.dataGenerator);
});

Expand Down
97 changes: 97 additions & 0 deletions x-pack/test/functional/apps/aiops/test_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,102 @@

import type { TestData } from './types';

export const kibanaLogsDataViewTestData: TestData = {
suiteTitle: 'kibana sample data logs',
dataGenerator: 'kibana_sample_data_logs',
isSavedSearch: false,
sourceIndexOrSavedSearch: 'kibana_sample_data_logs',
brushIntervalFactor: 1,
chartClickCoordinates: [235, 0],
fieldSelectorSearch: 'referer',
fieldSelectorApplyAvailable: true,
expected: {
totalDocCountFormatted: '14,074',
analysisGroupsTable: [
{
group:
'* clientip: 30.156.16.164* host.keyword: elastic-elastic-elastic.org* ip: 30.156.16.163* referer: http://www.elastic-elastic-elastic.com/success/timothy-l-kopra* response.keyword: 404Showing 5 out of 8 items. 8 items unique to this group.',
docCount: '100',
},
],
filteredAnalysisGroupsTable: [
{
group:
'* clientip: 30.156.16.164* host.keyword: elastic-elastic-elastic.org* ip: 30.156.16.163* response.keyword: 404* machine.os.keyword: win xpShowing 5 out of 7 items. 7 items unique to this group.',
docCount: '100',
},
],
analysisTable: [
{
fieldName: 'clientip',
fieldValue: '30.156.16.164',
logRate: 'Chart type:bar chart',
pValue: '3.10e-13',
impact: 'High',
},
{
fieldName: 'geo.dest',
fieldValue: 'IN',
logRate: 'Chart type:bar chart',
pValue: '0.000716',
impact: 'Medium',
},
{
fieldName: 'geo.srcdest',
fieldValue: 'US:IN',
logRate: 'Chart type:bar chart',
pValue: '0.000716',
impact: 'Medium',
},
{
fieldName: 'host.keyword',
fieldValue: 'elastic-elastic-elastic.org',
logRate: 'Chart type:bar chart',
pValue: '7.14e-9',
impact: 'High',
},
{
fieldName: 'ip',
fieldValue: '30.156.16.163',
logRate: 'Chart type:bar chart',
pValue: '3.28e-13',
impact: 'High',
},
{
fieldName: 'machine.os.keyword',
fieldValue: 'win xp',
logRate: 'Chart type:bar chart',
pValue: '0.0000997',
impact: 'Medium',
},
{
fieldName: 'referer',
fieldValue: 'http://www.elastic-elastic-elastic.com/success/timothy-l-kopra',
logRate: 'Chart type:bar chart',
pValue: '4.74e-13',
impact: 'High',
},
{
fieldName: 'response.keyword',
fieldValue: '404',
logRate: 'Chart type:bar chart',
pValue: '0.00000604',
impact: 'Medium',
},
],
fieldSelectorPopover: [
'clientip',
'geo.dest',
'geo.srcdest',
'host.keyword',
'ip',
'machine.os.keyword',
'referer',
'response.keyword',
],
},
};

export const farequoteDataViewTestData: TestData = {
suiteTitle: 'farequote with spike',
dataGenerator: 'farequote_with_spike',
Expand Down Expand Up @@ -122,6 +218,7 @@ export const artificialLogDataViewTestData: TestData = {
};

export const explainLogRateSpikesTestData: TestData[] = [
kibanaLogsDataViewTestData,
farequoteDataViewTestData,
farequoteDataViewTestDataWithQuery,
artificialLogDataViewTestData,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/aiops/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface TestData {
sourceIndexOrSavedSearch: string;
rowsPerPage?: 10 | 25 | 50;
brushBaselineTargetTimestamp?: number;
brushDeviationTargetTimestamp: number;
brushDeviationTargetTimestamp?: number;
brushIntervalFactor: number;
chartClickCoordinates: [number, number];
fieldSelectorSearch: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ export function ExplainLogRateSpikesDataGeneratorProvider({ getService }: FtrPro
return new (class DataGenerator {
public async generateData(dataGenerator: string) {
switch (dataGenerator) {
case 'kibana_sample_data_logs':
// will be added via UI
break;

case 'farequote_with_spike':
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/ml/farequote');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,11 @@ export function ExplainLogRateSpikesPageProvider({
},

async assertProgressTitle(expectedProgressTitle: string) {
await testSubjects.existOrFail('aiopProgressTitle');
const currentProgressTitle = await testSubjects.getVisibleText('aiopProgressTitle');
expect(currentProgressTitle).to.be(expectedProgressTitle);
await retry.tryForTime(30 * 1000, async () => {
await testSubjects.existOrFail('aiopProgressTitle');
const currentProgressTitle = await testSubjects.getVisibleText('aiopProgressTitle');
expect(currentProgressTitle).to.be(expectedProgressTitle);
});
},

async navigateToIndexPatternSelection() {
Expand Down

0 comments on commit bbce6de

Please sign in to comment.