Skip to content

Re-initialize metric charts when instrument unit, type or monotonicity changes - #21143

Merged
Sébastien Ros (sebastienros) merged 1 commit into
mainfrom
sebros/fix-metric-chart-reinit
Nov 4, 2026
Merged

Sébastien Ros (sebastienros) merged 1 commit into
mainfrom
sebros/fix-metric-chart-reinit

Conversation

@sebastienros

@sebastienros Sébastien Ros (sebastienros) commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

ChartBase decides between a full chart initialization and a data update using the instrument key (meter and instrument names), the dimension attributes, the theme and the display options. Switching resources can show an instrument with the same key and dimensions but a different unit, type or monotonicity. The chart then called updateChart, which keeps the previous instrument's trace names and layout, so the legend labels could be wrong.

Trace names come from the unit, and from whether the instrument is a monotonic counter ("per interval"). The type decides which traces are drawn. This PR adds all three to the re-initialization check.

Comparing dimension attributes by value, which stops charts re-initializing on every refresh, reached main through #21412. That removed the re-initialization that previously covered this case. This PR originally carried that value comparison too; only this follow-up remains after rebasing onto main.

Testing

  • New test PlotlyChartTests.UpdateDataAsync_SameInstrumentKeyWithDifferentUnitTypeOrMonotonicity_ReinitializesChart covers a unit change, a type change and a monotonicity change. All three cases fail without the ChartBase change.
  • All non-quarantined, non-outerloop tests in Aspire.Dashboard.Components.Tests pass.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 21143

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 21143"

@github-actions

This comment has been minimized.

Copilot AI left a comment

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.

🟢 Approval recommended

The focused fix preserves other reinitialization conditions and includes targeted regression coverage, with no unresolved findings.

No open issues 🎉

What changed in this PR

Prevents unnecessary metric chart reinitialization during data refreshes, preserving hover state and avoiding flicker and scroll disruption.

Changes:

  • Compare dimension attributes by value rather than array reference.
  • Reuse the cache’s attribute comparison helper.
  • Add regression coverage for refreshed dimensions with unchanged attributes.
File Description
tests/​Aspire.Dashboard.Components.Tests/​Controls/​PlotlyChartTests.cs Tests that equivalent refreshed dimensions do not reinitialize the chart.
src/​Aspire.Dashboard/​Components/​Controls/​Chart/​MetricInstrumentDataCache.cs Makes the attribute comparison helper internally accessible.
src/​Aspire.Dashboard/​Components/​Controls/​Chart/​ChartBase.cs Uses value-based dimension comparison.

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@github-actions

This comment has been minimized.

Copilot AI left a comment

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.

🟢 Approval recommended

The focused fix preserves dimension-change detection and includes regression coverage, with no unresolved issues identified.

No open issues 🎉

Review effort: Balanced

@github-actions

Copy link
Copy Markdown
Contributor

Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt.

@sebastienros Sébastien Ros (sebastienros) changed the title Stop re-initializing metric charts on every data refresh Stop re-initializing metric charts on every data refresh (legacy dashboard backport) Nov 2, 2026

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.

I reviewed the chart refresh flow, resource switching, and regression coverage. I found one case where switching resources can leave the chart using the previous instrument’s labels or trace layout.

Copilot AI left a comment

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.

🔵 Needs a closer look

Explicit duration or selection changes can be discarded by the tick throttle, leaving read-only metric tables indefinitely stale without a periodic retry.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Throttle drops explicit duration updates for read-only tables

src/​Aspire.Dashboard/​Components/​Controls/​Chart/​ChartBase.cs:116

Value-equal dimensions now send explicit duration or selection refreshes through the tick throttle, which can discard the only update. For example, changing a read-only metric table's duration within its one-second UpdateInterval can leave the previous rows displayed indefinitely because read-only repositories have no periodic tick to retry it. Make explicit data/window changes bypass the throttle or schedule a trailing data update without reinitializing Plotly, and add a read-only regression test for a duration change inside the throttle interval.

Review effort: Balanced

…y changes

The instrument key only contains the meter and instrument names. Switching
resources can show an instrument with the same key and dimensions but a
different unit, type or monotonicity. Each of these changes the rendered
trace names or layout, which only a full initialization replaces.

Comparing dimension attributes by value removed the re-initialization that
previously covered this case.
@sebastienros Sébastien Ros (sebastienros) changed the title Stop re-initializing metric charts on every data refresh (legacy dashboard backport) Re-initialize metric charts when instrument unit, type or monotonicity changes Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Tests selector

13 / 101 PR test projects · 2 PR jobs, from 2 changed files.

Selected PR test projects (13 / 101)

Aspire.Dashboard.Components.Tests, Aspire.Dashboard.Tests, Aspire.Hosting.Azure.Kubernetes.Tests, Aspire.Hosting.Azure.Tests, Aspire.Hosting.Blazor.Tests, Aspire.Hosting.Dotnet.Tests, Aspire.Hosting.DotnetTool.Tests, Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Radius.Tests, Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Playground.Tests, Aspire.Templates.Tests

Selected PR jobs (2)

extension-e2e, native-dashboard-validation


How these were chosen — grouped by what changed

⚠️ 11 of the 13 selected test projects come from a single change — src/Aspire.Dashboard/Components/Controls/Chart/ChartBase.cs.

🔧 src/Aspire.Dashboard/Components/Controls/Chart/ChartBase.cs (changed source)
→ 11 via the project graph: Aspire.Dashboard.Tests, Aspire.Hosting.Azure.Kubernetes.Tests (3 hops), Aspire.Hosting.Azure.Tests (2 hops), Aspire.Hosting.Blazor.Tests (2 hops), Aspire.Hosting.Dotnet.Tests (2 hops), Aspire.Hosting.DotnetTool.Tests (2 hops), Aspire.Hosting.JavaScript.Tests, Aspire.Hosting.Radius.Tests (2 hops), Aspire.Hosting.Testing.Tests, Aspire.Hosting.Tests, Aspire.Playground.Tests (2 hops)

📦 affected project Aspire.Dashboard
→ 1 test: Aspire.Templates.Tests

🧪 tests/Aspire.Dashboard.Components.Tests/Controls/PlotlyChartTests.cs (changed test)
→ 1 directly: Aspire.Dashboard.Components.Tests

Job reasons

Job Triggered by
extension-e2e • src/Aspire.Dashboard/Components/Controls/Chart/ChartBase.cs
• affected project Aspire.Dashboard
native-dashboard-validation affected project Aspire.Dashboard

Selection computed for commit 882c168.

Copilot AI left a comment

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.

🟢 Approval recommended

No active review issues are reported for the change addressing stale metric chart labels and layouts.

No open issues 🎉

Review effort: Balanced

@sebastienros
Sébastien Ros (sebastienros) merged commit dfe1c11 into main Nov 4, 2026
161 checks passed
@microsoft-github-policy-service microsoft-github-policy-service Bot added this to the 17.0 milestone Nov 4, 2026
@aspire-repo-bot

Copy link
Copy Markdown
Contributor

✅ No documentation update needed.

docs_optional → bug_fix_restores_documented_behavior. No signals triggered (signal_count 0). Changed files: src/Aspire.Dashboard/Components/Controls/Chart/ChartBase.cs and tests/Aspire.Dashboard.Components.Tests/Controls/PlotlyChartTests.cs. The change fixes chart re-initialization so legend labels are correct when the instrument unit, type or monotonicity changes. There are no new options, strings, or public surface.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants