[ES|QL] Apply the timerange to the fields fetch in the editor (#208490)

## Summary

Provides the timerange in the fetch fields api. This:

- fixes the bug where the fields are not suggested when there are system
named params such as `_tstart` and `_tend`
- makes it more performant as now it checks for fields in the selected
timerange making it more performant (especially for data in the frozen
tiers)

<img width="834" alt="image"
src="https://github.com/user-attachments/assets/ec0e6f87-3149-4a3f-a620-d7eab6a852a2"
/>
This commit is contained in:
Stratoula Kalafateli 2025-01-30 11:14:25 +01:00 committed by GitHub
parent 17e3f82bd2
commit a63781a5ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 21 additions and 5 deletions

View file

@ -17,6 +17,7 @@ import { ESQLEditor } from './esql_editor';
import type { ESQLEditorProps } from './types';
import { ReactWrapper } from 'enzyme';
import { coreMock } from '@kbn/core/server/mocks';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
describe('ESQLEditor', () => {
const uiConfig: Record<string, any> = {};
@ -30,6 +31,7 @@ describe('ESQLEditor', () => {
client: uiSettings,
},
core: coreMock.createStart(),
data: dataPluginMock.createStartContract(),
};
function renderESQLEditorComponent(testProps: ESQLEditorProps) {

View file

@ -23,7 +23,7 @@ import { isEqual } from 'lodash';
import { CodeEditor, CodeEditorProps } from '@kbn/code-editor';
import type { CoreStart } from '@kbn/core/public';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import type { AggregateQuery } from '@kbn/es-query';
import type { AggregateQuery, TimeRange } from '@kbn/es-query';
import type { ExpressionsStart } from '@kbn/expressions-plugin/public';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { ESQLLang, ESQL_LANG_ID, monaco, type ESQLCallbacks } from '@kbn/monaco';
@ -120,6 +120,7 @@ export const ESQLEditor = memo(function ESQLEditor({
fieldsMetadata,
uiSettings,
uiActions,
data,
} = kibana.services;
const variablesService = kibana.services?.esql?.variablesService;
@ -388,7 +389,7 @@ export const ESQLEditor = memo(function ESQLEditor({
const { cache: esqlFieldsCache, memoizedFieldsFromESQL } = useMemo(() => {
// need to store the timing of the first request so we can atomically clear the cache per query
const fn = memoize(
(...args: [{ esql: string }, ExpressionsStart, undefined, AbortController?]) => ({
(...args: [{ esql: string }, ExpressionsStart, TimeRange, AbortController?]) => ({
timestamp: Date.now(),
result: fetchFieldsFromESQL(...args),
}),
@ -422,11 +423,12 @@ export const ESQLEditor = memo(function ESQLEditor({
};
// Check if there's a stale entry and clear it
clearCacheWhenOld(esqlFieldsCache, esqlQuery.esql);
const timeRange = data.query.timefilter.timefilter.getTime();
try {
const table = await memoizedFieldsFromESQL(
esqlQuery,
expressions,
undefined,
timeRange,
abortController
).result;
const columns: ESQLRealField[] =
@ -470,19 +472,21 @@ export const ESQLEditor = memo(function ESQLEditor({
return callbacks;
}, [
fieldsMetadata,
kibana.services?.esql?.getJoinIndicesAutocomplete,
dataSourcesCache,
query.esql,
memoizedSources,
dataViews,
core,
esqlFieldsCache,
data.query.timefilter.timefilter,
memoizedFieldsFromESQL,
expressions,
abortController,
indexManagementApiService,
histogramBarTarget,
variablesService,
kibana.services?.esql?.getJoinIndicesAutocomplete,
variablesService?.esqlVariables,
variablesService?.areSuggestionsEnabled,
]);
const queryRunButtonProperties = useMemo(() => {

View file

@ -16,6 +16,7 @@ import type { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/publ
import type { UsageCollectionStart } from '@kbn/usage-collection-plugin/public';
import type { Storage } from '@kbn/kibana-utils-plugin/public';
import type { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { ESQLControlVariable } from '@kbn/esql-validation-autocomplete';
export interface ESQLEditorProps {
@ -112,6 +113,7 @@ export interface EsqlPluginStartBase {
export interface ESQLEditorDeps {
core: CoreStart;
dataViews: DataViewsPublicPluginStart;
data: DataPublicPluginStart;
expressions: ExpressionsStart;
storage: Storage;
uiActions: UiActionsStart;

View file

@ -14,6 +14,7 @@ import type { ExpressionsStart } from '@kbn/expressions-plugin/public';
import type { Storage } from '@kbn/kibana-utils-plugin/public';
import type { IndexManagementPluginSetup } from '@kbn/index-management-shared-types';
import type { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { UsageCollectionStart } from '@kbn/usage-collection-plugin/public';
import type { UiActionsStart } from '@kbn/ui-actions-plugin/public';
import type { EsqlPluginStart } from './plugin';
@ -23,6 +24,7 @@ export let core: CoreStart;
interface ServiceDeps {
core: CoreStart;
dataViews: DataViewsPublicPluginStart;
data: DataPublicPluginStart;
expressions: ExpressionsStart;
storage: Storage;
uiActions: UiActionsStart;
@ -49,6 +51,7 @@ export const setKibanaServices = (
esql: EsqlPluginStart,
kibanaCore: CoreStart,
dataViews: DataViewsPublicPluginStart,
data: DataPublicPluginStart,
expressions: ExpressionsStart,
storage: Storage,
uiActions: UiActionsStart,
@ -61,6 +64,7 @@ export const setKibanaServices = (
core,
dataViews,
expressions,
data,
storage,
uiActions,
indexManagementApiService: indexManagement?.apiService,

View file

@ -103,6 +103,7 @@ export class EsqlPlugin implements Plugin<{}, EsqlPluginStart> {
start,
core,
dataViews,
data,
expressions,
storage,
uiActions,

View file

@ -56,6 +56,7 @@ describe('ValueControlForm', () => {
client: uiSettings,
},
core: coreMock.createStart(),
data: dataMock,
};
describe('Interval type', () => {

View file

@ -7,6 +7,7 @@
import { setKibanaServices } from '@kbn/esql/public/kibana_services';
import { coreMock } from '@kbn/core/public/mocks';
import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { expressionsPluginMock } from '@kbn/expressions-plugin/public/mocks';
import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks';
import type { Storage } from '@kbn/kibana-utils-plugin/public';
@ -46,6 +47,7 @@ setKibanaServices(
},
coreMock.createStart(),
dataViewPluginMocks.createStartContract(),
dataPluginMock.createStartContract(),
expressionsPluginMock.createStartContract(),
storage,
uiActionsPluginMock.createStartContract()