diff --git a/test/functional/apps/discover/ccs_compatibility/_search_errors.ts b/test/functional/apps/discover/ccs_compatibility/_search_errors.ts new file mode 100644 index 0000000000000..da2d2b5567341 --- /dev/null +++ b/test/functional/apps/discover/ccs_compatibility/_search_errors.ts @@ -0,0 +1,101 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import expect from '@kbn/expect'; +import { FtrProviderContext } from '../ftr_provider_context'; + +export default function ({ getService, getPageObjects }: FtrProviderContext) { + const config = getService('config'); + const filterBar = getService('filterBar'); + const kibanaServer = getService('kibanaServer'); + const retry = getService('retry'); + const testSubjects = getService('testSubjects'); + const PageObjects = getPageObjects(['common', 'discover', 'header', 'timePicker']); + + const isCcsTest = config.get('esTestCluster.ccs'); + const archiveDirectory = isCcsTest + ? 'test/functional/fixtures/kbn_archiver/ccs/discover.json' + : 'test/functional/fixtures/kbn_archiver/discover.json'; + const esNode = isCcsTest + ? getService('remoteEsArchiver' as 'esArchiver') + : getService('esArchiver'); + + const defaultIndex = isCcsTest ? 'ftr-remote:logstash-*' : 'logstash-*'; + + describe('discover search errors', () => { + before(async () => { + await kibanaServer.importExport.load(archiveDirectory); + await esNode.loadIfNeeded('test/functional/fixtures/es_archiver/logstash_functional'); + }); + + after(async () => { + await kibanaServer.importExport.unload(archiveDirectory); + await esNode.unload('test/functional/fixtures/es_archiver/logstash_functional'); + }); + + it('exception on single shard shows warning and results', async () => { + await PageObjects.common.navigateToApp('discover'); + await PageObjects.discover.selectIndexPattern(defaultIndex); + await PageObjects.timePicker.setDefaultAbsoluteRange(); + await retry.try(async () => { + const hitCount = await PageObjects.discover.getHitCount(); + expect(hitCount).to.be('14,004'); + }); + await filterBar.addDslFilter(` + { + "query": { + "error_query": { + "indices": [ + { + "name": "${defaultIndex.slice(0, defaultIndex.length - 1)}2015.09.20", + "error_type": "exception", + "message": "'Watch out!'" + } + ] + } + } + }`); + + // Ensure documents are still returned for the successful shards + await retry.try(async function tryingForTime() { + const hitCount = await PageObjects.discover.getHitCount(); + expect(hitCount).to.be('9,247'); + }); + + // Ensure a warning is shown + await testSubjects.exists('searchResponseWarningsCallout'); + }); + + it('exception on all shards shows error', async () => { + await PageObjects.common.navigateToApp('discover'); + await PageObjects.discover.selectIndexPattern(defaultIndex); + await PageObjects.timePicker.setDefaultAbsoluteRange(); + await retry.try(async () => { + const hitCount = await PageObjects.discover.getHitCount(); + expect(hitCount).to.be('14,004'); + }); + await filterBar.addDslFilter(` + { + "query": { + "error_query": { + "indices": [ + { + "name": "${defaultIndex}", + "error_type": "exception", + "message": "'Watch out!'" + } + ] + } + } + }`); + + // Ensure an error is shown + await testSubjects.exists('searchResponseWarningsEmptyPrompt'); + }); + }); +} diff --git a/test/functional/apps/discover/ccs_compatibility/index.ts b/test/functional/apps/discover/ccs_compatibility/index.ts index 1204ce9daadb2..4f932c3993831 100644 --- a/test/functional/apps/discover/ccs_compatibility/index.ts +++ b/test/functional/apps/discover/ccs_compatibility/index.ts @@ -22,5 +22,6 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./_data_view_editor')); loadTestFile(require.resolve('./_saved_queries')); + loadTestFile(require.resolve('./_search_errors')); }); } diff --git a/test/functional/services/filter_bar.ts b/test/functional/services/filter_bar.ts index 22fa4ff0b5e59..eb9aae45621e1 100644 --- a/test/functional/services/filter_bar.ts +++ b/test/functional/services/filter_bar.ts @@ -65,6 +65,7 @@ type Filter = FilterLeaf | FilterNode; export class FilterBarService extends FtrService { private readonly comboBox = this.ctx.getService('comboBox'); + private readonly monacoEditor = this.ctx.getService('monacoEditor'); private readonly testSubjects = this.ctx.getService('testSubjects'); private readonly common = this.ctx.getPageObject('common'); private readonly header = this.ctx.getPageObject('header'); @@ -315,6 +316,19 @@ export class FilterBarService extends FtrService { await this.addFilterAndSelectDataView(null, filter); } + public async addDslFilter(value: string) { + await this.testSubjects.click('addFilter'); + await this.testSubjects.click('editQueryDSL'); + await this.monacoEditor.waitCodeEditorReady('addFilterPopover'); + await this.monacoEditor.setCodeEditorValue(value); + await this.testSubjects.scrollIntoView('saveFilter'); + await this.testSubjects.clickWhenNotDisabled('saveFilter'); + await this.retry.try(async () => { + await this.testSubjects.waitForDeleted('saveFilter'); + }); + await this.header.waitUntilLoadingHasFinished(); + } + /** * Activates filter editing * @param key field name