-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Obs ai assistant][ESQL] Visualizes a query #174677
Merged
stratoula
merged 52 commits into
elastic:main
from
stratoula:obs-ai-assistant-visualize-esql
Feb 5, 2024
Merged
Changes from 36 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
0548517
[Obs ai assistant][ESQL] Visualizes a query
stratoula 9132a88
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine a60baff
Make CI happy again
stratoula e90f370
Merge branch 'main' into obs-ai-assistant-visualize-esql
stratoula e59aa6c
Happy CI, happy life
stratoula ccbc3ae
Merge branch 'main' into obs-ai-assistant-visualize-esql
stratoula 09ff297
Make the assistant flyout work with the inline editing component
stratoula b6a37f1
Fixes jest test
stratoula 08bd3f4
Merge branch 'main' into obs-ai-assistant-visualize-esql
stratoula bba1b4e
Merge branch 'main' into obs-ai-assistant-visualize-esql
stratoula df0c56a
Add unit test in getAttributed function
stratoula 2016b6a
Minor tweaks
stratoula e7a171a
Cleanup
stratoula 704b8f5
More cleanup
stratoula 2bb0c06
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 5628842
Write some tests
stratoula 5e71490
Simplifications
stratoula 60a1d40
Merge branch 'main' into obs-ai-assistant-visualize-esql
stratoula 1b4e2da
Fix CI
stratoula c8b3896
Remove commented out code
stratoula b5fe67b
Merge branch 'main' into obs-ai-assistant-visualize-esql
stratoula e843fec
Address Pr comments
stratoula 84e26ff
Merge branch 'main' into obs-ai-assistant-visualize-esql
stratoula 6b01204
Merge with main and resolve conflicts
stratoula 4632fb1
Merge with main and resolve conflicts
stratoula cfcda31
Merge with main and resolve conflicts
stratoula ccd5810
[Obs AI Assistant] Correct executed ES|QL query
dgieselaar 536fce1
Merge branch 'obs-ai-assistant-execute-corrected' into obs-ai-assista…
dgieselaar 887603b
Extract and display preferred chart
dgieselaar 63ce42f
Fix the update visualization call
stratoula 2d1e844
Small fix on Visualize query CTA
stratoula d0cca57
Restore the execute_query function as AssistantOnly function for disp…
stratoula b1cd423
Merge with main and resolve conflicts
stratoula b9805c1
Rename esql to query function
dgieselaar cd4b939
Merge branch 'main' into obs-ai-assistant-visualize-esql
stratoula a72b140
Improving the variable name storing the lens overrides made by the user
stratoula 2c5bd3b
Update x-pack/plugins/observability_ai_assistant/server/functions/que…
stratoula 4547567
Merge branch 'main' into obs-ai-assistant-visualize-esql
stratoula 7894fbd
Integrate Conversation List and Edit Visualisation
CoenWarmer 4d69406
Merge branch 'obs-ai-assistant-visualize-esql' of https://github.com/…
CoenWarmer 029a531
Merge branch 'main' of github.com:elastic/kibana into obs-ai-assistan…
CoenWarmer f874e16
Fix import
CoenWarmer d76002e
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 2a13505
Clean translations
CoenWarmer dac6998
Merge branch 'obs-ai-assistant-visualize-esql' of https://github.com/…
CoenWarmer 98fc8da
Fix types
CoenWarmer 9f39185
Merge branch 'main' into obs-ai-assistant-visualize-esql
stratoula d79102c
Fix intl console warning
stratoula df07b85
Styling fixes
CoenWarmer 66924a0
Merge branch 'obs-ai-assistant-visualize-esql' of https://github.com/…
CoenWarmer 5705307
Make ui vis editor sidebar slightly wider
CoenWarmer 0d7c31b
Merge with main and resolve conflicts
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 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 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 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
134 changes: 134 additions & 0 deletions
134
packages/kbn-visualization-utils/__mocks__/suggestions_mock.ts
This file contains 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,134 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import type { TableChangeType } from '../src/types'; | ||
|
||
export const currentSuggestionMock = { | ||
title: 'Heat map', | ||
hide: false, | ||
score: 0.6, | ||
previewIcon: 'heatmap', | ||
visualizationId: 'lnsHeatmap', | ||
visualizationState: { | ||
shape: 'heatmap', | ||
layerId: '46aa21fa-b747-4543-bf90-0b40007c546d', | ||
layerType: 'data', | ||
legend: { | ||
isVisible: true, | ||
position: 'right', | ||
type: 'heatmap_legend', | ||
}, | ||
gridConfig: { | ||
type: 'heatmap_grid', | ||
isCellLabelVisible: false, | ||
isYAxisLabelVisible: true, | ||
isXAxisLabelVisible: true, | ||
isYAxisTitleVisible: false, | ||
isXAxisTitleVisible: false, | ||
}, | ||
valueAccessor: '5b9b8b76-0836-4a12-b9c0-980c9900502f', | ||
xAccessor: '81e332d6-ee37-42a8-a646-cea4fc75d2d3', | ||
}, | ||
keptLayerIds: ['46aa21fa-b747-4543-bf90-0b40007c546d'], | ||
datasourceState: { | ||
layers: { | ||
'46aa21fa-b747-4543-bf90-0b40007c546d': { | ||
index: 'd3d7af60-4c81-11e8-b3d7-01146121b73d', | ||
query: { | ||
esql: 'FROM kibana_sample_data_flights | keep Dest, AvgTicketPrice', | ||
}, | ||
columns: [ | ||
{ | ||
columnId: '81e332d6-ee37-42a8-a646-cea4fc75d2d3', | ||
fieldName: 'Dest', | ||
meta: { | ||
type: 'string', | ||
}, | ||
}, | ||
{ | ||
columnId: '5b9b8b76-0836-4a12-b9c0-980c9900502f', | ||
fieldName: 'AvgTicketPrice', | ||
meta: { | ||
type: 'number', | ||
}, | ||
}, | ||
], | ||
timeField: 'timestamp', | ||
}, | ||
}, | ||
indexPatternRefs: [], | ||
initialContext: { | ||
dataViewSpec: { | ||
id: 'd3d7af60-4c81-11e8-b3d7-01146121b73d', | ||
version: 'WzM1ODA3LDFd', | ||
title: 'kibana_sample_data_flights', | ||
timeFieldName: 'timestamp', | ||
sourceFilters: [], | ||
fields: { | ||
AvgTicketPrice: { | ||
count: 0, | ||
name: 'AvgTicketPrice', | ||
type: 'number', | ||
esTypes: ['float'], | ||
scripted: false, | ||
searchable: true, | ||
aggregatable: true, | ||
readFromDocValues: true, | ||
format: { | ||
id: 'number', | ||
params: { | ||
pattern: '$0,0.[00]', | ||
}, | ||
}, | ||
shortDotsEnable: false, | ||
isMapped: true, | ||
}, | ||
Dest: { | ||
count: 0, | ||
name: 'Dest', | ||
type: 'string', | ||
esTypes: ['keyword'], | ||
scripted: false, | ||
searchable: true, | ||
aggregatable: true, | ||
readFromDocValues: true, | ||
format: { | ||
id: 'string', | ||
}, | ||
shortDotsEnable: false, | ||
isMapped: true, | ||
}, | ||
timestamp: { | ||
count: 0, | ||
name: 'timestamp', | ||
type: 'date', | ||
esTypes: ['date'], | ||
scripted: false, | ||
searchable: true, | ||
aggregatable: true, | ||
readFromDocValues: true, | ||
format: { | ||
id: 'date', | ||
}, | ||
shortDotsEnable: false, | ||
isMapped: true, | ||
}, | ||
}, | ||
allowNoIndex: false, | ||
name: 'Kibana Sample Data Flights', | ||
}, | ||
fieldName: '', | ||
contextualFields: ['Dest', 'AvgTicketPrice'], | ||
query: { | ||
esql: 'FROM "kibana_sample_data_flights"', | ||
}, | ||
}, | ||
}, | ||
datasourceId: 'textBased', | ||
columns: 2, | ||
changeType: 'initial' as TableChangeType, | ||
}; |
This file contains 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
50 changes: 50 additions & 0 deletions
50
packages/kbn-visualization-utils/src/get_lens_attributes.test.ts
This file contains 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,50 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { getLensAttributesFromSuggestion } from './get_lens_attributes'; | ||
import { AggregateQuery } from '@kbn/es-query'; | ||
import type { DataView } from '@kbn/data-views-plugin/public'; | ||
import { currentSuggestionMock } from '../__mocks__/suggestions_mock'; | ||
|
||
describe('getLensAttributesFromSuggestion', () => { | ||
const dataView = { | ||
id: `index-pattern-with-timefield-id`, | ||
title: `index-pattern-with-timefield-title`, | ||
fields: [], | ||
getFieldByName: jest.fn(), | ||
timeFieldName: '@timestamp', | ||
isPersisted: () => false, | ||
toSpec: () => ({}), | ||
} as unknown as DataView; | ||
const query: AggregateQuery = { esql: 'from foo | limit 10' }; | ||
|
||
it('should return correct attributes for given suggestion', () => { | ||
const lensAttrs = getLensAttributesFromSuggestion({ | ||
filters: [], | ||
query, | ||
dataView, | ||
suggestion: currentSuggestionMock, | ||
}); | ||
expect(lensAttrs).toEqual({ | ||
state: expect.objectContaining({ | ||
adHocDataViews: { | ||
'index-pattern-with-timefield-id': {}, | ||
}, | ||
}), | ||
references: [ | ||
{ | ||
id: 'index-pattern-with-timefield-id', | ||
name: 'textBasedLanguages-datasource-layer-suggestion', | ||
type: 'index-pattern', | ||
}, | ||
], | ||
title: currentSuggestionMock.title, | ||
visualizationType: 'lnsHeatmap', | ||
}); | ||
}); | ||
}); |
64 changes: 64 additions & 0 deletions
64
packages/kbn-visualization-utils/src/get_lens_attributes.ts
This file contains 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,64 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import { i18n } from '@kbn/i18n'; | ||
import type { DataView } from '@kbn/data-views-plugin/public'; | ||
import type { AggregateQuery, Query, Filter } from '@kbn/es-query'; | ||
import type { Suggestion } from './types'; | ||
|
||
export const getLensAttributesFromSuggestion = ({ | ||
filters, | ||
query, | ||
suggestion, | ||
dataView, | ||
}: { | ||
filters: Filter[]; | ||
query: Query | AggregateQuery; | ||
suggestion: Suggestion | undefined; | ||
dataView?: DataView; | ||
}) => { | ||
const suggestionDatasourceState = Object.assign({}, suggestion?.datasourceState); | ||
const suggestionVisualizationState = Object.assign({}, suggestion?.visualizationState); | ||
const datasourceStates = | ||
suggestion && suggestion.datasourceState | ||
? { | ||
[suggestion.datasourceId!]: { | ||
...suggestionDatasourceState, | ||
}, | ||
} | ||
: { | ||
formBased: {}, | ||
}; | ||
const visualization = suggestionVisualizationState; | ||
const attributes = { | ||
title: suggestion | ||
? suggestion.title | ||
: i18n.translate('visualizationUtils.config.suggestion.title', { | ||
defaultMessage: 'New suggestion', | ||
}), | ||
references: [ | ||
{ | ||
id: dataView?.id ?? '', | ||
name: `textBasedLanguages-datasource-layer-suggestion`, | ||
type: 'index-pattern', | ||
}, | ||
], | ||
state: { | ||
datasourceStates, | ||
filters, | ||
query, | ||
visualization, | ||
...(dataView && | ||
dataView.id && | ||
!dataView.isPersisted() && { | ||
adHocDataViews: { [dataView.id]: dataView.toSpec(false) }, | ||
}), | ||
}, | ||
visualizationType: suggestion ? suggestion.visualizationId : 'lnsXY', | ||
}; | ||
return attributes; | ||
}; |
This file contains 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,43 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import type { Ast } from '@kbn/interpreter'; | ||
import type { IconType } from '@elastic/eui/src/components/icon/icon'; | ||
|
||
/** | ||
* Indicates what was changed in this table compared to the currently active table of this layer. | ||
* * `initial` means the layer associated with this table does not exist in the current configuration | ||
* * `unchanged` means the table is the same in the currently active configuration | ||
* * `reduced` means the table is a reduced version of the currently active table (some columns dropped, but not all of them) | ||
* * `extended` means the table is an extended version of the currently active table (added one or multiple additional columns) | ||
* * `reorder` means the table columns have changed order, which change the data as well | ||
* * `layers` means the change is a change to the layer structure, not to the table | ||
*/ | ||
export type TableChangeType = | ||
| 'initial' | ||
| 'unchanged' | ||
| 'reduced' | ||
| 'extended' | ||
| 'reorder' | ||
| 'layers'; | ||
|
||
export interface Suggestion<T = unknown, V = unknown> { | ||
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. ℹ️ Same as above. This can be reused in Lens and unified-histogram but I will do it on a follow up PR |
||
visualizationId: string; | ||
datasourceState?: V; | ||
datasourceId?: string; | ||
columns: number; | ||
score: number; | ||
title: string; | ||
visualizationState: T; | ||
previewExpression?: Ast | string; | ||
previewIcon: IconType; | ||
hide?: boolean; | ||
// flag to indicate if the visualization is incomplete | ||
incomplete?: boolean; | ||
changeType: TableChangeType; | ||
keptLayerIds: string[]; | ||
} |
This file contains 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.
ℹ️ I can reuse it in Lens but I will do it on a follow up PR. I moved it on the package because othwerise it creates circular dependencies.