From fa3029225ae386a71f0109132354746a75201dd7 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Thu, 19 Dec 2024 19:44:25 +0100 Subject: [PATCH] [Discover] Reintroduce ESQL request count tests (#204925) --- .../apps/discover/group3/_request_counts.ts | 157 +++++++++++++----- 1 file changed, 112 insertions(+), 45 deletions(-) diff --git a/test/functional/apps/discover/group3/_request_counts.ts b/test/functional/apps/discover/group3/_request_counts.ts index 32f1be5a62e79..ecf84ede5a714 100644 --- a/test/functional/apps/discover/group3/_request_counts.ts +++ b/test/functional/apps/discover/group3/_request_counts.ts @@ -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 () { @@ -39,6 +42,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { enableESQL: true, }); await timePicker.setDefaultAbsoluteRangeViaUiSettings(); + await common.navigateToApp('discover'); + await header.waitUntilLoadingHasFinished(); }); after(async () => { @@ -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 () => { @@ -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 = ({ @@ -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 () => { @@ -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 () => { @@ -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', @@ -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'); }); @@ -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(); + }); + }); + }); }); }