Skip to content

Commit

Permalink
[Discover] Reintroduce ESQL request count tests (#204925)
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal authored Dec 19, 2024
1 parent cdbcfd7 commit fa30292
Showing 1 changed file with 112 additions and 45 deletions.
157 changes: 112 additions & 45 deletions test/functional/apps/discover/group3/_request_counts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
]);
const testSubjects = getService('testSubjects');
const browser = getService('browser');
const monacoEditor = getService('monacoEditor');
const filterBar = getService('filterBar');
const queryBar = getService('queryBar');
const elasticChart = getService('elasticChart');
const log = getService('log');
const retry = getService('retry');

describe('discover request counts', function describeIndexTests() {
before(async function () {
Expand All @@ -39,6 +42,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
enableESQL: true,
});
await timePicker.setDefaultAbsoluteRangeViaUiSettings();
await common.navigateToApp('discover');
await header.waitUntilLoadingHasFinished();
});

after(async () => {
Expand All @@ -47,18 +52,31 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await kibanaServer.uiSettings.replace({});
});

beforeEach(async () => {
await common.navigateToApp('discover');
await header.waitUntilLoadingHasFinished();
});
const expectSearchCount = async (type: 'ese' | 'esql', searchCount: number) => {
await retry.try(async () => {
if (searchCount === 0) {
await browser.execute(async () => {
performance.clearResourceTimings();
});
}
await waitForLoadingToFinish();
const endpoint = type === 'esql' ? `${type}_async` : type;
const requests = await browser.execute(() =>
performance
.getEntries()
.filter((entry: any) => ['fetch', 'xmlhttprequest'].includes(entry.initiatorType))
);

const getSearchCount = async (type: 'ese' | 'esql') => {
const requests = await browser.execute(() =>
performance
.getEntries()
.filter((entry: any) => ['fetch', 'xmlhttprequest'].includes(entry.initiatorType))
);
return requests.filter((entry) => entry.name.endsWith(`/internal/search/${type}`)).length;
const result = requests.filter((entry) =>
entry.name.endsWith(`/internal/search/${endpoint}`)
);

const count = result.length;
if (count !== searchCount) {
log.warning('Request count differs:', result);
}
expect(count).to.be(searchCount);
});
};

const waitForLoadingToFinish = async () => {
Expand All @@ -68,15 +86,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
};

const expectSearches = async (type: 'ese' | 'esql', expected: number, cb: Function) => {
await browser.execute(async () => {
performance.clearResourceTimings();
});
let searchCount = await getSearchCount(type);
expect(searchCount).to.be(0);
await expectSearchCount(type, 0);
await cb();
await waitForLoadingToFinish();
searchCount = await getSearchCount(type);
expect(searchCount).to.be(expected);
await expectSearchCount(type, expected);
};

const getSharedTests = ({
Expand All @@ -103,8 +115,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
performance.setResourceTimingBufferSize(Number.MAX_SAFE_INTEGER);
});
await waitForLoadingToFinish();
const searchCount = await getSearchCount(type);
expect(searchCount).to.be(expectedRequests);
// one more requests for fields in ESQL mode
const actualExpectedRequests = type === 'esql' ? expectedRequests + 1 : expectedRequests;
await expectSearchCount(type, actualExpectedRequests);
});

it(`should send no more than ${expectedRequests} requests (documents + chart) when refreshing`, async () => {
Expand All @@ -121,12 +134,16 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

it(`should send no more than ${expectedRequests} requests (documents + chart) when changing the time range`, async () => {
await expectSearches(type, expectedRequests, async () => {
await timePicker.setAbsoluteRange(
'Sep 21, 2015 @ 06:31:44.000',
'Sep 23, 2015 @ 00:00:00.000'
);
});
await expectSearches(
type,
type === 'esql' ? expectedRequests + 1 : expectedRequests,
async () => {
await timePicker.setAbsoluteRange(
'Sep 21, 2015 @ 06:31:44.000',
'Sep 23, 2015 @ 00:00:00.000'
);
}
);
});

it(`should send ${savedSearchesRequests} requests for saved search changes`, async () => {
Expand All @@ -137,35 +154,50 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
'Sep 23, 2015 @ 00:00:00.000'
);
await waitForLoadingToFinish();
// TODO: Check why the request happens 4 times in case of opening a saved search
// https://github.com/elastic/kibana/issues/165192
// creating the saved search
await expectSearches(type, savedSearchesRequests ?? expectedRequests, async () => {
await discover.saveSearch(savedSearch);
});
// resetting the saved search
const actualExpectedRequests = savedSearchesRequests ?? expectedRequests;
log.debug('Creating saved search');
await expectSearches(
type,
type === 'esql' ? actualExpectedRequests + 2 : actualExpectedRequests,
async () => {
await discover.saveSearch(savedSearch);
}
);
log.debug('Resetting saved search');
await setQuery(query2);
await queryBar.clickQuerySubmitButton();
await waitForLoadingToFinish();
await expectSearches(type, expectedRequests, async () => {
await expectSearches(type, actualExpectedRequests, async () => {
await discover.revertUnsavedChanges();
});
// clearing the saved search
await expectSearches('ese', savedSearchesRequests ?? expectedRequests, async () => {
await testSubjects.click('discoverNewButton');
await waitForLoadingToFinish();
});
// loading the saved search
// TODO: https://github.com/elastic/kibana/issues/165192
await expectSearches(type, savedSearchesRequests ?? expectedRequests, async () => {
await discover.loadSavedSearch(savedSearch);
});
log.debug('Clearing saved search');
await expectSearches(
type,
type === 'esql' ? actualExpectedRequests + 2 : actualExpectedRequests,
async () => {
await testSubjects.click('discoverNewButton');
await waitForLoadingToFinish();
}
);
log.debug('Loading saved search');
await expectSearches(
type,
type === 'esql' ? actualExpectedRequests + 2 : actualExpectedRequests,
async () => {
await discover.loadSavedSearch(savedSearch);
}
);
});
};

describe('data view mode', () => {
const type = 'ese';

beforeEach(async () => {
await common.navigateToApp('discover');
await header.waitUntilLoadingHasFinished();
});

getSharedTests({
type,
savedSearch: 'data view test',
Expand Down Expand Up @@ -206,6 +238,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

it('should send no more than 3 requests (documents + chart + other bucket) when changing to a breakdown field with an other bucket', async () => {
await testSubjects.click('discoverNewButton');
await expectSearches(type, 3, async () => {
await discover.chooseBreakdownField('extension.raw');
});
Expand All @@ -223,5 +256,39 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});
});
});

describe('ES|QL mode', () => {
const type = 'esql';
before(async () => {
await common.navigateToApp('discover');
await header.waitUntilLoadingHasFinished();
await discover.selectTextBaseLang();
});

beforeEach(async () => {
await monacoEditor.setCodeEditorValue('from logstash-* | where bytes > 1000 ');
await queryBar.clickQuerySubmitButton();
await waitForLoadingToFinish();
});

getSharedTests({
type,
savedSearch: 'esql test',
query1: 'from logstash-* | where bytes > 1000 ',
query2: 'from logstash-* | where bytes < 2000 ',
savedSearchesRequests: 2,
setQuery: (query) => monacoEditor.setCodeEditorValue(query),
expectedRequests: 2,
});

it(`should send requests (documents + chart) when toggling the chart visibility`, async () => {
await expectSearches(type, 1, async () => {
await discover.toggleChartVisibility();
});
await expectSearches(type, 3, async () => {
await discover.toggleChartVisibility();
});
});
});
});
}

0 comments on commit fa30292

Please sign in to comment.