Skip to content

Conversation

@danegsta
Copy link
Member

When dealing with HostUrl values (such as for the otel endpoint references) we need to consider that we may have to remap both the address and port if in a tunnel scenario. This PR allows us to find a referenced by port and remap to the equivalent endpoint on a separate network context.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 30, 2025

🚀 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/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12521

Or

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

@danegsta danegsta requested a review from mitchdenny as a code owner October 30, 2025 16:40
Copy link
Contributor

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 refactors network context handling in value resolution by consolidating the networkContext parameter into the ValueProviderContext object. The main change is replacing the separate NetworkIdentifier? networkContext parameter with logic that derives the network identifier from the context using a new GetNetworkIdentifier() extension method.

Key changes:

  • Introduced ValueProviderExtensions.GetNetworkIdentifier() helper to extract network context from ValueProviderContext
  • Removed networkContext parameters from multiple methods in ResourceExtensions.cs and replaced calls with context-based resolution
  • Updated ValueProviderContext to include ExecutionContext property instead of Services
  • Enhanced HostUrl with more sophisticated container host name mapping logic that accounts for DCP configuration

Reviewed Changes

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

Show a summary per file
File Description
src/Aspire.Hosting/ApplicationModel/ValueProviderExtensions.cs New extension method to extract NetworkIdentifier from ValueProviderContext
src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs Removed networkContext parameters from multiple methods; updated to use context-based resolution
src/Aspire.Hosting/ApplicationModel/IValueProvider.cs Changed ValueProviderContext.Services to ExecutionContext
src/Aspire.Hosting/ApplicationModel/HostUrl.cs Enhanced logic to resolve container host names using DCP configuration and endpoint mapping
src/Aspire.Hosting/ApplicationModel/EndpointReference.cs Simplified network context resolution using GetNetworkIdentifier helper
src/Aspire.Hosting/ApplicationModel/ConnectionStringReference.cs Removed intermediate method and simplified to pass context directly
src/Aspire.Hosting/ApplicationModel/IResourceWithConnectionString.cs Simplified GetValueAsync to pass context through directly
src/Aspire.Hosting/ApplicationModel/ReferenceExpression.cs Minor code style change using target-typed new expression
src/Aspire.Hosting/Dcp/DcpExecutor.cs Updated container host name logic to use DCP info; cleaned up whitespace; added executionContext parameter
src/Aspire.Hosting/OtlpConfigurationExtensions.cs Removed trailing whitespace

Copy link
Member

@karolz-ms karolz-ms left a comment

Choose a reason for hiding this comment

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

Looks great overall, just a few questions and suggestions

@danegsta danegsta requested a review from ReubenBond as a code owner October 30, 2025 22:25
@danegsta danegsta enabled auto-merge (squash) October 31, 2025 00:37
{
// We need to consider that both the host and port may need to be remapped
var model = context.ExecutionContext.ServiceProvider.GetRequiredService<DistributedApplicationModel>();
var targetEndpoint = model.Resources.Where(r => !r.IsContainer())
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to scan the entire model??

Copy link
Member Author

Choose a reason for hiding this comment

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

All we know in HostUrl is an address and port, but both the address and port may need to change if running in a container. So I'm finding out if it's the URL to an existing endpoint and then mapping that to the appropriate container network endpoint if one exists. Ideally we'd just have a way to get the endpoints from the dashboard directly here and deprecate HostUrl entirely, but that's a larger change.

@danegsta danegsta disabled auto-merge October 31, 2025 05:34
@danegsta danegsta merged commit fe02826 into dotnet:main Oct 31, 2025
296 checks passed
@danegsta
Copy link
Member Author

/backport to release/13.0

@github-actions
Copy link
Contributor

Started backporting to release/13.0: https://github.com/dotnet/aspire/actions/runs/18964385455

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants