Skip to content

[9.4] [Lens as code] Fix metric trendline (#264777)#264888

Merged
kibanamachine merged 1 commit intoelastic:9.4from
kibanamachine:backport/9.4/pr-264777
Apr 22, 2026
Merged

[9.4] [Lens as code] Fix metric trendline (#264777)#264888
kibanamachine merged 1 commit intoelastic:9.4from
kibanamachine:backport/9.4/pr-264777

Conversation

@kibanamachine
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 9.4:

Questions ?

Please refer to the Backport tool documentation

## 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

(cherry picked from commit dbc7ea0)
@kibanamachine kibanamachine added the backport This PR is a backport of another PR label Apr 22, 2026
@kibanamachine kibanamachine enabled auto-merge (squash) April 22, 2026 06:17
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

Comment on lines +14 to +27
const DASHBOARD_API_VERSION = '2023-10-31';

const LOGSTASH_TIME_RANGE = {
from: '2015-09-19T06:31:44.000Z',
to: '2015-09-23T18:31:44.000Z',
};

function withSpace(path: string, spaceId: string): string {
return `/s/${spaceId}${path}`;
}

async function createDashboard(client: KbnClient, body: unknown, spaceId: string): Promise<string> {
const response = await client.request<unknown>({
method: 'POST',
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.

The createDashboard helper duplicates the dashboard-creation pattern already in esql_timeseries_dashboard_api.spec.ts (createDashboardWithLensPanel). Both hit the same API with the same version header.

See details

Consider extracting a shared createDashboard(client, body, spaceId) into the existing fixtures/helpers.ts so both spec files (and future ones) reuse the same helper. This keeps the API path, version header, and status assertion in one place.

// fixtures/helpers.ts
export async function createDashboard(
  client: KbnClient,
  body: unknown,
  spaceId: string
): Promise<string> {
  const response = await client.request<unknown>({
    method: 'POST',
    path: `/s/${spaceId}/api/dashboards`,
    body,
    headers: { 'elastic-api-version': '2023-10-31' },
  });
  if (response.status !== 200 && response.status !== 201) {
    throw new Error(`Dashboard create failed: ${response.status}`);
  }
  const { id } = response.data as Record<string, unknown>;
  if (typeof id !== 'string' || id.length === 0) {
    throw new Error('Dashboard create: expected a non-empty id');
  }
  return id;
}

Then both spec files import createDashboard from '../fixtures'.

Posted via Macroscope — Scout Test Review

Comment on lines +116 to +117
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

.echSingleMetricSparkline is a CSS class from @elastic/charts — no data-test-subj exists for it today. Raw class selectors can break silently when the library updates class names.

See details

The existing FTR page object (lens_page.ts) uses the same CSS class, so this isn't new risk. However, the Scout best practice is to prefer data-test-subj, and if one is missing, to add it in source code.

Consider scoping the CSS selector under the mtrVis test-subj container so it's at least more resilient:

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

Longer-term, a data-test-subj on the sparkline wrapper in @elastic/charts would make all these selectors more stable.

Posted via Macroscope — Scout Test Review

@kibanamachine kibanamachine merged commit 0a9c40e into elastic:9.4 Apr 22, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants