-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Discover Sessions as Code] Discover search embeddable: API schema, transforms, and feature flag #255213
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
lukasolson
merged 59 commits into
elastic:main
from
lukasolson:discover_sessions_as_code/embeddable_transforms
Apr 2, 2026
Merged
[Discover Sessions as Code] Discover search embeddable: API schema, transforms, and feature flag #255213
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
0afa3ac
Add SavedSearch ↔ simplified API transforms for session embeddable (#…
lukasolson 675fe97
Fix add panel from library
lukasolson f67109a
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 47f580b
time_range changes
lukasolson 3293434
Move view_mode to classic tab
lukasolson a4f4a6d
Add override state to schema, clean up transform utils
lukasolson 712e8b8
centralize search embeddable stored↔panel state transforms and use in…
lukasolson 6214f60
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 7ec6bd1
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson d7c23dc
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 6d19f55
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 17f1f40
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson bce00e7
fix(discover): align embeddable state with by-value / by-reference sc…
lukasolson 3e91d8d
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 901c75e
FIx logs stream embeddable
lukasolson fda13aa
Round trip test & fixes
lukasolson beca08c
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 43a83eb
Add feature flag
lukasolson ff5b701
Changes from node scripts/jest_integration -u src/core/server/integra…
kibanamachine 9329950
Changes from node scripts/lint_ts_projects --fix
kibanamachine 06da548
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine 08eba92
Fix type issues
lukasolson 5c69d6d
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 008fb9c
Move import back to discover-utils
lukasolson 1928dff
refactor(discover): clarify embeddable transforms for legacy vs sessi…
lukasolson 76111a3
Optimize bundle size
lukasolson 009cd19
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 83a7ce4
Actually register schema
lukasolson 418169b
Merge branch 'discover_sessions_as_code/embeddable_transforms' of git…
lukasolson 478bed2
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 90c8144
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson d7218be
Fix issue with save and return for by val
lukasolson 436519b
Add proper support for drilldown config
lukasolson 3369e73
Don't register schema if feature flag is turned off
lukasolson da4e44d
Separate into and for BWC
lukasolson c0bb2a5
Changes from node scripts/lint_ts_projects --fix
kibanamachine 28c80e5
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine bdbbed0
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 7dddca8
Merge branch 'discover_sessions_as_code/embeddable_transforms' of git…
lukasolson a49582d
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 56ff643
Use runtime field schema/transforms
lukasolson 78dff1c
shared as-code data_source schema and transforms
lukasolson f4f5af7
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 260694a
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 043f4f4
Add by-value/by-ref schema meta to Discover session embeddable schema
lukasolson 161041e
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson fde6325
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson 51c82b6
Merge branch 'discover_sessions_as_code/embeddable_transforms' of git…
lukasolson 0d17cd0
Review feedback
lukasolson daa82b8
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson b63f968
Review feedback part 2
lukasolson dfdb579
Merge branch 'discover_sessions_as_code/embeddable_transforms' of git…
lukasolson 86440d1
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson de337c1
Changes from node scripts/eslint_all_files --no-cache --fix
kibanamachine d379f27
Lower bundle size
lukasolson ffe5773
Merge branch 'discover_sessions_as_code/embeddable_transforms' of git…
lukasolson f17d1df
Fix types
lukasolson 0d55eca
Merge branch 'main' into discover_sessions_as_code/embeddable_transforms
lukasolson cfeaa92
Fix type check
lukasolson 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
14 changes: 14 additions & 0 deletions
14
src/platform/packages/shared/as-code/data-views-schema/src/constants.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,14 @@ | ||
| /* | ||
| * 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". | ||
| */ | ||
|
|
||
| /** `type` discriminator for as-code classic-tab `data_source`: saved Kibana data view id. */ | ||
| export const AS_CODE_DATA_VIEW_REFERENCE_TYPE = 'data_view_reference' as const; | ||
|
|
||
| /** `type` discriminator for as-code classic-tab `data_source`: inline DataViewSpec-shaped fields. */ | ||
| export const AS_CODE_DATA_VIEW_SPEC_TYPE = 'data_view_spec' as const; | ||
52 changes: 52 additions & 0 deletions
52
src/platform/packages/shared/as-code/data-views-schema/src/schema_data_view.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,52 @@ | ||
| /* | ||
| * 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 { schema } from '@kbn/config-schema'; | ||
| import { AS_CODE_DATA_VIEW_REFERENCE_TYPE, AS_CODE_DATA_VIEW_SPEC_TYPE } from './constants'; | ||
| import { runtimeFieldSchema } from './schema_runtime_field'; | ||
|
|
||
| export const dataViewReferenceSchema = schema.object( | ||
| { | ||
| type: schema.literal(AS_CODE_DATA_VIEW_REFERENCE_TYPE), | ||
| id: schema.string({ | ||
| meta: { | ||
| description: | ||
| 'The id of the Kibana data view to use as the data source. Example: "my-data-view".', | ||
| }, | ||
| }), | ||
| }, | ||
| { meta: { id: 'dataViewReferenceDataSourceTypeSchema' } } | ||
| ); | ||
|
|
||
| export const dataViewSpecSchema = schema.object( | ||
| { | ||
| type: schema.literal(AS_CODE_DATA_VIEW_SPEC_TYPE), | ||
| index_pattern: schema.string({ | ||
| meta: { | ||
| description: | ||
| 'The index pattern (Elasticsearch index expression) to use as the data source. Example: "my-index-*".', | ||
| }, | ||
| }), | ||
| time_field: schema.maybe( | ||
| schema.string({ | ||
| meta: { | ||
| description: | ||
| 'The name of the time field in the index. Used for time-based filtering. Example: "@timestamp".', | ||
| }, | ||
| }) | ||
| ), | ||
| runtime_fields: schema.maybe(schema.arrayOf(runtimeFieldSchema, { maxSize: 100 })), | ||
|
lukasolson marked this conversation as resolved.
|
||
| }, | ||
| { meta: { id: 'dataViewSpecDataSourceTypeSchema' } } | ||
| ); | ||
|
|
||
| export const dataViewSchema = schema.discriminatedUnion('type', [ | ||
| dataViewReferenceSchema, | ||
| dataViewSpecSchema, | ||
| ]); | ||
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
43 changes: 43 additions & 0 deletions
43
src/platform/packages/shared/as-code/data-views-transforms/src/from_stored_data_view.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,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", 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 { DataViewSpec } from '@kbn/data-views-plugin/common'; | ||
| import { | ||
| AS_CODE_DATA_VIEW_REFERENCE_TYPE, | ||
| AS_CODE_DATA_VIEW_SPEC_TYPE, | ||
| type AsCodeDataView, | ||
| } from '@kbn/as-code-data-views-schema'; | ||
| import { fromStoredRuntimeFields } from './from_stored_runtime_fields'; | ||
|
|
||
| /** | ||
| * Convert a stored search-source `index` value (saved object / serialized search source) | ||
| * to the as-code data view shape. | ||
| * | ||
| * @param index String id (referenced data view), inline {@link DataViewSpec}, or null/undefined | ||
| * @returns As-code `data_source` object for classic (KQL/Lucene) tabs | ||
| */ | ||
| export function fromStoredDataView( | ||
| index: string | DataViewSpec | null | undefined | ||
| ): AsCodeDataView { | ||
| if (!index) throw new Error('Cannot derive data view from empty index'); | ||
| if (typeof index === 'string') { | ||
| return { type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, id: index }; | ||
| } | ||
| if (!index.title) throw new Error('Cannot derive data view without `title` or `id`'); | ||
| return { | ||
| type: AS_CODE_DATA_VIEW_SPEC_TYPE, | ||
| index_pattern: index.title, | ||
| time_field: index.timeFieldName, | ||
| runtime_fields: fromStoredRuntimeFields( | ||
| index.runtimeFieldMap, | ||
| index.fieldFormats, | ||
| index.fieldAttrs | ||
| ), | ||
| }; | ||
| } |
73 changes: 73 additions & 0 deletions
73
src/platform/packages/shared/as-code/data-views-transforms/src/stored_data_source.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,73 @@ | ||
| /* | ||
| * 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 { | ||
| AS_CODE_DATA_VIEW_REFERENCE_TYPE, | ||
| AS_CODE_DATA_VIEW_SPEC_TYPE, | ||
| type AsCodeDataViewReference, | ||
| type AsCodeDataViewSpec, | ||
| } from '@kbn/as-code-data-views-schema'; | ||
| import { toStoredDataView } from './to_stored_data_view'; | ||
|
|
||
| describe('toStoredDataView', () => { | ||
| it('converts data_view_reference data_source to string id', () => { | ||
| const dataView: AsCodeDataViewReference = { | ||
| type: AS_CODE_DATA_VIEW_REFERENCE_TYPE, | ||
| id: 'my-data-view-id', | ||
| }; | ||
| const result = toStoredDataView(dataView); | ||
| expect(result).toBe('my-data-view-id'); | ||
| }); | ||
|
|
||
| it('converts index-pattern data_source to serialized index spec', () => { | ||
| const dataView: AsCodeDataViewSpec = { | ||
| type: AS_CODE_DATA_VIEW_SPEC_TYPE, | ||
| index_pattern: 'my-index-*', | ||
| time_field: '@timestamp', | ||
| runtime_fields: [ | ||
| { | ||
| name: 'rt', | ||
| type: 'keyword', | ||
| script: 'emit(doc["id"].value)', | ||
| format: { type: 'string' }, | ||
| }, | ||
| ], | ||
| }; | ||
| const result = toStoredDataView(dataView); | ||
| expect(result).toEqual({ | ||
| title: 'my-index-*', | ||
| timeFieldName: '@timestamp', | ||
| fieldFormats: { | ||
| rt: { id: 'string', params: undefined }, | ||
| }, | ||
| fieldAttrs: { | ||
| rt: {}, | ||
| }, | ||
| runtimeFieldMap: { | ||
| rt: { | ||
| type: 'keyword', | ||
| script: { source: 'emit(doc["id"].value)' }, | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('converts index-pattern data_source without runtime fields', () => { | ||
| const dataView: AsCodeDataViewSpec = { | ||
| type: AS_CODE_DATA_VIEW_SPEC_TYPE, | ||
| index_pattern: 'logs-*', | ||
| time_field: '@timestamp', | ||
| }; | ||
| const result = toStoredDataView(dataView); | ||
| expect(result).toEqual({ | ||
| title: 'logs-*', | ||
| timeFieldName: '@timestamp', | ||
| }); | ||
| }); | ||
| }); |
40 changes: 40 additions & 0 deletions
40
src/platform/packages/shared/as-code/data-views-transforms/src/to_stored_data_view.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,40 @@ | ||
| /* | ||
| * 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 { DataViewSpec } from '@kbn/data-views-plugin/common'; | ||
| import { | ||
| AS_CODE_DATA_VIEW_REFERENCE_TYPE, | ||
| type AsCodeDataView, | ||
| } from '@kbn/as-code-data-views-schema'; | ||
| import { | ||
| toStoredFieldAttributes, | ||
| toStoredFieldFormats, | ||
| toStoredRuntimeFields, | ||
| } from './to_stored_runtime_fields'; | ||
|
|
||
| /** | ||
| * Convert an as-code data view back to a stored search-source `index` value | ||
| * (string id for a referenced data view, or inline {@link DataViewSpec} fields). | ||
| * | ||
| * @param dataView As-code `data_source` value from classic tab state | ||
| * @returns Value suitable for `SerializedSearchSourceFields.index` | ||
| */ | ||
| export function toStoredDataView(dataView: AsCodeDataView): string | DataViewSpec { | ||
| if (dataView.type === AS_CODE_DATA_VIEW_REFERENCE_TYPE) return dataView.id; | ||
| const runtimeFieldMap = toStoredRuntimeFields(dataView.runtime_fields); | ||
| const fieldFormats = toStoredFieldFormats(dataView.runtime_fields); | ||
| const fieldAttrs = toStoredFieldAttributes(dataView.runtime_fields); | ||
| return { | ||
| title: dataView.index_pattern, | ||
| timeFieldName: dataView.time_field, | ||
| ...(runtimeFieldMap && Object.keys(runtimeFieldMap).length > 0 && { runtimeFieldMap }), | ||
| ...(fieldFormats && Object.keys(fieldFormats).length > 0 && { fieldFormats }), | ||
| ...(fieldAttrs && Object.keys(fieldAttrs).length > 0 && { fieldAttrs }), | ||
| }; | ||
| } |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.