Skip to content

[Lens as code] Optimize the OAS output using id references for entities#249625

Merged
dej611 merged 7 commits intoelastic:mainfrom
dej611:fix/lens-api-shrink
Jan 23, 2026
Merged

[Lens as code] Optimize the OAS output using id references for entities#249625
dej611 merged 7 commits intoelastic:mainfrom
dej611:fix/lens-api-shrink

Conversation

@dej611
Copy link
Copy Markdown
Contributor

@dej611 dej611 commented Jan 19, 2026

Summary

Fixes part of #234621, #249889

These changes make the OAS Lens bundle size shrink from 116 to 1 MB (-99%)

Before:

yarn build:lens-docs
yarn run v1.22.22
$ node scripts/capture_oas_snapshot --include-path /api/lens --no-serverless --update
 info Capturing OAS for traditional Kibana...
 info Starting Kibana...
   │ info Loading core with all plugins enabled so that we can capture OAS for all...
 info Recieved OAS, writing to /Users/marcoliberati/Work/kibana/oas_docs/bundle.json...
 succ OAS written to /Users/marcoliberati/Work/kibana/oas_docs/bundle.json. File size ~116.44 MB.
 succ Captured OAS for traditional Kibana.
✨  Done in 50.17s.

Initial optimization

yarn lens-docs      
yarn run v1.22.22
$ yarn build:lens-docs && yarn deploy:lens-docs
$ node scripts/capture_oas_snapshot --include-path /api/lens --no-serverless --update
 info Capturing OAS for traditional Kibana...
 info Starting Kibana...
   │ info Loading core with all plugins enabled so that we can capture OAS for all...
 info Recieved OAS, writing to /Users/marcoliberati/Work/kibana/oas_docs/bundle.json...
 succ OAS written to /Users/marcoliberati/Work/kibana/oas_docs/bundle.json. File size ~37.13 MB.
 succ Captured OAS for traditional Kibana.

Second iteration:

✗ yarn lens-docs
yarn run v1.22.22
$ yarn build:lens-docs && yarn bundle:lens-docs
$ node scripts/capture_oas_snapshot --include-path /api/lens --no-serverless --update
 info Capturing OAS for traditional Kibana...
 info Starting Kibana...
   │ info Loading core with all plugins enabled so that we can capture OAS for all...
 info Recieved OAS, writing to /Users/marcoliberati/Work/kibana/oas_docs/bundle.json...
 succ OAS written to /Users/marcoliberati/Work/kibana/oas_docs/bundle.json. File size ~1.07 MB.

Final solution:

✗ yarn lens-docs                        
yarn run v1.22.22
$ yarn build:lens-docs && yarn bundle:lens-docs
$ node scripts/capture_oas_snapshot --include-path /api/lens --no-serverless --update
 info Capturing OAS for traditional Kibana...
 info Starting Kibana...
   │ info Loading core with all plugins enabled so that we can capture OAS for all...
 info Recieved OAS, writing to /Users/marcoliberati/Work/kibana/oas_docs/bundle.json...
 succ OAS written to /Users/marcoliberati/Work/kibana/oas_docs/bundle.json. File size ~1.59 MB.
 succ Captured OAS for traditional Kibana.

That enables a smoother deployment over the API publishing platform and perform gitops over it (Github has a 100MB per file limit).

Unfortunately there are still issues on the doc platform itself which has a 30s timeout for server side rendering, and metric and gauge chart take longer to generate 🦥
I'll create a separate issue to track them.

The final solution produces a bundle which a bit less optimised than the previous step, but it guarantees that each entity chunk is relatively small (> 10kb) and that prevents issues with the documentation platform.

Entity size table details
=== Schema Sizes (in bytes) ===

Total schemas found: 76


Schema Name                                                  Size (bytes)
===========================================================================
Kibana_HTTP_APIs_metricESQL                                          8003
Kibana_HTTP_APIs_xyDataLayer                                         7445
Kibana_HTTP_APIs_heatmapNoESQL                                       7285
Kibana_HTTP_APIs_metricNoESQL                                        6859
Kibana_HTTP_APIs_gaugeESQL                                           4919
Kibana_HTTP_APIs_termsOperationSchema                                4854
Kibana_HTTP_APIs_categoricalColorMappingSchema                       4405
Kibana_HTTP_APIs_gradientColorMappingSchema                          4295
Kibana_HTTP_APIs_tagcloudESQL                                        3714
Kibana_HTTP_APIs_movingAverageOperationSchema                        3582
Kibana_HTTP_APIs_differencesOperationSchema                          3487
Kibana_HTTP_APIs_legacyMetricESQL                                    3481
Kibana_HTTP_APIs_gaugeNoESQL                                         3375
Kibana_HTTP_APIs_heatmapESQL                                         3113
Kibana_HTTP_APIs_regionMapESQL                                       3108
Kibana_HTTP_APIs_xyReferenceLayerESQL                                3096
Kibana_HTTP_APIs_xyAxis                                              3080
Kibana_HTTP_APIs_cumulativeSumOperationSchema                        2878
Kibana_HTTP_APIs_counterRateOperationSchema                          2874
Kibana_HTTP_APIs_formulaOperationDefinitionSchema                    2778
Kibana_HTTP_APIs_xyDataLayerESQL                                     2761
Kibana_HTTP_APIs_colorByValuePercentage                              2563
Kibana_HTTP_APIs_xyReferenceLayer                                    2235
Kibana_HTTP_APIs_colorByValueAbsolute                                2165
Kibana_HTTP_APIs_xyChartSchema                                       2091
Kibana_HTTP_APIs_xyAnnotationQuery                                   1859
Kibana_HTTP_APIs_xyLegendInternal                                    1671
Kibana_HTTP_APIs_heatmapAxesSchema                                   1655
Kibana_HTTP_APIs_xyLegendExternal                                    1565
Kibana_HTTP_APIs_xyAnnotationManualEvent                             1445
Kibana_HTTP_APIs_lastValueOperationSchema                            1392
Kibana_HTTP_APIs_uniqueCountMetricOperationSchema                    1360
Kibana_HTTP_APIs_sumMetricOperationSchema                            1343
Kibana_HTTP_APIs_countMetricOperationSchema                          1331
Kibana_HTTP_APIs_percentileRanksOperationSchema                      1323
Kibana_HTTP_APIs_minMaxAvgMedianStdDevMetricOperationSchema          1320
Kibana_HTTP_APIs_percentileOperationSchema                           1315
Kibana_HTTP_APIs_indexDatasetTypeSchema                              1207
Kibana_HTTP_APIs_xyAnnotationLayer                                   1184
Kibana_HTTP_APIs_histogramOperationSchema                            1176
Kibana_HTTP_APIs_xyDecorations                                       1153
Kibana_HTTP_APIs_searchFilterQueryStringSchema                        952
Kibana_HTTP_APIs_dateHistogramOperationSchema                         945
Kibana_HTTP_APIs_xyXAxis                                              878
Kibana_HTTP_APIs_xyAnnotationManualRange                              858
Kibana_HTTP_APIs_heatmapLegendSchema                                  811
Kibana_HTTP_APIs_staticOperationDefinitionSchema                      777
Kibana_HTTP_APIs_xyFittingFunction                                    775
Kibana_HTTP_APIs_metricBreakdownByEsql                                638
Kibana_HTTP_APIs_searchFilterObjectSchema                             625
Kibana_HTTP_APIs_xyAnnotationManualRangeInterval                      583
Kibana_HTTP_APIs_xyAnnotationPointLine                                576
Kibana_HTTP_APIs_metricPrimaryMetricAlignments                        544
Kibana_HTTP_APIs_metricCompareToBaseline                              534
Kibana_HTTP_APIs_numericFormatSchema                                  533
Kibana_HTTP_APIs_xyYAxisExtentCustom                                  517
Kibana_HTTP_APIs_xyXAxisExtentCustom                                  507
Kibana_HTTP_APIs_filtersOperationSchema                               494
Kibana_HTTP_APIs_metricIconConfig                                     450
Kibana_HTTP_APIs_durationFormatSchema                                 443
Kibana_HTTP_APIs_metricCompareToPrimary                               432
Kibana_HTTP_APIs_esqlDatasetTypeSchema                                408
Kibana_HTTP_APIs_dataViewDatasetTypeSchema                            406
Kibana_HTTP_APIs_byteFormatSchema                                     405
Kibana_HTTP_APIs_heatmapCellsSchema                                   380
Kibana_HTTP_APIs_xyAnnotationQueryTextField                           377
Kibana_HTTP_APIs_staticColorSchema                                    363
Kibana_HTTP_APIs_xyAxisTitle                                          342
Kibana_HTTP_APIs_filterSimpleSchema                                   340
Kibana_HTTP_APIs_xyYAxisExtentFull                                    330
Kibana_HTTP_APIs_filterWithLabelSchema                                320
Kibana_HTTP_APIs_xyXAxisExtentFull                                    310
Kibana_HTTP_APIs_customFormatSchema                                   305
Kibana_HTTP_APIs_heatmapAxisSimpleSchema                              280
Kibana_HTTP_APIs_xyYAxisExtentFocus                                   269
Kibana_HTTP_APIs_tableESQLDatasetTypeSchema                           257
===========================================================================
TOTAL                                                              138709


=== Summary Statistics ===

Average size: 1825 bytes
Minimum size: 257 bytes (Kibana_HTTP_APIs_tableESQLDatasetTypeSchema)
Maximum size: 8003 bytes (Kibana_HTTP_APIs_metricESQL)

Testing it

To check the actual changes it is best to use @nickofthyme 's temporary PR here: #249426 with the yarn build:lens-docs command.
Also, it is possible to get the generated bundle.json file from that PR and import it into https://editor.swagger.io/ to see the data in it

@dej611 dej611 added the Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// label Jan 19, 2026
@dej611 dej611 requested a review from a team as a code owner January 19, 2026 17:15
@dej611 dej611 added release_note:skip Skip the PR/issue when compiling release notes Feature:Lens backport:version Backport to applied version labels v9.4.0 labels Jan 19, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-visualizations (Team:Visualizations)

Copy link
Copy Markdown
Contributor

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

Changes look good to me, lots of great improvements!

@dej611 dej611 enabled auto-merge (squash) January 23, 2026 18:06
@dej611 dej611 merged commit a437033 into elastic:main Jan 23, 2026
15 of 16 checks passed
@kibanamachine kibanamachine added backport:skip This PR does not require backporting and removed backport:version Backport to applied version labels labels Jan 23, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

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

id before after diff
lens 2.0MB 2.0MB +1.3KB

History

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 Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Team label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t// v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants