-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[ES|QL] Supports remote cluster lookup mode indices in the editor #232907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
97ab689
5b1a44a
294d6c2
720784c
26b0806
24ab502
469e015
2dd9d5a
cbf5403
ccbcaf5
22cf8fa
e6e40df
9a8d3ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,7 @@ interface EsqlPluginStartDependencies { | |
| } | ||
|
|
||
| export interface EsqlPluginStart { | ||
| getJoinIndicesAutocomplete: () => Promise<IndicesAutocompleteResult>; | ||
| getJoinIndicesAutocomplete: (remoteClusters?: string) => Promise<IndicesAutocompleteResult>; | ||
| getTimeseriesIndicesAutocomplete: () => Promise<IndicesAutocompleteResult>; | ||
| getInferenceEndpointsAutocomplete?: ( | ||
| taskType: InferenceTaskType | ||
|
|
@@ -106,14 +106,18 @@ export class EsqlPlugin implements Plugin<{}, EsqlPluginStart> { | |
|
|
||
| const variablesService = new EsqlVariablesService(); | ||
|
|
||
| const getJoinIndicesAutocomplete = cacheNonParametrizedAsyncFunction( | ||
| async () => { | ||
| const getJoinIndicesAutocomplete = cacheParametrizedAsyncFunction( | ||
| async (remoteClusters?: string) => { | ||
| const query = remoteClusters ? { remoteClusters } : {}; | ||
|
|
||
| const result = await core.http.get<IndicesAutocompleteResult>( | ||
| '/internal/esql/autocomplete/join/indices' | ||
| '/internal/esql/autocomplete/join/indices', | ||
| { query } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: why not do the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tbh I find it better like that. I wanted this function to be closer to what the api looks like. So I am thinking of it the opposite way you do. As this is a nit and a bit of a personal preference, do you mind if I keep it as it is?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't mind at all. That is why I approved :) |
||
| ); | ||
|
|
||
| return result; | ||
| }, | ||
| (remoteClusters?: string) => remoteClusters || '', | ||
| 1000 * 60 * 5, // Keep the value in cache for 5 minutes | ||
| 1000 * 15 // Refresh the cache in the background only if 15 seconds passed since the last call | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
| import { getListOfCCSIndices } from './utils'; | ||
| import type { IndexAutocompleteItem } from '@kbn/esql-types'; | ||
|
|
||
| describe('getListOfCCSIndices', () => { | ||
| const createLookupItem = (indexName: string, aliases?: string[]): IndexAutocompleteItem => ({ | ||
| name: indexName, | ||
| mode: 'lookup', | ||
| aliases: aliases || [], | ||
| }); | ||
|
|
||
| it('should return empty array when no clusters are provided', () => { | ||
| const clusters: string[] = []; | ||
| const lookupIndices = [ | ||
| createLookupItem('cluster1:index1'), | ||
| createLookupItem('cluster2:index2'), | ||
| ]; | ||
| const result = getListOfCCSIndices(clusters, lookupIndices); | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it('should return empty array when no lookup indices are provided', () => { | ||
| const clusters = ['cluster1', 'cluster2']; | ||
| const lookupIndices: IndexAutocompleteItem[] = []; | ||
| const result = getListOfCCSIndices(clusters, lookupIndices); | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it('should return empty array when no indices match the specified clusters', () => { | ||
| const clusters = ['cluster1', 'cluster2']; | ||
| const lookupIndices = [ | ||
| createLookupItem('cluster3:index1'), | ||
| createLookupItem('cluster4:index2'), | ||
| ]; | ||
| const result = getListOfCCSIndices(clusters, lookupIndices); | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it('should handle indices without cluster prefix', () => { | ||
| const clusters = ['cluster1']; | ||
| const lookupIndices = [ | ||
| createLookupItem('index1'), | ||
| createLookupItem('cluster1:index2'), | ||
| createLookupItem('index3'), | ||
| ]; | ||
| const result = getListOfCCSIndices(clusters, lookupIndices); | ||
| expect(result).toEqual([createLookupItem('index2')]); | ||
| }); | ||
|
|
||
| it('should handle multiple indices in the same cluster', () => { | ||
| const clusters = ['cluster1']; | ||
| const lookupIndices = [ | ||
| createLookupItem('cluster1:index1', ['alias1']), | ||
| createLookupItem('cluster1:index2'), | ||
| createLookupItem('cluster1:index3'), | ||
| ]; | ||
| const result = getListOfCCSIndices(clusters, lookupIndices); | ||
| expect(result).toEqual([ | ||
| createLookupItem('index1', ['alias1']), | ||
| createLookupItem('index2'), | ||
| createLookupItem('index3'), | ||
| ]); | ||
| }); | ||
|
|
||
| it('should return empty array when no common indices exist across all clusters', () => { | ||
| const clusters = ['cluster1', 'cluster2', 'cluster3']; | ||
| const lookupIndices = [ | ||
| createLookupItem('cluster1:index1'), | ||
| createLookupItem('cluster2:index2'), | ||
| createLookupItem('cluster3:index3'), | ||
| ]; | ||
| const result = getListOfCCSIndices(clusters, lookupIndices); | ||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it('should find common indices across multiple clusters', () => { | ||
| const clusters = ['cluster1', 'cluster2', 'cluster3']; | ||
| const lookupIndices = [ | ||
| createLookupItem('cluster1:index1', ['alias1']), | ||
| createLookupItem('cluster1:index2'), | ||
| createLookupItem('cluster2:index1', ['alias2']), | ||
| createLookupItem('cluster2:index3'), | ||
| createLookupItem('cluster3:index1', ['alias1']), // alias1 is duplicated to test Set uniqueness | ||
| createLookupItem('cluster3:index4'), | ||
| ]; | ||
| const result = getListOfCCSIndices(clusters, lookupIndices); | ||
| expect(result).toEqual([createLookupItem('index1', ['alias1', 'alias2'])]); | ||
| }); | ||
|
|
||
| it('should handle malformed cluster:index patterns', () => { | ||
| const clusters = ['cluster1']; | ||
| const lookupIndices = [ | ||
| createLookupItem('cluster1:'), | ||
| createLookupItem(':index1'), | ||
| createLookupItem('cluster1:index2'), | ||
| createLookupItem('notacluster'), | ||
| ]; | ||
| const result = getListOfCCSIndices(clusters, lookupIndices); | ||
| expect(result).toEqual([createLookupItem('index2')]); | ||
| }); | ||
|
|
||
| it('should handle indices with complex names containing special characters', () => { | ||
| const clusters = ['cluster1', 'cluster2']; | ||
| const lookupIndices = [ | ||
| createLookupItem('cluster1:logs-2023.01.01'), | ||
| createLookupItem('cluster1:metrics_system'), | ||
| createLookupItem('cluster2:logs-2023.01.01'), | ||
| createLookupItem('cluster2:traces.apm'), | ||
| ]; | ||
| const result = getListOfCCSIndices(clusters, lookupIndices); | ||
| expect(result).toEqual([createLookupItem('logs-2023.01.01')]); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ Moved them to sources_autocomplete as they make more sense there