Skip to content

Use scheme instead of endpoint name when registering service discovery environment variables#14625

Closed
danegsta wants to merge 1 commit into
microsoft:mainfrom
danegsta:danegsta/serviceDiscovery
Closed

Use scheme instead of endpoint name when registering service discovery environment variables#14625
danegsta wants to merge 1 commit into
microsoft:mainfrom
danegsta:danegsta/serviceDiscovery

Conversation

@danegsta

Copy link
Copy Markdown
Member

Description

Updates the service discovery environment variable names to use the endpoint scheme rather than the endpoint name when building the environment variable name (i.e. services__{service name}__{scheme}__0 instead of services__{service name}__{endpoint name}__0.

Fixes #14411

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
      • 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
    • 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
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No - this is a bug fix and doesn't invalidate the current service discovery docs at aspire.dev

@danegsta
danegsta requested a review from eerhardt February 23, 2026 22:02
@danegsta
danegsta requested a review from mitchdenny as a code owner February 23, 2026 22:02
Copilot AI review requested due to automatic review settings February 23, 2026 22:02
@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/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 14625

Or

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

@danegsta

Copy link
Copy Markdown
Member Author

Closing this as I accidentally opened against main instead of release/13.2. Superseded by #14626.

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.

Pull request overview

This PR fixes service discovery environment variable naming by using the endpoint scheme (e.g., https) rather than the endpoint name when emitting services__... keys, aligning with .NET service discovery expectations and addressing the reported Python/uvicorn discovery regression.

Changes:

  • Emit service discovery keys as services__{serviceName}__{scheme}__{index} and track per-scheme indices to handle multiple endpoints sharing a scheme.
  • Update unit tests and Docker/Kubernetes publisher snapshots to reflect the new key format and indexing behavior.
  • Update related XML documentation/comments to reference {endpointScheme} (partially; one doc spot still mentions {endpointName}).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Aspire.Hosting/ResourceBuilderExtensions.cs Changes service discovery env var key generation to use endpoint scheme and handle per-scheme indexing; updates some docs.
src/Aspire.Hosting/ApplicationModel/ReferenceEnvironmentInjectionFlags.cs Updates enum doc comment to reflect scheme-based service discovery key format.
tests/Aspire.Hosting.Tests/WithReferenceTests.cs Updates assertions for scheme-based services__... keys and scheme-collision indexing.
tests/Aspire.Hosting.Kubernetes.Tests/Snapshots/KubernetesPublisherTests.KubernetesWithProjectResources#01.verified.yaml Updates Helm values snapshot keys/indexing for scheme-based service discovery env vars.
tests/Aspire.Hosting.Kubernetes.Tests/Snapshots/KubernetesPublisherTests.KubernetesWithProjectResources#06.verified.yaml Updates manifest snapshot keys/indexing for scheme-based service discovery env vars.
tests/Aspire.Hosting.Docker.Tests/Snapshots/DockerComposePublisherTests.DockerComposeWithProjectResources.verified.yaml Updates docker-compose snapshot keys/indexing for scheme-based service discovery env vars.

Comment on lines 790 to 794
/// <summary>
/// Injects service discovery and endpoint information from the specified endpoint into the project resource using the source resource's name as the service name.
/// Each endpoint uri will be injected using the format defined by the <see cref="ReferenceEnvironmentInjectionAnnotation"/> on the destination resource, i.e.
/// either "services__{name}__{endpointName}__{endpointIndex}={uriString}" for .NET service discovery, or "{NAME}_{ENDPOINT}={uri}" for endpoint injection.
/// </summary>

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

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

The XML doc for this overload still describes service discovery keys as using the endpoint name segment, but the implementation (and other WithReference overload docs) now use the endpoint scheme segment. Update this doc string to match the new key format (services__{name}{endpointScheme}{endpointIndex}).

Copilot uses AI. Check for mistakes.
@@ -1,4 +1,4 @@
---
---

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

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

This snapshot file now starts with a UTF-8 BOM character (U+FEFF), which can cause unnecessary diffs and can confuse YAML tooling/parsers. Please remove the BOM so the first line starts with '---' only.

Suggested change
---
---

Copilot uses AI. Check for mistakes.
@@ -1,4 +1,4 @@
parameters:
parameters:

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

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

This snapshot file now starts with a UTF-8 BOM character (U+FEFF) before 'parameters:'. Please remove the BOM to keep encoding consistent with other snapshots and avoid YAML key/name issues.

Suggested change
parameters:
parameters:

Copilot uses AI. Check for mistakes.
@@ -1,4 +1,4 @@
services:
services:

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

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

This snapshot file now starts with a UTF-8 BOM character (U+FEFF) before 'services:'. Please remove the BOM to avoid inconsistent encoding and unnecessary diffs.

Suggested change
services:
services:

Copilot uses AI. Check for mistakes.
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Service discovery seems to broken for python/uvicorn resources

2 participants