Skip to content

[Lens as code] Fix metric trendline#264777

Merged
markov00 merged 4 commits intoelastic:mainfrom
markov00:2026_04_15-hidrate_metric_timeline_v2
Apr 22, 2026
Merged

[Lens as code] Fix metric trendline#264777
markov00 merged 4 commits intoelastic:mainfrom
markov00:2026_04_15-hidrate_metric_timeline_v2

Conversation

@markov00
Copy link
Copy Markdown
Contributor

@markov00 markov00 commented Apr 21, 2026

Summary

This PR fixes the missing trendline for metric when creating the chart from the API.
There where multiple problems connected to that:

  • the histogram column definition wasn't a date_histogram operation but the newPrimaryColumns (the metric operation)
  • the columnOrder was wrong and caused the expression to not pick up property the idMap (datatable columns to accessord ids)
  • the references array wasn't populated with the dataview references used in the trendline

fix #251620

@markov00 markov00 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:version Backport to applied version labels v9.4.0 labels Apr 21, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Apr 21, 2026

Catch flakiness early (recommended)

Recommended before merge: run the flaky test runner against this PR to catch flakiness early.

Covers the new Scout spec at x-pack/platform/plugins/shared/lens/test/scout/ui/parallel_tests/metric_trendline.spec.ts added in this PR.

Trigger a run with the Flaky Test Runner UI or post this comment on the PR:

/flaky scoutConfig:x-pack/platform/plugins/shared/lens/test/scout/ui/parallel.playwright.config.ts:30

Share feedback in the #appex-qa channel.

Posted via Macroscope — Flaky Test Runner nudge

Copy link
Copy Markdown
Contributor

@macroscopeapp macroscopeapp Bot left a comment

Choose a reason for hiding this comment

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

Scout Test Review: found 2 issues. See inline comments for details.

Share feedback in the #appex-qa channel.

Posted via Macroscope — Scout Test Review

await pageObjects.dashboard.openDashboardWithId(dashboardId);

await expect(page.getByTestId('mtrVis')).toBeVisible();
await expect(page.locator('.echSingleMetricSparkline')).toBeVisible();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Locate UI elements reliably

The .echSingleMetricSparkline CSS class selector is fragile — it can break if the upstream chart library renames the class. Consider adding a data-test-subj to the sparkline container in the Lens metric visualization source and using page.testSubj.locator() here instead.

See details

The best practices recommend using data-test-subj attributes accessed through page.testSubj. If a data-test-subj doesn't exist, the recommended approach is to add one to the source code.

The metric visualization in x-pack/platform/plugins/shared/lens renders the Elastic Charts <Metric> component, which produces the .echSingleMetricSparkline element. Adding a data-test-subj wrapper around or near the sparkline in the Lens metric renderer would make this selector stable and consistent with Scout conventions.

If adding a data-test-subj isn't feasible right now, scoping the CSS selector under the already-asserted mtrVis test subject would at least limit the blast radius:

const metricPanel = page.getByTestId('mtrVis');
await expect(metricPanel).toBeVisible();
await expect(metricPanel.locator('.echSingleMetricSparkline')).toBeVisible();

Posted via Macroscope — Scout Test Review

@markov00 markov00 marked this pull request as ready for review April 21, 2026 18:24
@markov00 markov00 requested a review from a team as a code owner April 21, 2026 18:24
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@elastic elastic deleted a comment from infra-vault-gh-plugin-prod Bot Apr 21, 2026
@markov00 markov00 changed the title fix metric trendline [Lens as code] Fix metric trendline Apr 21, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #193 / aiops change point detection UI allows change point selection for detailed view

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
agentBuilder 1.1MB 1.1MB -6.0B
cases 2.3MB 2.3MB -6.0B
dashboard 1.1MB 1.1MB -6.0B
dashboardAgent 388.7KB 388.7KB -6.0B
discover 1.9MB 1.9MB -6.0B
infra 1.5MB 1.5MB -6.0B
lens 2.0MB 2.0MB -6.0B
observability 2.0MB 2.0MB -6.0B
observabilityAIAssistantApp 658.0KB 658.0KB -6.0B
unifiedDocViewer 673.0KB 673.0KB -6.0B
total -60.0B

History

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 LGTM, tested creating metric with trendline from api, no issues.

@markov00 markov00 merged commit dbc7ea0 into elastic:main Apr 22, 2026
17 checks passed
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 9.4

https://github.com/elastic/kibana/actions/runs/24763105549

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
9.4

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Apr 22, 2026
# Backport

This will backport the following commits from `main` to `9.4`:
- [[Lens as code] Fix metric trendline
(#264777)](#264777)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Marco
Vettorello","email":"marco.vettorello@elastic.co"},"sourceCommit":{"committedDate":"2026-04-22T06:08:35Z","message":"[Lens
as code] Fix metric trendline (#264777)\n\n## Summary\n\nThis PR fixes
the missing trendline for metric when creating the chart\nfrom the
API.\nThere where multiple problems connected to that:\n- the histogram
column definition wasn't a date_histogram operation but\nthe
`newPrimaryColumns` (the metric operation)\n- the `columnOrder` was
wrong and caused the expression to not pick up\nproperty the idMap
(datatable columns to accessord ids)\n- the `references` array wasn't
populated with the dataview references\nused in the trendline\n\nfix
https://github.com/elastic/kibana/issues/251620","sha":"dbc7ea062fede0f744d29c12645e95c41ddc9ad1","branchLabelMapping":{"^v9.5.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Visualizations","release_note:skip","backport:version","v9.4.0","v9.5.0"],"title":"[Lens
as code] Fix metric
trendline","number":264777,"url":"https://github.com/elastic/kibana/pull/264777","mergeCommit":{"message":"[Lens
as code] Fix metric trendline (#264777)\n\n## Summary\n\nThis PR fixes
the missing trendline for metric when creating the chart\nfrom the
API.\nThere where multiple problems connected to that:\n- the histogram
column definition wasn't a date_histogram operation but\nthe
`newPrimaryColumns` (the metric operation)\n- the `columnOrder` was
wrong and caused the expression to not pick up\nproperty the idMap
(datatable columns to accessord ids)\n- the `references` array wasn't
populated with the dataview references\nused in the trendline\n\nfix
https://github.com/elastic/kibana/issues/251620","sha":"dbc7ea062fede0f744d29c12645e95c41ddc9ad1"}},"sourceBranch":"main","suggestedTargetBranches":["9.4"],"targetPullRequestStates":[{"branch":"9.4","label":"v9.4.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.5.0","branchLabelMappingKey":"^v9.5.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/264777","number":264777,"mergeCommit":{"message":"[Lens
as code] Fix metric trendline (#264777)\n\n## Summary\n\nThis PR fixes
the missing trendline for metric when creating the chart\nfrom the
API.\nThere where multiple problems connected to that:\n- the histogram
column definition wasn't a date_histogram operation but\nthe
`newPrimaryColumns` (the metric operation)\n- the `columnOrder` was
wrong and caused the expression to not pick up\nproperty the idMap
(datatable columns to accessord ids)\n- the `references` array wasn't
populated with the dataview references\nused in the trendline\n\nfix
https://github.com/elastic/kibana/issues/251620","sha":"dbc7ea062fede0f744d29c12645e95c41ddc9ad1"}}]}]
BACKPORT-->

Co-authored-by: Marco Vettorello <marco.vettorello@elastic.co>
mbondyra added a commit to mbondyra/kibana that referenced this pull request Apr 22, 2026
…sationChanges23

* commit '9a7b717c662d1c904052bc59f0e5a81daab87c7f': (145 commits)
  Upgrade EUI to v114.2.0 (elastic#264550)
  [Entity Analytics] Add missing OpenAPI descriptions and examples to p… (elastic#264778)
  [Entity Resolution] Clarify CSV upload result for already-linked entities (elastic#264689)
  [AI Infra] Fix failing GenAI Settings Scout tests (elastic#260496)
  [Agent Builder] [Bug Bash] OAuth connector settings mention fields that are not there (elastic#264756)
  [performance] process-wide cache for advanced settings lookup (elastic#262618)
  [CI] Update limits.yml for securitySolution (elastic#264946)
  [SLO] Fix APM embeddable ids (elastic#264750)
  [EDR Workflows] Unify artifacts empty state buttons (elastic#264389)
  [Alert Triage workflow] Adds security.buildAlertEntityGraph and security.renderAlertNarrative… (elastic#259159)
  [SigEvents] Add KI feature identification endpoints and refactor task to use shared service (elastic#263528)
  [Scout] Migrate Data Views API tests from FTR - Part5 (elastic#264088)
  [Cases] Apply shared extended_fields path util server side (elastic#264706)
  [Lens as code] Fix metric trendline (elastic#264777)
  [api-docs] 2026-04-22 Daily api_docs build (elastic#264882)
  [Scout] Update test config manifests (elastic#264575)
  [workflows_management] Lazy-load Zod connector schemas to cut idle memory (elastic#264283)
  [ES|QL] Fix ES|QL columns reset race during active fetch (elastic#263947)
  [Content List] Column layout props, sticky actions, and title click handlers (elastic#264203)
  [Lens as code] Validate `id` in route for new vis types (elastic#264480)
  ...
SoniaSanzV pushed a commit to SoniaSanzV/kibana that referenced this pull request Apr 27, 2026
## Summary

This PR fixes the missing trendline for metric when creating the chart
from the API.
There where multiple problems connected to that:
- the histogram column definition wasn't a date_histogram operation but
the `newPrimaryColumns` (the metric operation)
- the `columnOrder` was wrong and caused the expression to not pick up
property the idMap (datatable columns to accessord ids)
- the `references` array wasn't populated with the dataview references
used in the trendline

fix elastic#251620
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels 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 v9.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Lens as code] Metric trendline not visible

4 participants