Skip to content

[Lens] Update Lens CM and APIs#229534

Merged
nickofthyme merged 112 commits intoelastic:mainfrom
nickofthyme:lens-transforms-phase-1
Sep 6, 2025
Merged

[Lens] Update Lens CM and APIs#229534
nickofthyme merged 112 commits intoelastic:mainfrom
nickofthyme:lens-transforms-phase-1

Conversation

@nickofthyme
Copy link
Contributor

@nickofthyme nickofthyme commented Jul 26, 2025

Summary

Lens transforms Phase 1 - Foundation for Lens by-ref transforms.

Major Changes:

  • Overhauls the Lens Content Management to use schema-driven types
    • Defines rigid schema and types to be used inside CM.
    • Implement a working item transform based on the lens item version.
      • Applied runtime migrations (v0 to v1) on all necessary CRUD operations.
    • Attempts to isolate lens SO types to CM.
  • All Lens /public CRUD operations pass through API, no more CM public client. One exception is the mSearch used from visualizations plugin.
  • Refactors Lens API
    • Allow new API structure (i.e. data & meta) as to align with the dashboard API (see [Dashboards as code] Return meta information in API response #196609).
    • Stub out usage of different formats between API request/response types and the Lens CM Item.
    • Stubs out the Config Builder flow to convert the new API format to Lens item, and vise versa.
    • Use CM schemas to build out Lens route request and response schema
  • Refactor lens /public client to use new CRUD API
    • Need to patch a basic lens client for visualizations plugin to use for updating basic attributes.
    • Refactor lens client to new client consuming the Lens API instead of CM client.
    • Patch Lens item to conform to the LensDocument, the new client still expect the old LensDocument but converts the API format to pass to/from the server. The client does all the conversions.
    • Updates all usages of lens client to new client.
  • Rely on shared/common schema definitions whenever possible.
  • Change the visualize library client to use a basic client with only get and update methods.

Closes #225367

Checklist

  • Unit or functional tests were updated or added to match the most common scenarios
  • If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list
  • This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The release_note:breaking label should be applied in these situations.

- make accessible from /common
- fix reference.name schema misalignment
- add `createdBy` and `updatedBy` to the SO schema
- use generics on common schema functions to pass type correctly
- add schema for search result
- The `getContentClientFactory` required request but never uses it.
- Add `request` to `StorageContext` to pass to CM storage handlers
- This never checked if `mSearch` was available when creating the ctx.
- Check for `mSearch` before adding to ctx, log server warning if missing
- Add `logger` to `mSearch` factory
- We should allow transforms to run on unversioned items
- These version are not targets, they are only pulled up to the first version.
- allow using `kbn/object-versioning` in common.
- Vis type alias client only needs basic methods (i.e. `get` and `update`).
- Create a slim `BasicVisualizationClient`
- The basic client can use `cm` or `http`.
- update constants and use route schema
- update handling of API formats in and out of CM client
- This add CM transforms to convert existing lens items to v1
- Adds version number to lens SO attributes.
- Duplicates and tweaks runtime migrations for legend and color mappings.
- Refactor lens client to use new CRUD api instead of CM
- Create basic lens client using CM to use new API types
- Convert lens type alias client to use new basic client
- Update calls to lens client dependency to `http`
- Update lens doc service to use new lens client
- Update lens attribute service to use updated doc service
@nickofthyme nickofthyme added Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting labels Jul 26, 2025
@elastic elastic deleted a comment from elasticmachine Jul 27, 2025
Copy link
Contributor

@markov00 markov00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As previously discussed, you need to remove the isNewApiFormat before saving the config into the SO. Currently this is not done and that property is currently going to be stored into the SO.

qn895 pushed a commit to qn895/kibana that referenced this pull request Sep 2, 2025
## Summary

Changes to the `down` method type from elastic#153304, missed passing the
generic input type. Also fixes types on schema utility functions from
`@kbn/content-management-utils`.

I created elastic#231191 and a child
issues for CO teams to track and fix.

_Pulling this out of a larger PR, elastic#229534, to ease CO review._

### Checklist
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
@nickofthyme nickofthyme requested a review from markov00 September 3, 2025 16:14
Copy link
Contributor

@markov00 markov00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes looks good to me, addressed all my concerns

Copy link
Contributor

@AlexGPlay AlexGPlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data discovery changes lgtm

Copilot AI review requested due to automatic review settings September 4, 2025 23:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements Phase 1 of the Lens by-ref transforms foundation, introducing a comprehensive overhaul of the Lens Content Management system to use schema-driven types and establishing a new API structure aligned with the dashboard API.

Key changes include:

  • Complete restructuring of Lens Content Management to use strict schema-driven types with runtime migrations from v0 to v1
  • Introduction of new Lens CRUD API with data/meta structure format replacing direct CM client usage
  • Implementation of Config Builder stubs for API format transformations
  • Addition of comprehensive schema definitions and versioning system

Reviewed Changes

Copilot reviewed 141 out of 141 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
x-pack/platform/plugins/shared/lens/server/ Complete overhaul of server-side CM with new v1 schemas, transforms, and API routes
x-pack/platform/plugins/shared/lens/public/persistence/ Refactored client-side persistence layer with new LensClient and attribute service
x-pack/platform/test/api_integration/apis/lens/ Updated API integration tests to use new endpoint paths and response formats
x-pack/solutions/security/plugins/security_solution/public/ Removed deprecated type, updated_at, and version properties from Lens attributes
x-pack/platform/plugins/shared/lens/common/ Added new transform system, constants, and content management schemas

Copy link
Contributor

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saved objects changes LGTM.

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #94 / Observability AI Assistant Functional tests knowledge_base_management/index.spec.ts Knowledge management tab Bulk import knowledge base entries successfully imports multiple entries from a NDJSON file

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
lens 1410 1414 +4

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/content-management-utils 124 139 +15
lens 573 598 +25
total +40

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
dashboard 623.0KB 623.0KB +10.0B
discover 1.1MB 1.1MB +10.0B
eventAnnotationListing 204.5KB 204.6KB +10.0B
lens 1.5MB 1.5MB +177.0B
observabilityAIAssistantApp 177.7KB 177.7KB +10.0B
onechat 841.5KB 841.6KB +10.0B
securitySolution 10.3MB 10.3MB -284.0B
visualizations 351.4KB 351.5KB +27.0B
total -30.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
lens 58.9KB 60.9KB +2.0KB
Unknown metric groups

API count

id before after diff
@kbn/content-management-utils 191 206 +15
lens 672 697 +25
visualizations 869 870 +1
total +41

ESLint disabled line counts

id before after diff
lens 24 23 -1

Total ESLint disabled count

id before after diff
lens 24 23 -1

History

@nickofthyme nickofthyme merged commit 74c64ba into elastic:main Sep 6, 2025
12 checks passed
shahargl pushed a commit to shahargl/kibana that referenced this pull request Sep 7, 2025
## Summary

**Lens transforms Phase 1** - Foundation for Lens by-ref transforms.

Major Changes:
- Overhauls the Lens Content Management to use schema-driven types
  - Defines rigid schema and types to be used inside CM.
  - Implement a working item transform based on the lens item version.
- Applied runtime migrations (`v0` to `v1`) on all necessary CRUD
operations.
  - Attempts to isolate lens SO types to CM.
- All Lens /public CRUD operations pass through API, no more CM public
client. One exception is the `mSearch` used from visualizations plugin.
- Refactors Lens API
- Allow new API structure (i.e. `data` & `meta`) as to align with the
dashboard API (see elastic#196609).
- Stub out usage of different formats between API request/response types
and the Lens CM Item.
- Stubs out the Config Builder flow to convert the new API format to
Lens item, and vise versa.
  - Use CM schemas to build out Lens route request and response schema
- Refactor lens /public client to use new CRUD API
- Need to patch a basic lens client for visualizations plugin to use for
updating basic attributes.
- Refactor lens client to new client consuming the Lens API instead of
CM client.
- Patch Lens item to conform to the `LensDocument`, the new client still
expect the old `LensDocument` but converts the API format to pass
to/from the server. The client does all the conversions.
  - Updates all usages of lens client to new client.
- Rely on shared/common schema definitions whenever possible.
- Change the visualize library client to use a basic client with only
`get` and `update` methods.

Closes elastic#225367

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [x] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com>
KodeRad pushed a commit to KodeRad/kibana that referenced this pull request Sep 15, 2025
## Summary

**Lens transforms Phase 1** - Foundation for Lens by-ref transforms.

Major Changes:
- Overhauls the Lens Content Management to use schema-driven types
  - Defines rigid schema and types to be used inside CM.
  - Implement a working item transform based on the lens item version.
- Applied runtime migrations (`v0` to `v1`) on all necessary CRUD
operations.
  - Attempts to isolate lens SO types to CM.
- All Lens /public CRUD operations pass through API, no more CM public
client. One exception is the `mSearch` used from visualizations plugin.
- Refactors Lens API
- Allow new API structure (i.e. `data` & `meta`) as to align with the
dashboard API (see elastic#196609).
- Stub out usage of different formats between API request/response types
and the Lens CM Item.
- Stubs out the Config Builder flow to convert the new API format to
Lens item, and vise versa.
  - Use CM schemas to build out Lens route request and response schema
- Refactor lens /public client to use new CRUD API
- Need to patch a basic lens client for visualizations plugin to use for
updating basic attributes.
- Refactor lens client to new client consuming the Lens API instead of
CM client.
- Patch Lens item to conform to the `LensDocument`, the new client still
expect the old `LensDocument` but converts the API format to pass
to/from the server. The client does all the conversions.
  - Updates all usages of lens client to new client.
- Rely on shared/common schema definitions whenever possible.
- Change the visualize library client to use a basic client with only
`get` and `update` methods.

Closes elastic#225367

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [x] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Sep 24, 2025
## Summary

**Lens transforms Phase 1** - Foundation for Lens by-ref transforms.

Major Changes:
- Overhauls the Lens Content Management to use schema-driven types
  - Defines rigid schema and types to be used inside CM.
  - Implement a working item transform based on the lens item version.
- Applied runtime migrations (`v0` to `v1`) on all necessary CRUD
operations.
  - Attempts to isolate lens SO types to CM.
- All Lens /public CRUD operations pass through API, no more CM public
client. One exception is the `mSearch` used from visualizations plugin.
- Refactors Lens API
- Allow new API structure (i.e. `data` & `meta`) as to align with the
dashboard API (see elastic#196609).
- Stub out usage of different formats between API request/response types
and the Lens CM Item.
- Stubs out the Config Builder flow to convert the new API format to
Lens item, and vise versa.
  - Use CM schemas to build out Lens route request and response schema
- Refactor lens /public client to use new CRUD API
- Need to patch a basic lens client for visualizations plugin to use for
updating basic attributes.
- Refactor lens client to new client consuming the Lens API instead of
CM client.
- Patch Lens item to conform to the `LensDocument`, the new client still
expect the old `LensDocument` but converts the API format to pass
to/from the server. The client does all the conversions.
  - Updates all usages of lens client to new client.
- Rely on shared/common schema definitions whenever possible.
- Change the visualize library client to use a basic client with only
`get` and `update` methods.

Closes elastic#225367

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [x] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com>
niros1 pushed a commit that referenced this pull request Sep 30, 2025
## Summary

**Lens transforms Phase 1** - Foundation for Lens by-ref transforms.

Major Changes:
- Overhauls the Lens Content Management to use schema-driven types
  - Defines rigid schema and types to be used inside CM.
  - Implement a working item transform based on the lens item version.
- Applied runtime migrations (`v0` to `v1`) on all necessary CRUD
operations.
  - Attempts to isolate lens SO types to CM.
- All Lens /public CRUD operations pass through API, no more CM public
client. One exception is the `mSearch` used from visualizations plugin.
- Refactors Lens API
- Allow new API structure (i.e. `data` & `meta`) as to align with the
dashboard API (see #196609).
- Stub out usage of different formats between API request/response types
and the Lens CM Item.
- Stubs out the Config Builder flow to convert the new API format to
Lens item, and vise versa.
  - Use CM schemas to build out Lens route request and response schema
- Refactor lens /public client to use new CRUD API
- Need to patch a basic lens client for visualizations plugin to use for
updating basic attributes.
- Refactor lens client to new client consuming the Lens API instead of
CM client.
- Patch Lens item to conform to the `LensDocument`, the new client still
expect the old `LensDocument` but converts the API format to pass
to/from the server. The client does all the conversions.
  - Updates all usages of lens client to new client.
- Rely on shared/common schema definitions whenever possible.
- Change the visualize library client to use a basic client with only
`get` and `update` methods.

Closes #225367

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [x] This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Marco Vettorello <vettorello.marco@gmail.com>
mistic pushed a commit that referenced this pull request Nov 11, 2025
## Summary

Lens transforms Phase 2

### Changes

#### Integrate the Config Builder

This integrates the `LensConfigBuilder` into the full end-to-end flow of
all aspects of Lens including:
- Lens APIs (transforms config to pass over the wire, convert to SO for
saving)
- Lens public client (transform api format to old Lens state)
- Lens transforms (transforms Lens by-value panels for dashboards)

#### Update Lens CM and API schema

The schemas following changes from #229534, did not match the
integration perfectly and stubbed out a few things. So there was some
cleanup needed to these schema to make them clearer and easier to
understand.

These also needed to be changed to integrate the new
`lensApiStateSchema` that will include all New API Formats.

#### Registers Lens embeddable transforms

Transforms:
- `dashboard/server` - Used to transform by-ref Lens dashboard panels.
- `dashboard/public` - Used to transform panels from url state.
- `lens/public` - Used to transform standalone Lens embeddables (see
example
[here](https://github.com/elastic/kibana/blob/ed9f709ef56b182116ebcd788245fdecfdacfd8b/x-pack/platform/plugins/shared/cases/public/components/visualizations/lens_renderer.tsx#L40)).

These transforms are meant to transform both:
- **Item transforms** - Current `v0` Lens state/attributes with old
configurations to the latest state/attributes. Applying all existing
runtime migrations and pins version to latest Lens item `v1`.
- Only for `lens/public` transforms, we are not saving standalone Lens
embeddable state in new API format.
- **API Format transforms** - Transforms the current `v1` Lens state to
the new API format and vis-versa.
- Needed to save Lens as `v1` as SO but pass the New API Format over the
wire.
- Needed to save Lens state in dashboard by-value panels in the New API
Format.

Transforms are behind a features flag, when enabled it will transform
only supported chart types for all lens visualizations including by-ref
and by-value. When disabled (default) it will pass around the only Lens
SO state as it does today.

```yml
# kibana.dev.yml
feature_flags.overrides:
  lens.apiFormat: true
```

### Issues

Closes #229543
Closes #229546
Closed #237192

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)

---------

Co-authored-by: Peter Pisljar <peter.pisljar@elastic.co>
Co-authored-by: dej611 <dej611@gmail.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
Co-authored-by: Marco Vettorello <marco.vettorello@elastic.co>
eokoneyo pushed a commit to eokoneyo/kibana that referenced this pull request Dec 2, 2025
)

## Summary

Lens transforms Phase 2

### Changes

#### Integrate the Config Builder

This integrates the `LensConfigBuilder` into the full end-to-end flow of
all aspects of Lens including:
- Lens APIs (transforms config to pass over the wire, convert to SO for
saving)
- Lens public client (transform api format to old Lens state)
- Lens transforms (transforms Lens by-value panels for dashboards)

#### Update Lens CM and API schema

The schemas following changes from elastic#229534, did not match the
integration perfectly and stubbed out a few things. So there was some
cleanup needed to these schema to make them clearer and easier to
understand.

These also needed to be changed to integrate the new
`lensApiStateSchema` that will include all New API Formats.

#### Registers Lens embeddable transforms

Transforms:
- `dashboard/server` - Used to transform by-ref Lens dashboard panels.
- `dashboard/public` - Used to transform panels from url state.
- `lens/public` - Used to transform standalone Lens embeddables (see
example
[here](https://github.com/elastic/kibana/blob/ed9f709ef56b182116ebcd788245fdecfdacfd8b/x-pack/platform/plugins/shared/cases/public/components/visualizations/lens_renderer.tsx#L40)).

These transforms are meant to transform both:
- **Item transforms** - Current `v0` Lens state/attributes with old
configurations to the latest state/attributes. Applying all existing
runtime migrations and pins version to latest Lens item `v1`.
- Only for `lens/public` transforms, we are not saving standalone Lens
embeddable state in new API format.
- **API Format transforms** - Transforms the current `v1` Lens state to
the new API format and vis-versa.
- Needed to save Lens as `v1` as SO but pass the New API Format over the
wire.
- Needed to save Lens state in dashboard by-value panels in the New API
Format.

Transforms are behind a features flag, when enabled it will transform
only supported chart types for all lens visualizations including by-ref
and by-value. When disabled (default) it will pass around the only Lens
SO state as it does today.

```yml
# kibana.dev.yml
feature_flags.overrides:
  lens.apiFormat: true
```

### Issues

Closes elastic#229543
Closes elastic#229546
Closed elastic#237192

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)

---------

Co-authored-by: Peter Pisljar <peter.pisljar@elastic.co>
Co-authored-by: dej611 <dej611@gmail.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
Co-authored-by: Marco Vettorello <marco.vettorello@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:actionable-obs Formerly "obs-ux-management", responsible for SLO, o11y alerting, significant events, & synthetics. Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Lens as code] Add transform layer to CM

10 participants