mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
### Summary Refactoring general ui service (test helpers), to a kbn package. - Optimize methods and drop some code duplication. ### Why - Makes the service easily available from multiple code areas. - This is a preparation to potentially moving tests to plugins / packages, where they would no longer be able to import thing from test or x-pack/test but only from a package. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
162 lines
6.3 KiB
TypeScript
162 lines
6.3 KiB
TypeScript
/*
|
|
* 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 type { estypes } from '@elastic/elasticsearch';
|
|
import expect from '@kbn/expect';
|
|
import assert from 'assert';
|
|
import type { FtrProviderContext } from '../../functional/ftr_provider_context';
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|
const PageObjects = getPageObjects(['common', 'timePicker']);
|
|
const testSubjects = getService('testSubjects');
|
|
const retry = getService('retry');
|
|
const es = getService('es');
|
|
const log = getService('log');
|
|
const indexPatterns = getService('indexPatterns');
|
|
const comboBox = getService('comboBox');
|
|
const kibanaServer = getService('kibanaServer');
|
|
const esArchiver = getService('esArchiver');
|
|
const monacoEditor = getService('monacoEditor');
|
|
const toasts = getService('toasts');
|
|
|
|
describe('handling warnings with search source fetch', function () {
|
|
const dataViewTitle = 'sample-01,sample-01-rollup';
|
|
const fromTime = 'Jun 17, 2022 @ 00:00:00.000';
|
|
const toTime = 'Jun 23, 2022 @ 00:00:00.000';
|
|
const testArchive = 'test/functional/fixtures/es_archiver/search/downsampled';
|
|
const testIndex = 'sample-01';
|
|
const testRollupIndex = 'sample-01-rollup';
|
|
const testRollupField = 'kubernetes.container.memory.usage.bytes';
|
|
const shardFailureType = 'unsupported_aggregation_on_downsampled_index';
|
|
const shardFailureReason = `Field [${testRollupField}] of type [aggregate_metric_double] is not supported for aggregation [percentiles]`;
|
|
|
|
const getTestJson = async (tabTestSubj: string, codeTestSubj: string) => {
|
|
log.info(`switch to ${tabTestSubj} tab...`);
|
|
await testSubjects.click(tabTestSubj);
|
|
const block = await testSubjects.find(codeTestSubj);
|
|
const testText = (await block.getVisibleText()).trim();
|
|
return testText && JSON.parse(testText);
|
|
};
|
|
|
|
before(async () => {
|
|
// create rollup data
|
|
log.info(`loading ${testIndex} index...`);
|
|
await esArchiver.loadIfNeeded(testArchive);
|
|
log.info(`add write block to ${testIndex} index...`);
|
|
await es.indices.addBlock({ index: testIndex, block: 'write' });
|
|
try {
|
|
log.info(`rolling up ${testIndex} index...`);
|
|
// es client currently does not have method for downsample
|
|
await es.transport.request<void>({
|
|
method: 'POST',
|
|
path: '/sample-01/_downsample/sample-01-rollup',
|
|
body: { fixed_interval: '1h' },
|
|
});
|
|
} catch (err) {
|
|
log.info(`ignoring resource_already_exists_exception...`);
|
|
if (!err.message.match(/resource_already_exists_exception/)) {
|
|
throw err;
|
|
}
|
|
}
|
|
|
|
log.info(`creating ${dataViewTitle} data view...`);
|
|
await indexPatterns.create(
|
|
{
|
|
title: dataViewTitle,
|
|
timeFieldName: '@timestamp',
|
|
},
|
|
{ override: true }
|
|
);
|
|
await kibanaServer.uiSettings.update({
|
|
'dateFormat:tz': 'UTC',
|
|
defaultIndex: '0ae0bc7a-e4ca-405c-ab67-f2b5913f2a51',
|
|
'timepicker:timeDefaults': '{ "from": "now-1y", "to": "now" }',
|
|
});
|
|
|
|
await PageObjects.common.navigateToApp('searchExamples');
|
|
});
|
|
|
|
beforeEach(async () => {
|
|
await comboBox.setCustom('dataViewSelector', dataViewTitle);
|
|
await comboBox.set('searchMetricField', testRollupField);
|
|
await PageObjects.timePicker.setAbsoluteRange(fromTime, toTime);
|
|
});
|
|
|
|
after(async () => {
|
|
await es.indices.delete({ index: [testIndex, testRollupIndex] });
|
|
await kibanaServer.savedObjects.cleanStandardList();
|
|
await kibanaServer.uiSettings.replace({});
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await toasts.dismissAll();
|
|
});
|
|
|
|
it('should show search warnings as toasts', async () => {
|
|
await testSubjects.click('searchSourceWithOther');
|
|
|
|
await retry.try(async () => {
|
|
expect(await toasts.getCount()).to.be(2);
|
|
await testSubjects.click('viewWarningBtn');
|
|
});
|
|
|
|
// request
|
|
await retry.try(async () => {
|
|
await testSubjects.click('inspectorRequestDetailRequest');
|
|
const requestText = await monacoEditor.getCodeEditorValue(0);
|
|
expect(requestText).to.contain(testRollupField);
|
|
});
|
|
|
|
// response
|
|
await retry.try(async () => {
|
|
await testSubjects.click('inspectorRequestDetailResponse');
|
|
const responseText = await monacoEditor.getCodeEditorValue(0);
|
|
expect(responseText).to.contain(shardFailureReason);
|
|
});
|
|
|
|
await testSubjects.click('euiFlyoutCloseButton');
|
|
|
|
// wait for response - toasts appear before the response is rendered
|
|
let response: estypes.SearchResponse | undefined;
|
|
await retry.try(async () => {
|
|
response = await getTestJson('responseTab', 'responseCodeBlock');
|
|
expect(response).not.to.eql({});
|
|
});
|
|
|
|
// response tab
|
|
assert(response && response._shards.failures);
|
|
expect(response._shards.total).to.be(4);
|
|
expect(response._shards.successful).to.be(2);
|
|
expect(response._shards.skipped).to.be(0);
|
|
expect(response._shards.failed).to.be(2);
|
|
expect(response._shards.failures.length).to.equal(1);
|
|
expect(response._shards.failures[0].index).to.equal(testRollupIndex);
|
|
expect(response._shards.failures[0].reason.type).to.equal(shardFailureType);
|
|
expect(response._shards.failures[0].reason.reason).to.equal(shardFailureReason);
|
|
|
|
// warnings tab
|
|
const warnings = await getTestJson('warningsTab', 'warningsCodeBlock');
|
|
expect(warnings).to.eql([]);
|
|
});
|
|
|
|
it('should show search warnings in results tab', async () => {
|
|
await testSubjects.click('searchSourceWithoutOther');
|
|
|
|
// wait for toasts - toasts appear after the response is rendered
|
|
await retry.try(async () => {
|
|
expect(await toasts.getCount()).to.be(2);
|
|
});
|
|
|
|
// warnings tab
|
|
const warnings = await getTestJson('warningsTab', 'warningsCodeBlock');
|
|
expect(warnings.length).to.be(1);
|
|
expect(warnings[0].type).to.be('incomplete');
|
|
});
|
|
});
|
|
}
|