Skip to content

Commit 5743d10

Browse files
authored
[Discover] Fix ES|QL embeddable without data view spec failing to load (#241217)
## Summary This PR fixes an issue where adding an ES|QL based Discover session without an ad hoc data view spec as a dashboard panel fails. Instead, it now checks for an ad hoc data view in ES|QL tabs, and generates one from the query if none exists (similar to Discover itself). Fixes #241218. ### Checklist - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [x] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels.
1 parent fa8c899 commit 5743d10

File tree

4 files changed

+108
-6
lines changed

4 files changed

+108
-6
lines changed

src/platform/plugins/shared/discover/public/embeddable/initialize_search_embeddable_api.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ import type { DiscoverGridSettings, SavedSearch } from '@kbn/saved-search-plugin
2424
import type { SortOrder, VIEW_MODE } from '@kbn/saved-search-plugin/public';
2525
import type { DataGridDensity, DataTableColumnsMeta } from '@kbn/unified-data-table';
2626

27-
import type { AggregateQuery, Filter, Query } from '@kbn/es-query';
27+
import {
28+
isOfAggregateQueryType,
29+
type AggregateQuery,
30+
type Filter,
31+
type Query,
32+
} from '@kbn/es-query';
2833
import type { DiscoverServices } from '../build_services';
2934
import { EDITABLE_SAVED_SEARCH_KEYS } from '../../common/embeddable/constants';
3035
import { getSearchEmbeddableDefaults } from './get_search_embeddable_defaults';
@@ -34,17 +39,25 @@ import type {
3439
SearchEmbeddableSerializedAttributes,
3540
SearchEmbeddableStateManager,
3641
} from './types';
42+
import { getEsqlDataView } from '../application/main/state_management/utils/get_esql_data_view';
3743

3844
const initializeSearchSource = async (
39-
dataService: DiscoverServices['data'],
45+
discoverServices: DiscoverServices,
4046
serializedSearchSource?: SerializedSearchSourceFields
4147
) => {
4248
const [searchSource, parentSearchSource] = await Promise.all([
43-
dataService.search.searchSource.create(serializedSearchSource),
44-
dataService.search.searchSource.create(),
49+
discoverServices.data.search.searchSource.create(serializedSearchSource),
50+
discoverServices.data.search.searchSource.create(),
4551
]);
52+
4653
searchSource.setParent(parentSearchSource);
47-
const dataView = searchSource.getField('index');
54+
55+
const query = searchSource.getField('query');
56+
let dataView = searchSource.getField('index');
57+
58+
if (isOfAggregateQueryType(query)) {
59+
dataView = await getEsqlDataView(query, dataView, discoverServices);
60+
}
4861

4962
return { searchSource, dataView };
5063
};
@@ -84,7 +97,7 @@ export const initializeSearchEmbeddableApi = async (
8497
}> => {
8598
/** We **must** have a search source, so start by initializing it */
8699
const { searchSource, dataView } = await initializeSearchSource(
87-
discoverServices.data,
100+
discoverServices,
88101
initialState.serializedSearchSource
89102
);
90103
const searchSource$ = new BehaviorSubject<ISearchSource>(searchSource);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import expect from '@kbn/expect';
11+
import type { FtrProviderContext } from '../ftr_provider_context';
12+
13+
export default function ({ getService, getPageObjects }: FtrProviderContext) {
14+
const dataGrid = getService('dataGrid');
15+
const dashboardAddPanel = getService('dashboardAddPanel');
16+
const filterBar = getService('filterBar');
17+
const esArchiver = getService('esArchiver');
18+
const kibanaServer = getService('kibanaServer');
19+
const { dashboard, header, timePicker } = getPageObjects(['dashboard', 'header', 'timePicker']);
20+
21+
describe('discover ES|QL embeddable', () => {
22+
before(async () => {
23+
await esArchiver.loadIfNeeded(
24+
'src/platform/test/functional/fixtures/es_archiver/logstash_functional'
25+
);
26+
await kibanaServer.importExport.load(
27+
'src/platform/test/functional/fixtures/kbn_archiver/discover'
28+
);
29+
await timePicker.setDefaultAbsoluteRangeViaUiSettings();
30+
});
31+
32+
after(async () => {
33+
await timePicker.resetDefaultAbsoluteRangeViaUiSettings();
34+
await kibanaServer.importExport.unload(
35+
'src/platform/test/functional/fixtures/kbn_archiver/discover'
36+
);
37+
await kibanaServer.savedObjects.cleanStandardList();
38+
});
39+
40+
beforeEach(async () => {
41+
await dashboard.navigateToApp();
42+
await filterBar.ensureFieldEditorModalIsClosed();
43+
await dashboard.gotoDashboardLandingPage();
44+
await dashboard.clickNewDashboard();
45+
});
46+
47+
it('should add an ES|QL based Discover session panel to a dashboard', async () => {
48+
await dashboardAddPanel.addSavedSearch('ES|QL Discover Session');
49+
await header.waitUntilLoadingHasFinished();
50+
await dashboard.waitForRenderComplete();
51+
await dashboard.verifyNoRenderErrors();
52+
expect(await dataGrid.getDocCount()).to.be(1000);
53+
});
54+
});
55+
}

src/platform/test/functional/apps/discover/embeddable/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
2727
loadTestFile(require.resolve('./_saved_search_embeddable'));
2828
loadTestFile(require.resolve('./multiple_data_views'));
2929
loadTestFile(require.resolve('./_log_stream_embeddable.ts'));
30+
loadTestFile(require.resolve('./_esql_embeddable.ts'));
3031
});
3132
}

src/platform/test/functional/fixtures/kbn_archiver/discover.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,36 @@
4949
"type": "search",
5050
"version": "WzUsMl0="
5151
}
52+
53+
{
54+
"id": "15ba60d9-a202-49f4-aabe-b9b97efe9a32",
55+
"type": "search",
56+
"version": "WzExLDFd",
57+
"attributes": {
58+
"title": "ES|QL Discover Session",
59+
"description": "ES|QL Discover Session Description",
60+
"tabs": [
61+
{
62+
"id": "c94f57e3-dc37-4a78-8f5b-17269f479b0e",
63+
"label": "Untitled",
64+
"attributes": {
65+
"columns": [],
66+
"isTextBasedQuery": true,
67+
"timeRestore": false,
68+
"kibanaSavedObjectMeta": {
69+
"searchSourceJSON": "{\"query\":{\"esql\":\"FROM logstash-* | SORT @timestamp desc | LIMIT 1000\"},\"filter\":[]}"
70+
},
71+
"sort": [
72+
[
73+
"@timestamp",
74+
"desc"
75+
]
76+
]
77+
}
78+
}
79+
]
80+
},
81+
"references": [],
82+
"coreMigrationVersion": "8.8.0",
83+
"typeMigrationVersion": "10.9.0"
84+
}

0 commit comments

Comments
 (0)