From ca8965b3ef58caa1f47758bf6e51fb74278c4f1e Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Thu, 2 Apr 2020 12:48:47 +0200 Subject: [PATCH 01/19] Unskip test --- test/functional/apps/discover/_field_visualize.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/functional/apps/discover/_field_visualize.ts b/test/functional/apps/discover/_field_visualize.ts index 24f4ba592324c..842aa74d0998a 100644 --- a/test/functional/apps/discover/_field_visualize.ts +++ b/test/functional/apps/discover/_field_visualize.ts @@ -33,7 +33,8 @@ export default function({ getService, getPageObjects }: FtrProviderContext) { }; // FLAKY: https://github.com/elastic/kibana/issues/61714 - describe.skip('discover field visualize button', () => { + // eslint-disable-next-line ban/ban + describe.only('discover field visualize button', () => { before(async function() { log.debug('load kibana index with default index pattern'); await esArchiver.load('discover'); From 12fdaba53a0aa12adba1e8a67f4c6693a48792dd Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Fri, 3 Apr 2020 23:36:54 +0200 Subject: [PATCH 02/19] Add visualize button test in OSS --- test/functional/apps/discover/_discover.js | 17 +++++++++++++++++ .../apps/discover/_field_visualize.ts | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/test/functional/apps/discover/_discover.js b/test/functional/apps/discover/_discover.js index 850b2773b5025..d8923762d8229 100644 --- a/test/functional/apps/discover/_discover.js +++ b/test/functional/apps/discover/_discover.js @@ -30,6 +30,23 @@ export default function({ getService, getPageObjects }) { defaultIndex: 'logstash-*', }; + // eslint-disable-next-line mocha/no-exclusive-tests + describe.only('discover test visualize', function describeIndexVisualizeTests() { + before(async function() { + await esArchiver.load('discover'); + // and load a set of makelogs data + await esArchiver.loadIfNeeded('logstash_functional'); + await kibanaServer.uiSettings.replace(defaultSettings); + }); + + it(`shows visualize button`, async () => { + await PageObjects.common.navigateToApp('discover'); + await PageObjects.timePicker.setDefaultAbsoluteRange(); + await PageObjects.discover.clickFieldListItem('bytes'); + await PageObjects.discover.expectFieldListItemVisualize('bytes'); + }); + }); + describe('discover test', function describeIndexTests() { before(async function() { log.debug('load kibana index with default index pattern'); diff --git a/test/functional/apps/discover/_field_visualize.ts b/test/functional/apps/discover/_field_visualize.ts index 842aa74d0998a..83a5876f0c570 100644 --- a/test/functional/apps/discover/_field_visualize.ts +++ b/test/functional/apps/discover/_field_visualize.ts @@ -34,7 +34,7 @@ export default function({ getService, getPageObjects }: FtrProviderContext) { // FLAKY: https://github.com/elastic/kibana/issues/61714 // eslint-disable-next-line ban/ban - describe.only('discover field visualize button', () => { + describe('discover field visualize button', () => { before(async function() { log.debug('load kibana index with default index pattern'); await esArchiver.load('discover'); From 3e9b076eceb0282ca52cf273baeacdf877aac7fc Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Sat, 4 Apr 2020 20:23:06 +0200 Subject: [PATCH 03/19] Remove other discover tests --- test/functional/apps/discover/_discover.js | 193 --------------------- 1 file changed, 193 deletions(-) diff --git a/test/functional/apps/discover/_discover.js b/test/functional/apps/discover/_discover.js index d8923762d8229..662b0af68ff4d 100644 --- a/test/functional/apps/discover/_discover.js +++ b/test/functional/apps/discover/_discover.js @@ -17,14 +17,9 @@ * under the License. */ -import expect from '@kbn/expect'; - export default function({ getService, getPageObjects }) { - const log = getService('log'); - const retry = getService('retry'); const esArchiver = getService('esArchiver'); const kibanaServer = getService('kibanaServer'); - const queryBar = getService('queryBar'); const PageObjects = getPageObjects(['common', 'discover', 'header', 'timePicker']); const defaultSettings = { defaultIndex: 'logstash-*', @@ -46,192 +41,4 @@ export default function({ getService, getPageObjects }) { await PageObjects.discover.expectFieldListItemVisualize('bytes'); }); }); - - describe('discover test', function describeIndexTests() { - before(async function() { - log.debug('load kibana index with default index pattern'); - await esArchiver.load('discover'); - - // and load a set of makelogs data - await esArchiver.loadIfNeeded('logstash_functional'); - await kibanaServer.uiSettings.replace(defaultSettings); - log.debug('discover'); - await PageObjects.common.navigateToApp('discover'); - await PageObjects.timePicker.setDefaultAbsoluteRange(); - }); - - describe('query', function() { - this.tags(['skipFirefox']); - const queryName1 = 'Query # 1'; - - it('should show correct time range string by timepicker', async function() { - const time = await PageObjects.timePicker.getTimeConfig(); - expect(time.start).to.be(PageObjects.timePicker.defaultStartTime); - expect(time.end).to.be(PageObjects.timePicker.defaultEndTime); - const rowData = await PageObjects.discover.getDocTableIndex(1); - log.debug('check the newest doc timestamp in UTC (check diff timezone in last test)'); - expect(rowData.startsWith('Sep 22, 2015 @ 23:50:13.253')).to.be.ok(); - }); - - it('save query should show toast message and display query name', async function() { - await PageObjects.discover.saveSearch(queryName1); - const actualQueryNameString = await PageObjects.discover.getCurrentQueryName(); - expect(actualQueryNameString).to.be(queryName1); - }); - - it('load query should show query name', async function() { - await PageObjects.discover.loadSavedSearch(queryName1); - - await retry.try(async function() { - expect(await PageObjects.discover.getCurrentQueryName()).to.be(queryName1); - }); - }); - - it('should show the correct hit count', async function() { - const expectedHitCount = '14,004'; - await retry.try(async function() { - expect(await PageObjects.discover.getHitCount()).to.be(expectedHitCount); - }); - }); - - it('should show correct time range string in chart', async function() { - const actualTimeString = await PageObjects.discover.getChartTimespan(); - const expectedTimeString = `${PageObjects.timePicker.defaultStartTime} - ${PageObjects.timePicker.defaultEndTime}`; - expect(actualTimeString).to.be(expectedTimeString); - }); - - it('should modify the time range when a bar is clicked', async function() { - await PageObjects.timePicker.setDefaultAbsoluteRange(); - await PageObjects.discover.clickHistogramBar(); - const time = await PageObjects.timePicker.getTimeConfig(); - expect(time.start).to.be('Sep 21, 2015 @ 09:00:00.000'); - expect(time.end).to.be('Sep 21, 2015 @ 12:00:00.000'); - const rowData = await PageObjects.discover.getDocTableField(1); - expect(rowData).to.have.string('Sep 21, 2015 @ 11:59:22.316'); - }); - - it('should modify the time range when the histogram is brushed', async function() { - await PageObjects.timePicker.setDefaultAbsoluteRange(); - await PageObjects.discover.brushHistogram(); - - const newDurationHours = await PageObjects.timePicker.getTimeDurationInHours(); - expect(Math.round(newDurationHours)).to.be(25); - const rowData = await PageObjects.discover.getDocTableField(1); - expect(Date.parse(rowData)).to.be.within( - Date.parse('Sep 20, 2015 @ 22:00:00.000'), - Date.parse('Sep 20, 2015 @ 23:30:00.000') - ); - }); - - it('should show correct initial chart interval of Auto', async function() { - await PageObjects.timePicker.setDefaultAbsoluteRange(); - await PageObjects.discover.waitUntilSearchingHasFinished(); - const actualInterval = await PageObjects.discover.getChartInterval(); - - const expectedInterval = 'Auto'; - expect(actualInterval).to.be(expectedInterval); - }); - - it('should show Auto chart interval', async function() { - const expectedChartInterval = 'Auto'; - - const actualInterval = await PageObjects.discover.getChartInterval(); - expect(actualInterval).to.be(expectedChartInterval); - }); - - it('should not show "no results"', async () => { - const isVisible = await PageObjects.discover.hasNoResults(); - expect(isVisible).to.be(false); - }); - }); - - describe('query #2, which has an empty time range', () => { - const fromTime = 'Jun 11, 1999 @ 09:22:11.000'; - const toTime = 'Jun 12, 1999 @ 11:21:04.000'; - - before(async () => { - log.debug('setAbsoluteRangeForAnotherQuery'); - await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime); - await PageObjects.discover.waitUntilSearchingHasFinished(); - }); - - it('should show "no results"', async () => { - const isVisible = await PageObjects.discover.hasNoResults(); - expect(isVisible).to.be(true); - }); - - it('should suggest a new time range is picked', async () => { - const isVisible = await PageObjects.discover.hasNoResultsTimepicker(); - expect(isVisible).to.be(true); - }); - }); - - describe('nested query', () => { - before(async () => { - log.debug('setAbsoluteRangeForAnotherQuery'); - await PageObjects.timePicker.setDefaultAbsoluteRange(); - await PageObjects.discover.waitUntilSearchingHasFinished(); - }); - - it('should support querying on nested fields', async function() { - await queryBar.setQuery('nestedField:{ child: nestedValue }'); - await queryBar.submitQuery(); - await retry.try(async function() { - expect(await PageObjects.discover.getHitCount()).to.be('1'); - }); - }); - }); - - describe('data-shared-item', function() { - it('should have correct data-shared-item title and description', async () => { - const expected = { - title: 'A Saved Search', - description: 'A Saved Search Description', - }; - - await retry.try(async () => { - await PageObjects.discover.loadSavedSearch(expected.title); - const { - title, - description, - } = await PageObjects.common.getSharedItemTitleAndDescription(); - expect(title).to.eql(expected.title); - expect(description).to.eql(expected.description); - }); - }); - }); - - describe('time zone switch', () => { - it('should show bars in the correct time zone after switching', async function() { - await kibanaServer.uiSettings.replace({ 'dateFormat:tz': 'America/Phoenix' }); - await PageObjects.common.navigateToApp('discover'); - await PageObjects.header.awaitKibanaChrome(); - await queryBar.setQuery(''); - await PageObjects.timePicker.setDefaultAbsoluteRange(); - - log.debug( - 'check that the newest doc timestamp is now -7 hours from the UTC time in the first test' - ); - const rowData = await PageObjects.discover.getDocTableIndex(1); - expect(rowData.startsWith('Sep 22, 2015 @ 16:50:13.253')).to.be.ok(); - }); - }); - describe('usage of discover:searchOnPageLoad', () => { - it('should fetch data from ES initially when discover:searchOnPageLoad is false', async function() { - await kibanaServer.uiSettings.replace({ 'discover:searchOnPageLoad': false }); - await PageObjects.common.navigateToApp('discover'); - await PageObjects.header.awaitKibanaChrome(); - - expect(await PageObjects.discover.getNrOfFetches()).to.be(0); - }); - - it('should not fetch data from ES initially when discover:searchOnPageLoad is true', async function() { - await kibanaServer.uiSettings.replace({ 'discover:searchOnPageLoad': true }); - await PageObjects.common.navigateToApp('discover'); - await PageObjects.header.awaitKibanaChrome(); - - expect(await PageObjects.discover.getNrOfFetches()).to.be(1); - }); - }); - }); } From e55fddeb36a42373007b8d651d73e51d7f9a3426 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Sun, 5 Apr 2020 23:38:52 +0200 Subject: [PATCH 04/19] Implement retry for flaky tests --- .../feature_controls/discover_spaces.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts index f33b8b4899d16..a28b1e5a42f07 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts @@ -10,6 +10,7 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const config = getService('config'); const spacesService = getService('spaces'); + const retry = getService('retry'); const PageObjects = getPageObjects([ 'common', 'discover', @@ -25,9 +26,11 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { } // FLAKY: https://github.com/elastic/kibana/issues/60559 - describe.skip('spaces', () => { + describe('spaces', () => { before(async () => { await esArchiver.loadIfNeeded('logstash_functional'); + await PageObjects.common.navigateToApp('discover'); + await PageObjects.timePicker.setDefaultAbsoluteRange(); }); describe('space with no features disabled', () => { @@ -68,9 +71,11 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { await PageObjects.common.navigateToApp('discover', { basePath: '/s/custom_space', }); - await setDiscoverTimeRange(); - await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectFieldListItemVisualize('bytes'); + await retry.try(async () => { + await setDiscoverTimeRange(); + await PageObjects.discover.clickFieldListItem('bytes'); + await PageObjects.discover.expectFieldListItemVisualize('bytes'); + }); }); }); @@ -134,9 +139,11 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { await PageObjects.common.navigateToApp('discover', { basePath: '/s/custom_space', }); - await setDiscoverTimeRange(); - await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); + await retry.try(async () => { + await setDiscoverTimeRange(); + await PageObjects.discover.clickFieldListItem('bytes'); + await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); + }); }); }); From 9e3e00a50cbeefe574a7fe89002a8e853ae8d4f2 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Mon, 6 Apr 2020 07:51:05 +0200 Subject: [PATCH 05/19] Remove before code that failed --- .../apps/discover/feature_controls/discover_spaces.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts index a28b1e5a42f07..15a376c3bf665 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts @@ -29,8 +29,6 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { describe('spaces', () => { before(async () => { await esArchiver.loadIfNeeded('logstash_functional'); - await PageObjects.common.navigateToApp('discover'); - await PageObjects.timePicker.setDefaultAbsoluteRange(); }); describe('space with no features disabled', () => { From afc9ff3468e2ef2fa3140fefb8904a4c1051e58d Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Mon, 6 Apr 2020 12:14:12 +0200 Subject: [PATCH 06/19] Improve retry code --- .../apps/discover/feature_controls/discover_spaces.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts index 15a376c3bf665..10cb0a8751f27 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts @@ -26,7 +26,8 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { } // FLAKY: https://github.com/elastic/kibana/issues/60559 - describe('spaces', () => { + // eslint-disable-next-line ban/ban + describe.only('spaces', () => { before(async () => { await esArchiver.loadIfNeeded('logstash_functional'); }); @@ -71,6 +72,10 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { }); await retry.try(async () => { await setDiscoverTimeRange(); + + const hasNoResults = await PageObjects.discover.hasNoResults(); + expect(hasNoResults).to.be(false); + await PageObjects.discover.clickFieldListItem('bytes'); await PageObjects.discover.expectFieldListItemVisualize('bytes'); }); @@ -139,6 +144,8 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { }); await retry.try(async () => { await setDiscoverTimeRange(); + const hasNoResults = await PageObjects.discover.hasNoResults(); + expect(hasNoResults).to.be(false); await PageObjects.discover.clickFieldListItem('bytes'); await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); }); From f1ee00fd28ab1e1173fab113f9e1028069ee9c9c Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Mon, 6 Apr 2020 15:10:30 +0200 Subject: [PATCH 07/19] Apply fix to discover security and spaces --- .../feature_controls/discover_security.ts | 35 +++++++++++++------ .../feature_controls/discover_spaces.ts | 5 +-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts index dc8c488460100..c147dd97c1ea1 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts @@ -28,8 +28,7 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { await PageObjects.timePicker.setDefaultAbsoluteRange(); } - // FLAKY: https://github.com/elastic/kibana/issues/60535 - describe.skip('security', () => { + describe('security', () => { before(async () => { await esArchiver.load('discover/feature_controls/security'); await esArchiver.loadIfNeeded('logstash_functional'); @@ -185,9 +184,14 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { it(`doesn't show visualize button`, async () => { await PageObjects.common.navigateToApp('discover'); - await setDiscoverTimeRange(); - await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); + await retry.try(async () => { + await setDiscoverTimeRange(); + const hasNoResults = await PageObjects.discover.hasNoResults(); + expect(hasNoResults).to.be(false); + + await PageObjects.discover.clickFieldListItem('bytes'); + await PageObjects.discover.expectFieldListItemVisualize('bytes'); + }); }); it(`Permalinks doesn't show create short-url button`, async () => { @@ -274,9 +278,13 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { it(`doesn't show visualize button`, async () => { await PageObjects.common.navigateToApp('discover'); - await setDiscoverTimeRange(); - await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); + await retry.try(async () => { + await setDiscoverTimeRange(); + const hasNoResults = await PageObjects.discover.hasNoResults(); + expect(hasNoResults).to.be(false); + await PageObjects.discover.clickFieldListItem('bytes'); + await PageObjects.discover.expectFieldListItemVisualize('bytes'); + }); }); it('Permalinks shows create short-url button', async () => { @@ -351,9 +359,14 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { it(`shows the visualize button`, async () => { await PageObjects.common.navigateToApp('discover'); - await setDiscoverTimeRange(); - await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectFieldListItemVisualize('bytes'); + await retry.try(async () => { + await setDiscoverTimeRange(); + const hasNoResults = await PageObjects.discover.hasNoResults(); + expect(hasNoResults).to.be(false); + + await PageObjects.discover.clickFieldListItem('bytes'); + await PageObjects.discover.expectFieldListItemVisualize('bytes'); + }); }); }); diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts index 10cb0a8751f27..0b0ca2e15b9dd 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts @@ -25,9 +25,7 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { await PageObjects.timePicker.setDefaultAbsoluteRange(); } - // FLAKY: https://github.com/elastic/kibana/issues/60559 - // eslint-disable-next-line ban/ban - describe.only('spaces', () => { + describe('spaces', () => { before(async () => { await esArchiver.loadIfNeeded('logstash_functional'); }); @@ -72,7 +70,6 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { }); await retry.try(async () => { await setDiscoverTimeRange(); - const hasNoResults = await PageObjects.discover.hasNoResults(); expect(hasNoResults).to.be(false); From ff5895e099ffe2ca48c170dd50e441c34c1f60c6 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Mon, 6 Apr 2020 15:37:05 +0200 Subject: [PATCH 08/19] Undo _discover.js changes --- test/functional/apps/discover/_discover.js | 190 ++++++++++++++++++++- 1 file changed, 183 insertions(+), 7 deletions(-) diff --git a/test/functional/apps/discover/_discover.js b/test/functional/apps/discover/_discover.js index 662b0af68ff4d..850b2773b5025 100644 --- a/test/functional/apps/discover/_discover.js +++ b/test/functional/apps/discover/_discover.js @@ -17,28 +17,204 @@ * under the License. */ +import expect from '@kbn/expect'; + export default function({ getService, getPageObjects }) { + const log = getService('log'); + const retry = getService('retry'); const esArchiver = getService('esArchiver'); const kibanaServer = getService('kibanaServer'); + const queryBar = getService('queryBar'); const PageObjects = getPageObjects(['common', 'discover', 'header', 'timePicker']); const defaultSettings = { defaultIndex: 'logstash-*', }; - // eslint-disable-next-line mocha/no-exclusive-tests - describe.only('discover test visualize', function describeIndexVisualizeTests() { + describe('discover test', function describeIndexTests() { before(async function() { + log.debug('load kibana index with default index pattern'); await esArchiver.load('discover'); + // and load a set of makelogs data await esArchiver.loadIfNeeded('logstash_functional'); await kibanaServer.uiSettings.replace(defaultSettings); - }); - - it(`shows visualize button`, async () => { + log.debug('discover'); await PageObjects.common.navigateToApp('discover'); await PageObjects.timePicker.setDefaultAbsoluteRange(); - await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectFieldListItemVisualize('bytes'); + }); + + describe('query', function() { + this.tags(['skipFirefox']); + const queryName1 = 'Query # 1'; + + it('should show correct time range string by timepicker', async function() { + const time = await PageObjects.timePicker.getTimeConfig(); + expect(time.start).to.be(PageObjects.timePicker.defaultStartTime); + expect(time.end).to.be(PageObjects.timePicker.defaultEndTime); + const rowData = await PageObjects.discover.getDocTableIndex(1); + log.debug('check the newest doc timestamp in UTC (check diff timezone in last test)'); + expect(rowData.startsWith('Sep 22, 2015 @ 23:50:13.253')).to.be.ok(); + }); + + it('save query should show toast message and display query name', async function() { + await PageObjects.discover.saveSearch(queryName1); + const actualQueryNameString = await PageObjects.discover.getCurrentQueryName(); + expect(actualQueryNameString).to.be(queryName1); + }); + + it('load query should show query name', async function() { + await PageObjects.discover.loadSavedSearch(queryName1); + + await retry.try(async function() { + expect(await PageObjects.discover.getCurrentQueryName()).to.be(queryName1); + }); + }); + + it('should show the correct hit count', async function() { + const expectedHitCount = '14,004'; + await retry.try(async function() { + expect(await PageObjects.discover.getHitCount()).to.be(expectedHitCount); + }); + }); + + it('should show correct time range string in chart', async function() { + const actualTimeString = await PageObjects.discover.getChartTimespan(); + const expectedTimeString = `${PageObjects.timePicker.defaultStartTime} - ${PageObjects.timePicker.defaultEndTime}`; + expect(actualTimeString).to.be(expectedTimeString); + }); + + it('should modify the time range when a bar is clicked', async function() { + await PageObjects.timePicker.setDefaultAbsoluteRange(); + await PageObjects.discover.clickHistogramBar(); + const time = await PageObjects.timePicker.getTimeConfig(); + expect(time.start).to.be('Sep 21, 2015 @ 09:00:00.000'); + expect(time.end).to.be('Sep 21, 2015 @ 12:00:00.000'); + const rowData = await PageObjects.discover.getDocTableField(1); + expect(rowData).to.have.string('Sep 21, 2015 @ 11:59:22.316'); + }); + + it('should modify the time range when the histogram is brushed', async function() { + await PageObjects.timePicker.setDefaultAbsoluteRange(); + await PageObjects.discover.brushHistogram(); + + const newDurationHours = await PageObjects.timePicker.getTimeDurationInHours(); + expect(Math.round(newDurationHours)).to.be(25); + const rowData = await PageObjects.discover.getDocTableField(1); + expect(Date.parse(rowData)).to.be.within( + Date.parse('Sep 20, 2015 @ 22:00:00.000'), + Date.parse('Sep 20, 2015 @ 23:30:00.000') + ); + }); + + it('should show correct initial chart interval of Auto', async function() { + await PageObjects.timePicker.setDefaultAbsoluteRange(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + const actualInterval = await PageObjects.discover.getChartInterval(); + + const expectedInterval = 'Auto'; + expect(actualInterval).to.be(expectedInterval); + }); + + it('should show Auto chart interval', async function() { + const expectedChartInterval = 'Auto'; + + const actualInterval = await PageObjects.discover.getChartInterval(); + expect(actualInterval).to.be(expectedChartInterval); + }); + + it('should not show "no results"', async () => { + const isVisible = await PageObjects.discover.hasNoResults(); + expect(isVisible).to.be(false); + }); + }); + + describe('query #2, which has an empty time range', () => { + const fromTime = 'Jun 11, 1999 @ 09:22:11.000'; + const toTime = 'Jun 12, 1999 @ 11:21:04.000'; + + before(async () => { + log.debug('setAbsoluteRangeForAnotherQuery'); + await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime); + await PageObjects.discover.waitUntilSearchingHasFinished(); + }); + + it('should show "no results"', async () => { + const isVisible = await PageObjects.discover.hasNoResults(); + expect(isVisible).to.be(true); + }); + + it('should suggest a new time range is picked', async () => { + const isVisible = await PageObjects.discover.hasNoResultsTimepicker(); + expect(isVisible).to.be(true); + }); + }); + + describe('nested query', () => { + before(async () => { + log.debug('setAbsoluteRangeForAnotherQuery'); + await PageObjects.timePicker.setDefaultAbsoluteRange(); + await PageObjects.discover.waitUntilSearchingHasFinished(); + }); + + it('should support querying on nested fields', async function() { + await queryBar.setQuery('nestedField:{ child: nestedValue }'); + await queryBar.submitQuery(); + await retry.try(async function() { + expect(await PageObjects.discover.getHitCount()).to.be('1'); + }); + }); + }); + + describe('data-shared-item', function() { + it('should have correct data-shared-item title and description', async () => { + const expected = { + title: 'A Saved Search', + description: 'A Saved Search Description', + }; + + await retry.try(async () => { + await PageObjects.discover.loadSavedSearch(expected.title); + const { + title, + description, + } = await PageObjects.common.getSharedItemTitleAndDescription(); + expect(title).to.eql(expected.title); + expect(description).to.eql(expected.description); + }); + }); + }); + + describe('time zone switch', () => { + it('should show bars in the correct time zone after switching', async function() { + await kibanaServer.uiSettings.replace({ 'dateFormat:tz': 'America/Phoenix' }); + await PageObjects.common.navigateToApp('discover'); + await PageObjects.header.awaitKibanaChrome(); + await queryBar.setQuery(''); + await PageObjects.timePicker.setDefaultAbsoluteRange(); + + log.debug( + 'check that the newest doc timestamp is now -7 hours from the UTC time in the first test' + ); + const rowData = await PageObjects.discover.getDocTableIndex(1); + expect(rowData.startsWith('Sep 22, 2015 @ 16:50:13.253')).to.be.ok(); + }); + }); + describe('usage of discover:searchOnPageLoad', () => { + it('should fetch data from ES initially when discover:searchOnPageLoad is false', async function() { + await kibanaServer.uiSettings.replace({ 'discover:searchOnPageLoad': false }); + await PageObjects.common.navigateToApp('discover'); + await PageObjects.header.awaitKibanaChrome(); + + expect(await PageObjects.discover.getNrOfFetches()).to.be(0); + }); + + it('should not fetch data from ES initially when discover:searchOnPageLoad is true', async function() { + await kibanaServer.uiSettings.replace({ 'discover:searchOnPageLoad': true }); + await PageObjects.common.navigateToApp('discover'); + await PageObjects.header.awaitKibanaChrome(); + + expect(await PageObjects.discover.getNrOfFetches()).to.be(1); + }); }); }); } From 0088147bf2c23f41dd01bce73b8108e254eec9e3 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Mon, 6 Apr 2020 16:44:27 +0200 Subject: [PATCH 09/19] Add missing retry service to discover_security.ts --- .../apps/discover/feature_controls/discover_security.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts index c147dd97c1ea1..19db1cf0cec59 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts @@ -8,6 +8,7 @@ import { FtrProviderContext } from '../../../ftr_provider_context'; export default function({ getPageObjects, getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); + const retry = getService('retry'); const security = getService('security'); const globalNav = getService('globalNav'); const config = getService('config'); From d318d329fdbb226c8dc54a7f4eda368f4c3cfc97 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Mon, 6 Apr 2020 17:51:57 +0200 Subject: [PATCH 10/19] Fix security bugs --- .../apps/discover/feature_controls/discover_security.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts index 19db1cf0cec59..2004bba5d6812 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts @@ -191,7 +191,7 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { expect(hasNoResults).to.be(false); await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectFieldListItemVisualize('bytes'); + await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); }); }); @@ -284,7 +284,7 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { const hasNoResults = await PageObjects.discover.hasNoResults(); expect(hasNoResults).to.be(false); await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectFieldListItemVisualize('bytes'); + await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); }); }); From e73cd0b3e5ec20f8d7bd3b36fb2988935dffda33 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Thu, 16 Apr 2020 07:10:16 +0200 Subject: [PATCH 11/19] Adapt tests to use PageObjects.discover.getHitCount() --- .../feature_controls/discover_security.ts | 24 +++++++++---------- .../feature_controls/discover_spaces.ts | 13 +++++----- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts index 2004bba5d6812..450c2079ce877 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts @@ -185,13 +185,12 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { it(`doesn't show visualize button`, async () => { await PageObjects.common.navigateToApp('discover'); + await setDiscoverTimeRange(); await retry.try(async () => { - await setDiscoverTimeRange(); - const hasNoResults = await PageObjects.discover.hasNoResults(); - expect(hasNoResults).to.be(false); - + const hitCount = await PageObjects.discover.getHitCount(); + expect(parseInt(hitCount, 10)).to.be.greaterThan(0); await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); + await PageObjects.discover.expectFieldListItemVisualize('bytes'); }); }); @@ -279,12 +278,12 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { it(`doesn't show visualize button`, async () => { await PageObjects.common.navigateToApp('discover'); + await setDiscoverTimeRange(); await retry.try(async () => { - await setDiscoverTimeRange(); - const hasNoResults = await PageObjects.discover.hasNoResults(); - expect(hasNoResults).to.be(false); + const hitCount = await PageObjects.discover.getHitCount(); + expect(parseInt(hitCount, 10)).to.be.greaterThan(0); await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); + await PageObjects.discover.expectFieldListItemVisualize('bytes'); }); }); @@ -360,11 +359,10 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { it(`shows the visualize button`, async () => { await PageObjects.common.navigateToApp('discover'); + await setDiscoverTimeRange(); await retry.try(async () => { - await setDiscoverTimeRange(); - const hasNoResults = await PageObjects.discover.hasNoResults(); - expect(hasNoResults).to.be(false); - + const hitCount = await PageObjects.discover.getHitCount(); + expect(parseInt(hitCount, 10)).to.be.greaterThan(0); await PageObjects.discover.clickFieldListItem('bytes'); await PageObjects.discover.expectFieldListItemVisualize('bytes'); }); diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts index 0b0ca2e15b9dd..effdce4f9deb6 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts @@ -68,11 +68,10 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { await PageObjects.common.navigateToApp('discover', { basePath: '/s/custom_space', }); + await setDiscoverTimeRange(); await retry.try(async () => { - await setDiscoverTimeRange(); - const hasNoResults = await PageObjects.discover.hasNoResults(); - expect(hasNoResults).to.be(false); - + const hitCount = await PageObjects.discover.getHitCount(); + expect(parseInt(hitCount, 10)).to.be.greaterThan(0); await PageObjects.discover.clickFieldListItem('bytes'); await PageObjects.discover.expectFieldListItemVisualize('bytes'); }); @@ -139,10 +138,10 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { await PageObjects.common.navigateToApp('discover', { basePath: '/s/custom_space', }); + await setDiscoverTimeRange(); await retry.try(async () => { - await setDiscoverTimeRange(); - const hasNoResults = await PageObjects.discover.hasNoResults(); - expect(hasNoResults).to.be(false); + const hitCount = await PageObjects.discover.getHitCount(); + expect(parseInt(hitCount, 10)).to.be.greaterThan(0); await PageObjects.discover.clickFieldListItem('bytes'); await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); }); From 8cff5efdfe7cee2e67fc7046856bccfcd9d2e771 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Thu, 16 Apr 2020 14:10:41 +0200 Subject: [PATCH 12/19] fix tests that expect the visualize button not to exist --- .../apps/discover/feature_controls/discover_security.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts index 450c2079ce877..68ef0b4b150e9 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts @@ -190,7 +190,7 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { const hitCount = await PageObjects.discover.getHitCount(); expect(parseInt(hitCount, 10)).to.be.greaterThan(0); await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectFieldListItemVisualize('bytes'); + await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); }); }); @@ -283,7 +283,7 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { const hitCount = await PageObjects.discover.getHitCount(); expect(parseInt(hitCount, 10)).to.be.greaterThan(0); await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectFieldListItemVisualize('bytes'); + await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); }); }); From 1a368b3222d70342d3c679f34f9f6c847cb53f7f Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Fri, 17 Apr 2020 10:39:27 +0200 Subject: [PATCH 13/19] Add debugging --- .../apps/discover/feature_controls/discover_security.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts index 68ef0b4b150e9..ded4b2021dbfc 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts @@ -12,6 +12,7 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { const security = getService('security'); const globalNav = getService('globalNav'); const config = getService('config'); + const log = getService('log'); const PageObjects = getPageObjects([ 'common', 'discover', @@ -185,9 +186,11 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { it(`doesn't show visualize button`, async () => { await PageObjects.common.navigateToApp('discover'); + await PageObjects.common.sleep(500); await setDiscoverTimeRange(); await retry.try(async () => { const hitCount = await PageObjects.discover.getHitCount(); + log.debug('doesnt show visualize button: hit count', hitCount); expect(parseInt(hitCount, 10)).to.be.greaterThan(0); await PageObjects.discover.clickFieldListItem('bytes'); await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); @@ -278,9 +281,11 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { it(`doesn't show visualize button`, async () => { await PageObjects.common.navigateToApp('discover'); + await PageObjects.common.sleep(500); await setDiscoverTimeRange(); await retry.try(async () => { const hitCount = await PageObjects.discover.getHitCount(); + log.debug('doesnt show visualize button: hit count', hitCount); expect(parseInt(hitCount, 10)).to.be.greaterThan(0); await PageObjects.discover.clickFieldListItem('bytes'); await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); From 49974e43f9296093c1bdf9a8f78c5d7ca438f8ce Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Fri, 17 Apr 2020 20:29:08 +0200 Subject: [PATCH 14/19] Increase waitForCompletionTimeout to 5s --- .../plugins/data_enhanced/server/search/es_search_strategy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts index 6b329bccab4a7..9bdd029d79c3a 100644 --- a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts @@ -69,7 +69,7 @@ async function asyncSearch( const path = encodeURI(request.id ? `/_async_search/${request.id}` : `/${index}/_async_search`); // Wait up to 1s for the response to return - const query = toSnakeCase({ waitForCompletionTimeout: '1s', ...queryParams }); + const query = toSnakeCase({ waitForCompletionTimeout: '5s', ...queryParams }); const { response, id } = (await caller( 'transport.request', From cc76e78b87f8c4f81d543629af464ae0a7abd871 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Sat, 18 Apr 2020 11:21:40 +0200 Subject: [PATCH 15/19] Undo test adaptions --- .../feature_controls/discover_security.ts | 30 ++++--------------- .../feature_controls/discover_spaces.ts | 17 +++-------- 2 files changed, 10 insertions(+), 37 deletions(-) diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts index ded4b2021dbfc..76ca613af4b55 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_security.ts @@ -8,11 +8,9 @@ import { FtrProviderContext } from '../../../ftr_provider_context'; export default function({ getPageObjects, getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); - const retry = getService('retry'); const security = getService('security'); const globalNav = getService('globalNav'); const config = getService('config'); - const log = getService('log'); const PageObjects = getPageObjects([ 'common', 'discover', @@ -186,15 +184,9 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { it(`doesn't show visualize button`, async () => { await PageObjects.common.navigateToApp('discover'); - await PageObjects.common.sleep(500); await setDiscoverTimeRange(); - await retry.try(async () => { - const hitCount = await PageObjects.discover.getHitCount(); - log.debug('doesnt show visualize button: hit count', hitCount); - expect(parseInt(hitCount, 10)).to.be.greaterThan(0); - await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); - }); + await PageObjects.discover.clickFieldListItem('bytes'); + await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); }); it(`Permalinks doesn't show create short-url button`, async () => { @@ -281,15 +273,9 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { it(`doesn't show visualize button`, async () => { await PageObjects.common.navigateToApp('discover'); - await PageObjects.common.sleep(500); await setDiscoverTimeRange(); - await retry.try(async () => { - const hitCount = await PageObjects.discover.getHitCount(); - log.debug('doesnt show visualize button: hit count', hitCount); - expect(parseInt(hitCount, 10)).to.be.greaterThan(0); - await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); - }); + await PageObjects.discover.clickFieldListItem('bytes'); + await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); }); it('Permalinks shows create short-url button', async () => { @@ -365,12 +351,8 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { it(`shows the visualize button`, async () => { await PageObjects.common.navigateToApp('discover'); await setDiscoverTimeRange(); - await retry.try(async () => { - const hitCount = await PageObjects.discover.getHitCount(); - expect(parseInt(hitCount, 10)).to.be.greaterThan(0); - await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectFieldListItemVisualize('bytes'); - }); + await PageObjects.discover.clickFieldListItem('bytes'); + await PageObjects.discover.expectFieldListItemVisualize('bytes'); }); }); diff --git a/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts b/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts index effdce4f9deb6..4bedc757f0b57 100644 --- a/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts +++ b/x-pack/test/functional/apps/discover/feature_controls/discover_spaces.ts @@ -10,7 +10,6 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { const esArchiver = getService('esArchiver'); const config = getService('config'); const spacesService = getService('spaces'); - const retry = getService('retry'); const PageObjects = getPageObjects([ 'common', 'discover', @@ -69,12 +68,8 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { basePath: '/s/custom_space', }); await setDiscoverTimeRange(); - await retry.try(async () => { - const hitCount = await PageObjects.discover.getHitCount(); - expect(parseInt(hitCount, 10)).to.be.greaterThan(0); - await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectFieldListItemVisualize('bytes'); - }); + await PageObjects.discover.clickFieldListItem('bytes'); + await PageObjects.discover.expectFieldListItemVisualize('bytes'); }); }); @@ -139,12 +134,8 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { basePath: '/s/custom_space', }); await setDiscoverTimeRange(); - await retry.try(async () => { - const hitCount = await PageObjects.discover.getHitCount(); - expect(parseInt(hitCount, 10)).to.be.greaterThan(0); - await PageObjects.discover.clickFieldListItem('bytes'); - await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); - }); + await PageObjects.discover.clickFieldListItem('bytes'); + await PageObjects.discover.expectMissingFieldListItemVisualize('bytes'); }); }); From 19864111d9d3eebb64538f985eb35337331d4d34 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Wed, 22 Apr 2020 07:48:50 +0200 Subject: [PATCH 16/19] Modify async search code --- .../data_enhanced/public/search/async_search_strategy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts b/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts index 6271d7fcbeaac..da963500d9568 100644 --- a/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts @@ -54,7 +54,7 @@ export const asyncSearchStrategyProvider: TSearchStrategyProvider { // If the response indicates it is complete, stop polling and complete the observable - if ((response.loaded ?? 0) >= (response.total ?? 0)) return EMPTY; + if (response.is_partial === false) return EMPTY; id = response.id; From 51f52bc7adbbfb994907437fdf17c58720c690d5 Mon Sep 17 00:00:00 2001 From: Matthias Wilhelm Date: Wed, 22 Apr 2020 07:59:42 +0200 Subject: [PATCH 17/19] undo wait for completion timeout setting too 5s --- .../plugins/data_enhanced/server/search/es_search_strategy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts index 9bdd029d79c3a..6b329bccab4a7 100644 --- a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts @@ -69,7 +69,7 @@ async function asyncSearch( const path = encodeURI(request.id ? `/_async_search/${request.id}` : `/${index}/_async_search`); // Wait up to 1s for the response to return - const query = toSnakeCase({ waitForCompletionTimeout: '5s', ...queryParams }); + const query = toSnakeCase({ waitForCompletionTimeout: '1s', ...queryParams }); const { response, id } = (await caller( 'transport.request', From ba1dbbf6c0aa2a8cceb3bdae2f6c559bf64f134e Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 22 Apr 2020 13:18:42 +0300 Subject: [PATCH 18/19] resolves #64132 --- .../public/search/async_search_strategy.ts | 7 ++++++- .../server/search/es_search_strategy.ts | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts b/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts index 6271d7fcbeaac..79aac270b8280 100644 --- a/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts @@ -53,8 +53,13 @@ export const asyncSearchStrategyProvider: TSearchStrategyProvider { + // If the response indicates of an error, stop polling and complete the observable + if (!response || (response.is_partial && !response.is_running)) { + return throwError(new AbortError()); + } + // If the response indicates it is complete, stop polling and complete the observable - if ((response.loaded ?? 0) >= (response.total ?? 0)) return EMPTY; + if (!response.is_partial && !response.is_running) return EMPTY; id = response.id; diff --git a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts index 6b329bccab4a7..bf502889ffa4f 100644 --- a/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/server/search/es_search_strategy.ts @@ -23,6 +23,8 @@ import { shimHitsTotal } from './shim_hits_total'; export interface AsyncSearchResponse { id: string; + is_partial: boolean; + is_running: boolean; response: SearchResponse; } @@ -71,13 +73,19 @@ async function asyncSearch( // Wait up to 1s for the response to return const query = toSnakeCase({ waitForCompletionTimeout: '1s', ...queryParams }); - const { response, id } = (await caller( + const { id, response, is_partial, is_running } = (await caller( 'transport.request', { method, path, body, query }, options )) as AsyncSearchResponse; - return { id, rawResponse: shimHitsTotal(response), ...getTotalLoaded(response._shards) }; + return { + id, + is_partial, + is_running, + rawResponse: shimHitsTotal(response), + ...getTotalLoaded(response._shards), + }; } async function rollupSearch( From c6688fbfa4d3a71f0ed01a005c10a275ed6bdb47 Mon Sep 17 00:00:00 2001 From: Liza K Date: Wed, 22 Apr 2020 13:24:29 +0300 Subject: [PATCH 19/19] simplify condition --- .../data_enhanced/public/search/async_search_strategy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts b/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts index 79aac270b8280..32968a9e54fe9 100644 --- a/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts +++ b/x-pack/plugins/data_enhanced/public/search/async_search_strategy.ts @@ -59,7 +59,7 @@ export const asyncSearchStrategyProvider: TSearchStrategyProvider