-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[ES|QL] METRICS_INFO support: columns_after & summary #256758
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b7f6e71
adds metrics_info to registry with columns_after and summary
momovdg 5529adb
filters metrics_info only for TS source
momovdg 475bd86
filters commands after other commands
momovdg 4154010
adds tests
momovdg 4c66005
updates packages versions
momovdg 7efb129
updates packages versions
momovdg 3a719f6
review: renaming of property
momovdg 75ef6ff
review: removes constants.ts
momovdg 5c889c9
review: filter commands based on hiddenAfterCommands anywhere in the …
momovdg e141e3c
review: renaming in test
momovdg 5936fa7
review: fixes test
momovdg 816d6b2
Merge branch 'main' into esql-metrics-info
stratoula File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ackages/shared/kbn-esql-language/src/commands/registry/metrics_info/columns_after.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * 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 type { ESQLCommand } from '@elastic/esql/types'; | ||
| import type { ESQLColumnData } from '../types'; | ||
| import { columnsAfter } from './columns_after'; | ||
| import { METRICS_INFO_COLUMNS } from './columns_after'; | ||
|
|
||
| describe('METRICS_INFO > columnsAfter', () => { | ||
| const mockCommand = { name: 'metrics_info' } as ESQLCommand; | ||
|
|
||
| it('appends METRICS_INFO columns to previous columns', () => { | ||
| const previousColumns: ESQLColumnData[] = [ | ||
| { name: 'field1', type: 'keyword', userDefined: false }, | ||
| { name: 'field2', type: 'double', userDefined: false }, | ||
| ]; | ||
|
|
||
| const result = columnsAfter(mockCommand, previousColumns, ''); | ||
|
|
||
| expect(result).toEqual<ESQLColumnData[]>([ | ||
| { name: 'field1', type: 'keyword', userDefined: false }, | ||
| { name: 'field2', type: 'double', userDefined: false }, | ||
| ...METRICS_INFO_COLUMNS, | ||
| ]); | ||
| }); | ||
|
|
||
| it('returns only METRICS_INFO columns when previous columns is empty', () => { | ||
| const result = columnsAfter(mockCommand, [], ''); | ||
|
|
||
| expect(result).toEqual(METRICS_INFO_COLUMNS); | ||
| }); | ||
| }); |
28 changes: 28 additions & 0 deletions
28
...orm/packages/shared/kbn-esql-language/src/commands/registry/metrics_info/columns_after.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * 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 type { ESQLCommand } from '@elastic/esql/types'; | ||
| import type { ESQLColumnData } from '../types'; | ||
|
|
||
| export const METRICS_INFO_COLUMNS: ESQLColumnData[] = [ | ||
| { name: 'metric_name', type: 'keyword', userDefined: false }, | ||
| { name: 'data_stream', type: 'keyword', userDefined: false }, | ||
| { name: 'unit', type: 'keyword', userDefined: false }, | ||
| { name: 'metric_type', type: 'keyword', userDefined: false }, | ||
| { name: 'field_type', type: 'keyword', userDefined: false }, | ||
| { name: 'dimension_fields', type: 'keyword', userDefined: false }, | ||
| ]; | ||
|
|
||
| export const columnsAfter = ( | ||
| _command: ESQLCommand, | ||
| previousColumns: ESQLColumnData[], | ||
| _query: string | ||
| ): ESQLColumnData[] => { | ||
| return [...previousColumns, ...METRICS_INFO_COLUMNS]; | ||
| }; |
37 changes: 37 additions & 0 deletions
37
src/platform/packages/shared/kbn-esql-language/src/commands/registry/metrics_info/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * 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 { i18n } from '@kbn/i18n'; | ||
| import type { ICommand, ICommandMethods } from '../registry'; | ||
| import type { ICommandContext } from '../types'; | ||
| import { Commands } from '../../definitions/keywords'; | ||
| import { columnsAfter } from './columns_after'; | ||
| import { summary } from './summary'; | ||
|
|
||
| const metricsInfoCommandMethods: ICommandMethods<ICommandContext> = { | ||
| autocomplete: () => Promise.resolve([]), | ||
| columnsAfter, | ||
| summary, | ||
| }; | ||
|
|
||
| export const metricsInfoCommand: ICommand = { | ||
| name: Commands.METRICS_INFO, | ||
| methods: metricsInfoCommandMethods, | ||
| metadata: { | ||
| description: i18n.translate('kbn-esql-language.esql.definitions.metricsInfoDoc', { | ||
| defaultMessage: | ||
| 'The METRICS_INFO command returns information about the metrics in the query. Only available on TS commands.', | ||
| }), | ||
| declaration: 'METRICS_INFO', | ||
| examples: ['TS index | METRICS_INFO'], | ||
| preview: true, | ||
| requiresTimeseriesSource: true, | ||
| hiddenAfterCommands: [Commands.STATS, Commands.INLINE_STATS], | ||
| }, | ||
| }; |
31 changes: 31 additions & 0 deletions
31
...form/packages/shared/kbn-esql-language/src/commands/registry/metrics_info/summary.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * 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 type { ESQLCommand } from '@elastic/esql/types'; | ||
| import { summary } from './summary'; | ||
| import { METRICS_INFO_COLUMNS } from './columns_after'; | ||
|
|
||
| describe('METRICS_INFO > summary', () => { | ||
| const mockCommand = { name: 'metrics_info' } as ESQLCommand; | ||
|
|
||
| it('returns exactly the fixed set of metrics info columns', () => { | ||
| const result = summary(mockCommand); | ||
|
|
||
| expect(result.newColumns).toEqual(new Set(METRICS_INFO_COLUMNS.map((column) => column.name))); | ||
| }); | ||
|
|
||
| it('does not return renamedColumnsPairs, metadataColumns, aggregates, or grouping', () => { | ||
| const result = summary(mockCommand); | ||
|
|
||
| expect(result.renamedColumnsPairs).toBeUndefined(); | ||
| expect(result.metadataColumns).toBeUndefined(); | ||
| expect(result.aggregates).toBeUndefined(); | ||
| expect(result.grouping).toBeUndefined(); | ||
| }); | ||
| }); |
17 changes: 17 additions & 0 deletions
17
src/platform/packages/shared/kbn-esql-language/src/commands/registry/metrics_info/summary.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /* | ||
| * 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 type { ESQLCommand } from '@elastic/esql/types'; | ||
| import type { ESQLCommandSummary } from '../types'; | ||
| import { METRICS_INFO_COLUMNS } from './columns_after'; | ||
|
|
||
| export const summary = (_command: ESQLCommand): ESQLCommandSummary => { | ||
| const newColumns = METRICS_INFO_COLUMNS.map((column) => column.name); | ||
| return { newColumns: new Set(newColumns) }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You only check the last command, this means that
will suggest metrics info while it should not
This should make it work as we want
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.
fixed in 5c889c9