Skip to content

Dashboard: preserve resource selection in telemetry pages and metric charts - #21431

Open
David Fowler (davidfowl) wants to merge 11 commits into
mainfrom
aspireagent/fix-21419-dashboard-selection
Open

David Fowler (davidfowl) wants to merge 11 commits into
mainfrom
aspireagent/fix-21419-dashboard-selection

Conversation

@davidfowl

@davidfowl David Fowler (davidfowl) commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fixes the two remaining selection-loss review findings tracked in #21419 (follow-up to #21412).

1. Structured logs / traces lose the resource scope when telemetry arrives later.
If a resource's logs or traces page is opened before that resource has sent telemetry, the route resolves to "(All)" and the view model keeps a null ResourceKey. When telemetry later arrives, GetSelectionTelemetryKeys returns null ("use the page's resource key"), so the page lists every resource's data under the selected resource. For structured logs, the read subscription with a null key also marks unrelated resources' errors as viewed.

Fix: when new telemetry resources are reported, StructuredLogs and Traces re-resolve the route's resource if the page is still on "(All)". This sets the selected resource, resource key/keys and subscription, then refreshes the grid. Metrics already does the same in OnResourcesUpdatedAsync. Until the route resolves, structured logs uses a non-read subscription and doesn't mark errors as viewed. Other resources' errors that arrive first, or in the same batch, therefore keep their unread counts.

2. Metrics chart loses its resource in a multi-resource selection.
With api and worker selected and api's instrument chart open, changing duration or graph/table view rebuilt the URL without /resource/api, so the page dropped back to the aggregate instrument list.

Fix: for multi-selection, GetUrlFromSerializableViewModel keeps the resource name when an instrument chart is open and the resource is part of the current selection. The aggregate list and stale names still drop it.

Regression tests (all three fail on main and pass with this change):

  • StructuredLogsTests.ResourcesLayout_SelectedResourceSendsTelemetryAfterPageOpened_ShowsOnlyThatResource: only api logs are shown. worker's errors stay unviewed, both the one sent before api's first telemetry and the one sent after.
  • TracesTests.ResourcesLayout_SelectedResourceSendsTelemetryAfterPageOpened_ShowsOnlyThatResource: only api traces are shown.
  • MetricsTests.ResourcesLayout_MultiSelectionInstrumentChart_ChangingViewKeepsActiveResource: the path stays /metrics/resource/api, with the instrument, view and selection kept.

Before the fix, the Metrics test navigated to /metrics instead of /metrics/resource/api. The logs and traces tests timed out waiting for the selected resource to become api (it stayed "(All)"). The full Aspire.Dashboard.Components.Tests suite passes locally (1164/1164).

No visual/layout change, so there are no screenshots.

Fixes #21419

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No

🤖 Posted by AspireAgent (AI Agent)

…harts

- Structured logs and traces resolve the route's resource again when its
  telemetry arrives, so a page opened before the resource sent telemetry
  stops showing (and marking viewed) every resource's data.
- Metrics keeps the open chart's resource in the URL for a multi-resource
  selection, so changing duration or view no longer drops back to the
  aggregate instrument list.

Fixes #21419

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@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 -- 21431

Or

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

@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.

🟡 Changes recommended

The unresolved-route all-resource read subscription can irrecoverably suppress worker unread counts when worker telemetry arrives first or in the same batch, requiring a fix and regression coverage.

1 open issue
What changed in this PR

Addresses resource-selection loss tracked in #21419 following the dashboard redesign in #21412.

Changes:

  • Re-resolves resource-scoped logs and traces pages when telemetry becomes available.
  • Preserves the active metrics chart resource during option changes in multi-resource selections.
  • Adds regression tests for delayed telemetry and chart navigation.
File Description
tests/​Aspire.Dashboard.Components.Tests/​Pages/​TracesTests.cs Tests trace scoping after delayed telemetry.
tests/​Aspire.Dashboard.Components.Tests/​Pages/​StructuredLogsTests.cs Tests log scoping and unrelated unread-error preservation.
tests/​Aspire.Dashboard.Components.Tests/​Pages/​MetricsTests.cs Tests chart resource retention when switching views.
src/​Aspire.Dashboard/​Components/​Pages/​Traces.razor.cs Resolves pending route resources and refreshes traces.
src/​Aspire.Dashboard/​Components/​Pages/​StructuredLogs.razor.cs Resolves pending route resources and updates log subscriptions.
src/​Aspire.Dashboard/​Components/​Pages/​Metrics.razor.cs Retains selected chart resources in navigation URLs.

Review effort: Balanced

… unresolved

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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 block approval of the resource-selection fixes.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@github-actions

This comment has been minimized.

@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.

@davidfowl
David Fowler (davidfowl) marked this pull request as ready for review October 30, 2026 08:21
David Pine (IEvangelist) added a commit that referenced this pull request Nov 4, 2026
## Description

Selecting a resource that has not sent telemetry should not unexpectedly
move users from Traces or Structured logs to Overview. Keep the current
telemetry page and let its existing empty state explain the absence of
data, matching Metrics.

UX-30 only. This updates selection URL routing in `ResourcesLayout`; it
does not change telemetry arrival handling or chart scope in #21431, or
redesign Home/Details. Selecting a single parameter still opens
Overview.

Based on freshly fetched `microsoft/aspire` upstream `main` at
`9f0961d0c7173732f45ce88d571c8b53f8059934`.

### User-facing usage

While on Traces or Structured logs, select a resource with no telemetry.
The resource selection updates without leaving the page. Traces shows
its existing "No traces" empty state. Ctrl/Cmd-click to select multiple
resources, or select all to clear the explicit selection, without
changing telemetry pages.

### Validation

- `.\restore.cmd` - passed.
- Before the production fix, the following command reproduced two
failures: Traces and Structured logs generated `/resources/cache`
instead of their telemetry URLs. Four cases passed, including Metrics
and the single-parameter exception:

  ```powershell
dotnet test --project
tests\Aspire.Dashboard.Components.Tests\Aspire.Dashboard.Components.Tests.csproj
--no-launch-profile -- --filter-method
'*.Telemetry_ChangingTheSelectionStaysOnTheCurrentTabEvenWithoutTelemetry'
--filter-method '*.Telemetry_SelectingOnlyAParameterNavigatesToOverview'
--filter-not-trait 'quarantined=true' --filter-not-trait
'outerloop=true'
  ```

- After the fix, the following command passed all 87 cases, including
no-telemetry single/multiple/no selection, parameter-only navigation,
and the rendered Traces empty state:

  ```powershell
dotnet test --project
tests\Aspire.Dashboard.Components.Tests\Aspire.Dashboard.Components.Tests.csproj
--no-launch-profile -- --filter-class '*.ResourcesLayoutTests'
--filter-not-trait 'quarantined=true' --filter-not-trait
'outerloop=true'
  ```

- `git diff --check` - passed.
- Real-browser verification against this branch's build passed using a
temporary Playwright fixture, with six interactions covering both pages
at all three viewport sizes. The fixture seeded one trace and one
structured log for `api`, and no telemetry for `cache`. It navigated
through the normal tab UI, verified the populated `api` page, then
selected `cache` at each target viewport. Assertions checked the scoped
URL, resource title, selected tab, explicit empty message, and absence
of document horizontal overflow. The fixture and browser were disposed
after capture; the capture harness is not part of this PR.

  ```powershell
dotnet test --project
tests\Aspire.Dashboard.Playwright.Tests\Aspire.Dashboard.Playwright.Tests.csproj
--no-launch-profile -- --filter-method '*.CaptureAffectedStates'
--filter-not-trait 'quarantined=true' --filter-not-trait
'outerloop=true'
  ```

### Screenshots / Recordings

Actual Chromium viewport captures from this branch, using synthetic test
resources only. Each screenshot shows `cache` selected after switching
from a resource with data. Traces remains at `/traces/resource/cache`
with **No traces found**; Structured logs remains at
`/structuredlogs/resource/cache` with **No structured logs found**.

At **390 x 844** and **768 x 1024**, selection used the responsive
resource picker: open the drawer, select `cache`, and verify it closes.
At **1440 x 900**, selection used the persistent resource pane. All six
images were visually inspected: resource scope and empty-state text
remain readable, the empty message stays within the viewport, and
document/body width equals viewport width. At mobile width, the existing
tab strip truncates trailing labels and exposes its overflow action; the
page heading identifies the current telemetry view.

| Viewport (pixels) | Traces: selected no-data resource | Structured
logs: selected no-data resource |
| --- | --- | --- |
| Mobile **390 x 844** | ![Traces no-data resource - mobile
390x844](https://github.com/user-attachments/assets/4eb6ff31-2230-41dd-a70d-38880ad5438b)
| ![Structured logs no-data resource - mobile
390x844](https://github.com/user-attachments/assets/48356570-d85b-4a32-bb2d-59dbcb3e4791)
|
| Tablet **768 x 1024** | ![Traces no-data resource - tablet
768x1024](https://github.com/user-attachments/assets/2ad72901-4cdf-4309-b7e7-7cbf4ac370d7)
| ![Structured logs no-data resource - tablet
768x1024](https://github.com/user-attachments/assets/79363849-f474-477c-8c58-09deb28b2bb1)
|
| Desktop **1440 x 900** | ![Traces no-data resource - desktop
1440x900](https://github.com/user-attachments/assets/556482a8-e75f-411d-8da7-8af8daee7a43)
| ![Structured logs no-data resource - desktop
1440x900](https://github.com/user-attachments/assets/9d33a3bf-0701-4863-814d-b5d180c13368)
|

Fixes # (issue)

## Checklist

- Is this feature complete?
  - [x] Yes. Ready to ship.
  - [ ] No. Follow-up changes expected.
- Are you including unit tests for the changes and scenario tests if
relevant?
  - [x] Yes
  - [ ] No
- Did you add public API?
  - [ ] Yes
    - If yes, did you have an API Review for it?
      - [ ] Yes
      - [ ] No
- Did you add `<remarks />` and `<code />` elements on your triple slash
comments?
      - [ ] Yes
      - [ ] No
  - [x] No
- Does the change make any security assumptions or guarantees?
  - [ ] Yes
    - If yes, have you done a threat model and had a security review?
      - [ ] Yes
      - [ ] No
  - [x] No

Co-authored-by: David Pine <7679720+IEvangelist@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@davidfowl David Fowler (davidfowl) added the agent:working An AI agent is actively working on this issue or PR label Nov 6, 2026 — with Copilot SWE Agent
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copy link
Copy Markdown
Collaborator Author

Merged main into this branch to resolve conflicts in StructuredLogs.razor.cs and Traces.razor.cs. main now subscribes to ResourcesLayout.ResourcesChanged just before the OnNewResources subscription. I kept that subscription and this PR's async callback, which awaits ResolveRouteResourceAsync(). No other changes.

Local tests: Aspire.Dashboard.Components.Tests passed 1371/1371. The MetricsTests, StructuredLogsTests and TracesTests classes ran 6 times. One early run had a single failure that didn't reproduce in the next 5 runs.

🤖 Posted by AspireAgent (AI Agent)

@davidfowl David Fowler (davidfowl) removed the agent:working An AI agent is actively working on this issue or PR label Nov 6, 2026
@aspire-repo-bot
aspire-repo-bot Bot requested a balanced review from Copilot November 6, 2026 07:26
@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

No active review issues remain for the resource-scoping and chart-selection changes.

No open issues 🎉

Review effort: Balanced

@github-actions

github-actions Bot commented Nov 6, 2026

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.

@davidfowl David Fowler (davidfowl) added the agent:working An AI agent is actively working on this issue or PR label Nov 7, 2026 — with Copilot SWE Agent

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.

🟡 Changes recommended

Replica-driven name changes can close open metric charts, delayed subscription updates can lose unread log counts, and two tests race independent telemetry callbacks.

4 open issues

Review effort: Balanced

- Metrics: find an open chart's resource in a multi-selection by its telemetry
  key, so a replica arriving while the chart is open (which renames "api" to
  "api-<instance>") doesn't close the chart on the next duration or view change.
- Structured logs: replace the previous page's subscription before awaiting the
  grid refresh, so navigating away from all logs can't mark an error that
  arrives during the refresh as viewed.
- Tests: wait for the layout's telemetry key as well as the page's selected
  resource, because the page and layout are notified by separate callbacks
  that can run in either order. Add coverage for a replica arriving while a
  multi-selection chart is open.
@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.

🔵 Needs a closer look

Ambiguous resource-to-telemetry mappings and their effects on log subscriptions and trace filtering warrant human assessment.

No open issues 🎉

4 resolved since last review

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.

With the resource list, the logs subscription now follows the telemetry keys
the grid queries instead of the page's own resource. A read subscription marks
new errors as viewed when they arrive, and the page's subscription had no key
for a multi-resource selection, so selecting api and worker also hid errors
from every other resource. The page's resource could also disagree with the
resource list when several telemetry resources share a name.

The subscription is a read subscription only for a single shown resource. With
several resources, or none with telemetry yet, it only refreshes the grid, and
GetData still marks the shown resources' errors as viewed.
@sebastienros

Copy link
Copy Markdown
Contributor

Added c0a4bf9, which extends the "unrelated errors aren't marked as read" fix to multi-resource selections in structured logs.

Problem. With several resources selected (for example api and worker), the page has no route resource, so its logs subscription was a read subscription without a key. NotifyLogsAdded treats that as covering every resource, so errors from unselected resources (for example cache) were marked as viewed as soon as they arrived. The same mismatch could happen with a single selection when the page's own resource lookup disagrees with the resource list, for example when several telemetry resources share a composite name such as (api-a, 1) and (api, a-1).

Fix. With the resource list, UpdateSubscription now follows the telemetry keys that the grid queries:

Resource list's keys Subscription
One key Read subscription for that key, as before
Several keys, or none with telemetry yet SubscriptionType.Other for every resource: it only refreshes the grid, and GetData still marks the shown resources' errors as viewed
No resource list Unchanged: the page's resource, and Other while the route resource is unresolved

The subscription is also updated when the layout's keys change (OnLayoutResourcesChanged and GetData).

Tradeoff. In a multi-selection, a selected resource's unread badge can show briefly until the grid refreshes.

Test. StructuredLogsTests.ResourcesLayout_MultiSelection_OnlySelectedResourcesErrorsAreMarkedViewed selects api and worker, then sends errors from worker and from the unselected cache. worker's error is marked as viewed, and cache's stays unviewed. Without the fix, cache's unviewed count is 0 instead of 1. All 1459 tests in Aspire.Dashboard.Components.Tests pass locally.

@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.

🟡 Changes recommended

A selection-change race can leave a stale log subscription active and incorrectly mark errors from the previously selected resource as viewed.

1 open issue

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.

On navigation, the resource list updates its selection and raises
ResourcesChanged before it renders the page with the new URL's parameters.
The page computed its telemetry keys from its own SelectedResourceNames, which
were still the previous selection's, so the handler kept the previous read
subscription and the previous resource's new errors were marked as viewed while
the page moved away from it. Every key lookup on the page now uses the resource
list's selection, which comes from the same URL query.
@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.

🟡 Changes recommended

Switching away from structured logs can briefly subscribe to the destination resource and incorrectly mark its errors as viewed.

1 open issue
1 resolved since last review

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.

The resource list raises ResourcesChanged on a tab change, before the departing
page is replaced, and its selection is then the destination page's. Since the
page follows the resource list's selection, going from
structuredlogs/resource/api to metrics/resource/worker subscribed to worker's
logs and marked their new errors as viewed without showing them.

While the resource list is on another tab, the page now drops its logs
subscription, keeps the keys it was showing, doesn't refresh the grid, and
doesn't mark any errors as viewed.
@github-actions

Copy link
Copy Markdown
Contributor

Tests selector

13 / 101 PR test projects · 2 PR jobs, from 6 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/Pages/Metrics.razor.cs.

🔧 src/Aspire.Dashboard/Components/Pages/Metrics.razor.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/Pages/MetricsTests.cs (changed test)
→ 1 directly: Aspire.Dashboard.Components.Tests

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

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

Job reasons

Job Triggered by
extension-e2e • src/Aspire.Dashboard/Components/Pages/Metrics.razor.cs, src/Aspire.Dashboard/Components/Pages/StructuredLogs.razor.cs, src/Aspire.Dashboard/Components/Pages/Traces.razor.cs
• affected project Aspire.Dashboard
native-dashboard-validation affected project Aspire.Dashboard

Selection computed for commit ec7fdc0.

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

The interaction between telemetry-only selection, replica renaming, and chart lookup warrants human assessment.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@sebastienros

Copy link
Copy Markdown
Contributor

Manual verification of ec7fdc0

I verified the changes in a live dashboard built from this branch. I used a temporary playground (not committed) whose resources send no telemetry until triggered, so each resource's first telemetry could be timed. Resources: api, worker, cache, rep with two replicas, and two telemetry-only sources that both report service.name=ext with instance IDs one and two.

Area Scenario Result
Logs, telemetry arrives late Opened api's logs before api sent anything, then sent a worker error, api's first log, and another worker error ✅ The page scoped itself to api and shows only its log. worker kept 2 unread errors
Traces, telemetry arrives late Opened cache's traces before cache sent anything, then sent cache and worker requests ✅ Shows only cache's trace
Unread, one resource An api error while viewing api ✅ Shown, with no unread badge
Unread, several selected Selected api and cache, then sent worker and cache errors ✅ worker's unread count went from 2 to 3. cache's error is shown, with no badge
Unread, selection change Selected worker, then rep-fsavenup (no telemetry yet), then sent a worker error ✅ worker has 1 unread error
Unread, tab switch In-app navigation from api's logs to worker's metrics, then errors from both ✅ Both stay unread, and there are no console errors
Metrics, several selected api and worker selected: opened api's chart, switched to Table, changed the duration to 15 minutes ✅ The path stays /metrics/resource/api. The chart's back button still returns to the combined instrument list
Metrics, replica arrives Opened /metrics/resource/rep while only replica kcpqsjuy had telemetry, started the second replica, then changed the view ✅ The chart keeps its data, and the URL becomes /metrics/resource/rep-kcpqsjuy
Metrics, telemetry-only, several selected ext-one and ext-two selected: opened ext-one's chart and changed the view ✅ The path stays /metrics/resource/ext-one, and the data is shown

Not covered manually: the brief windows fixed in the last commits (navigating from all logs to a resource without telemetry, the selection changing before the page's parameters do, and a tab change before the page is replaced). A manual run can only check the state after the navigation. Regression tests that fail without each fix cover these windows.

Separate finding, not caused by this PR: with a single telemetry-only source selected (ext), a second instance arriving renames the source entries to ext-one and ext-two. The resource list's selection is still ext, so its header shows "Resource not found" and no entry is highlighted. The chart keeps working. This is in ResourcesLayout, which this PR doesn't change, so I'm looking at it separately.

This branch has not been deployed

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

Labels

area-dashboard pr-shepherd:fix PR shepherd: request an automated fix pass on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dashboard: preserve resource selection in telemetry pages and metrics charts

4 participants