[Lens as code] Fix metric trendline#264777
Conversation
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 Trigger a run with the Flaky Test Runner UI or post this comment on the PR: Share feedback in the #appex-qa channel. Posted via Macroscope — Flaky Test Runner nudge |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
|
Pinging @elastic/kibana-visualizations (Team:Visualizations) |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
History
|
nickofthyme
left a comment
There was a problem hiding this comment.
Changes LGTM, tested creating metric with trendline from api, no issues.
|
Starting backport for target branches: 9.4 https://github.com/elastic/kibana/actions/runs/24763105549 |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
# 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>
…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) ...
## 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
Summary
This PR fixes the missing trendline for metric when creating the chart from the API.
There where multiple problems connected to that:
newPrimaryColumns(the metric operation)columnOrderwas wrong and caused the expression to not pick up property the idMap (datatable columns to accessord ids)referencesarray wasn't populated with the dataview references used in the trendlinefix #251620