Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/platform/packages/private/kbn-esql-editor/src/esql_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
monaco,
type ESQLCallbacks,
} from '@kbn/monaco';
import type { ILicense } from '@kbn/licensing-plugin/public';
import memoize from 'lodash/memoize';
import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { fixESQLQueryWithVariables } from '@kbn/esql-utils';
Expand Down Expand Up @@ -161,6 +162,7 @@ export const ESQLEditor = memo(function ESQLEditor({
const [isCodeEditorExpandedFocused, setIsCodeEditorExpandedFocused] = useState(false);
const [isQueryLoading, setIsQueryLoading] = useState(true);
const [abortController, setAbortController] = useState(new AbortController());
const [license, setLicense] = useState<ILicense | undefined>(undefined);

// contains both client side validation and server messages
const [editorMessages, setEditorMessages] = useState<{
Expand Down Expand Up @@ -443,7 +445,7 @@ export const ESQLEditor = memo(function ESQLEditor({
}, []);

const { cache: dataSourcesCache, memoizedSources } = useMemo(() => {
const fn = memoize((...args: [DataViewsPublicPluginStart, CoreStart]) => ({
const fn = memoize((...args: [DataViewsPublicPluginStart, CoreStart, boolean]) => ({
timestamp: Date.now(),
result: getESQLSources(...args),
}));
Expand All @@ -455,7 +457,9 @@ export const ESQLEditor = memo(function ESQLEditor({
const callbacks: ESQLCallbacks = {
getSources: async () => {
clearCacheWhenOld(dataSourcesCache, fixedQuery);
const sources = await memoizedSources(dataViews, core).result;
const ccrFeature = license?.getFeature('ccr');
const areRemoteIndicesAvailable = ccrFeature?.isAvailable ?? false;
const sources = await memoizedSources(dataViews, core, areRemoteIndicesAvailable).result;
return sources;
},
getColumnsFor: async ({ query: queryToExecute }: { query?: string } | undefined = {}) => {
Expand Down Expand Up @@ -517,6 +521,7 @@ export const ESQLEditor = memo(function ESQLEditor({
return callbacks;
}, [
fieldsMetadata,
license,
kibana.services?.esql?.getJoinIndicesAutocomplete,
dataSourcesCache,
fixedQuery,
Expand Down Expand Up @@ -593,6 +598,20 @@ export const ESQLEditor = memo(function ESQLEditor({
}
}, [isLoading, isQueryLoading, parseMessages, code]);

useEffect(() => {
async function fetchLicense() {
try {
const ls = await kibana.services?.esql?.getLicense();
if (!isEqual(license, ls)) {
setLicense(ls);
}
} catch (error) {
// failed to fetch
}
}
fetchLicense();
}, [kibana.services?.esql, license]);

const queryValidation = useCallback(
async ({ active }: { active: boolean }) => {
if (!editorModel.current || editorModel.current.isDisposed()) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,38 @@ describe('helpers', function () {
},
]),
};
const indices = await getRemoteIndicesList(updatedDataViewsMock);
const indices = await getRemoteIndicesList(updatedDataViewsMock, true);
expect(indices).toStrictEqual([{ name: 'remote:logs', hidden: false, type: 'Index' }]);
});

it('should not suggest ccs indices if not allowed', async function () {
const dataViewsMock = dataViewPluginMocks.createStartContract();
const updatedDataViewsMock = {
...dataViewsMock,
getIndices: jest.fn().mockResolvedValue([
{
name: 'remote: alias1',
item: {
indices: ['index1'],
},
},
{
name: 'remote:.system1',
item: {
name: 'system',
},
},
{
name: 'remote:logs',
item: {
name: 'logs',
timestamp_field: '@timestamp',
},
},
]),
};
const indices = await getRemoteIndicesList(updatedDataViewsMock, false);
expect(indices).toStrictEqual([]);
});
});
});
16 changes: 13 additions & 3 deletions src/platform/packages/private/kbn-esql-editor/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,13 @@ export const getIndicesList = async (dataViews: DataViewsPublicPluginStart) => {
});
};

export const getRemoteIndicesList = async (dataViews: DataViewsPublicPluginStart) => {
export const getRemoteIndicesList = async (
dataViews: DataViewsPublicPluginStart,
areRemoteIndicesAvailable: boolean
) => {
if (!areRemoteIndicesAvailable) {
return [];
}
const indices = await dataViews.getIndices({
showAllIndices: false,
pattern: '*:*',
Expand Down Expand Up @@ -255,9 +261,13 @@ const getIntegrations = async (core: CoreStart) => {
);
};

export const getESQLSources = async (dataViews: DataViewsPublicPluginStart, core: CoreStart) => {
export const getESQLSources = async (
dataViews: DataViewsPublicPluginStart,
core: CoreStart,
areRemoteIndicesAvailable: boolean
) => {
const [remoteIndices, localIndices, integrations] = await Promise.all([
getRemoteIndicesList(dataViews),
getRemoteIndicesList(dataViews, areRemoteIndicesAvailable),
getIndicesList(dataViews),
getIntegrations(core),
]);
Expand Down
2 changes: 2 additions & 0 deletions src/platform/packages/private/kbn-esql-editor/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type { AggregateQuery } from '@kbn/es-query';
import type { ExpressionsStart } from '@kbn/expressions-plugin/public';
import type { IndexManagementPluginSetup } from '@kbn/index-management-shared-types';
import type { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/public';
import type { ILicense } from '@kbn/licensing-plugin/public';
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';
Expand Down Expand Up @@ -107,6 +108,7 @@ interface ESQLVariableService {
export interface EsqlPluginStartBase {
getJoinIndicesAutocomplete: () => Promise<JoinIndicesAutocompleteResult>;
variablesService: ESQLVariableService;
getLicense: () => Promise<ILicense | undefined>;
}

export interface ESQLEditorDeps {
Expand Down
3 changes: 2 additions & 1 deletion src/platform/packages/private/kbn-esql-editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"@kbn/kibana-utils-plugin",
"@kbn/ui-actions-plugin",
"@kbn/shared-ux-table-persist",
"@kbn/esql-types"
"@kbn/esql-types",
"@kbn/licensing-plugin"
],
"exclude": [
"target/**/*",
Expand Down
3 changes: 2 additions & 1 deletion src/platform/plugins/shared/esql/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"optionalPlugins": [
"indexManagement",
"fieldsMetadata",
"usageCollection"
"usageCollection",
"licensing"
],
"requiredPlugins": [
"data",
Expand Down
4 changes: 4 additions & 0 deletions src/platform/plugins/shared/esql/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import type { Plugin, CoreStart, CoreSetup } from '@kbn/core/public';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import type { ExpressionsStart } from '@kbn/expressions-plugin/public';
import { LicensingPluginStart } from '@kbn/licensing-plugin/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { IndexManagementPluginSetup } from '@kbn/index-management-shared-types';
import type { UiActionsSetup, UiActionsStart } from '@kbn/ui-actions-plugin/public';
Expand Down Expand Up @@ -41,6 +42,7 @@ interface EsqlPluginStartDependencies {
uiActions: UiActionsStart;
data: DataPublicPluginStart;
fieldsMetadata: FieldsMetadataPublicStart;
licensing?: LicensingPluginStart;
usageCollection?: UsageCollectionStart;
}

Expand Down Expand Up @@ -70,6 +72,7 @@ export class EsqlPlugin implements Plugin<{}, EsqlPluginStart> {
uiActions,
fieldsMetadata,
usageCollection,
licensing,
}: EsqlPluginStartDependencies
): EsqlPluginStart {
const storage = new Storage(localStorage);
Expand Down Expand Up @@ -112,6 +115,7 @@ export class EsqlPlugin implements Plugin<{}, EsqlPluginStart> {
const start = {
getJoinIndicesAutocomplete,
variablesService,
getLicense: async () => await licensing?.getLicense(),
};

setKibanaServices(
Expand Down
1 change: 1 addition & 0 deletions src/platform/plugins/shared/esql/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@kbn/i18n-react",
"@kbn/visualization-utils",
"@kbn/esql-types",
"@kbn/licensing-plugin"
],
"exclude": [
"target/**/*",
Expand Down