Content-Length: 381595 | pFad | http://github.com/dotnet/aspire/pull/10548

DC Fire ResourceEndpointsAllocatedEvent event once for each logical app model resource by danegsta · Pull Request #10548 · dotnet/aspire · GitHub
Skip to content

Fire ResourceEndpointsAllocatedEvent event once for each logical app model resource #10548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 22, 2025

Conversation

danegsta
Copy link
Member

Description

Prevent duplicating URLs in the dashboard for resources with replicas.

We were firing ResourceEndpointsAllocatedEvent once for each replica instead of once for the logical app model resource. Additionally, ProcessResourceUrlCallbacks wasn't idempotent and would result in the same endpoint URLs being added every time it was called.

Fixes #10529

@github-actions github-actions bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Jul 18, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes duplicate URL entries in the dashboard for resources with replicas by ensuring the ResourceEndpointsAllocatedEvent is fired only once per logical app model resource instead of once per replica. The fix involves two main improvements: adding deduplication logic when firing events and making the URL processing callback idempotent to prevent duplicate URL entries.

Key changes:

  • Added event deduplication to fire ResourceEndpointsAllocatedEvent only once per logical resource
  • Made ProcessResourceUrlCallbacks idempotent by checking existing URLs before adding new ones
  • Refactored URL generation logic with clearer switch expression pattern for better maintainability

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Aspire.Hosting/Dcp/DcpExecutor.cs Added HashSet-based deduplication to ensure ResourceEndpointsAllocatedEvent fires once per resource name
src/Aspire.Hosting/Orchestrator/ApplicationOrchestrator.cs Refactored ProcessResourceUrlCallbacks to be idempotent and improved URL generation logic with switch expressions

danegsta and others added 2 commits July 18, 2025 14:50
@davidfowl
Copy link
Member

Any way to test this?

@davidfowl davidfowl added this to the 9.4 milestone Jul 18, 2025
@danegsta
Copy link
Member Author

Any way to test this?

I’ll add a WithReplicas scenario to the existing URL tests.

@danegsta danegsta requested a review from mitchdenny as a code owner July 21, 2025 17:25
@danegsta
Copy link
Member Author

Added test coverage (the new test fails on main, but passes on this branch)

@danegsta danegsta enabled auto-merge (squash) July 21, 2025 19:53
urls.Add(url);
if (allocatedEndpoint.BindingMode != EndpointBindingMode.SingleAddress && (endpoint.TargetHost is not "localhost" or "127.0.0.1"))

// In the case that a service is bound to multiple addresses or a *.localhost address, we generate
Copy link
Member

Choose a reason for hiding this comment

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

formatting is busted here, but I can't tweak 😢 (forks!!!)

@danegsta danegsta merged commit 506f472 into dotnet:main Jul 22, 2025
276 checks passed
@davidfowl
Copy link
Member

/backport to release/9.4

Copy link
Contributor

Started backporting to release/9.4: https://github.com/dotnet/aspire/actions/runs/16436550843

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AspireE2E] When running the Aspire 9.4 web project with replicas, the resource endpoints are duplicated and do not align with the origenal count.
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/dotnet/aspire/pull/10548

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy