-
Notifications
You must be signed in to change notification settings - Fork 647
Remove dependencies on AfterEndpointsAllocatedEvent #9598
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
Conversation
There was a problem hiding this 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 deprecates AfterEndpointsAllocatedEvent
in favor of the more granular BeforeResourceStartedEvent
and ResourceEndpointsAllocatedEvent
, updating internal subscriptions and tests accordingly.
- Mark
AfterEndpointsAllocatedEvent
as[Obsolete]
and update all internal subscribe calls. - Replace test uses of the obsolete event with the appropriate new events (or suppress warnings when testing legacy behavior).
- Remove obsolete event publishing in many tests and adjust builder extensions to use the new event model.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
tests/Aspire.Hosting.Tests/WithUrlsTests.cs | Updated subscription from AfterEndpointsAllocatedEvent to ResourceEndpointsAllocatedEvent . |
tests/Aspire.Hosting.Tests/Eventing/DistributedApplicationBuilderEventingTests.cs | Added pragmas to suppress warnings when subscribing to the obsolete event. |
tests/Aspire.Hosting.Redis.Tests/AddRedisTests.cs | Removed obsolete event publish calls (needs replacement in some tests). |
tests/Aspire.Hosting.Qdrant.Tests/QdrantFunctionalTests.cs | Switched subscription to ConnectionStringAvailableEvent . |
tests/Aspire.Hosting.PostgreSQL.Tests/AddPostgresTests.cs | Removed obsolete event publishes and changed test signature. |
tests/Aspire.Hosting.MySql.Tests/AddMySqlTests.cs | Updated to publish BeforeResourceStartedEvent for phpMyAdmin. |
src/Aspire.Hosting/ResourceBuilderExtensions.cs | Rewired health-check subscribe to ResourceEndpointsAllocatedEvent . |
src/Aspire.Hosting/Orchestrator/ApplicationOrchestrator.cs | Replaced subscribe to obsolete event; updated handler signature. |
src/Aspire.Hosting/Lifecycle/IDistributedApplicationLifecycleHook.cs | Introduced new AfterEndpointsAllocatedAsync default method. |
src/Aspire.Hosting/ApplicationModel/AfterEndpointsAllocatedEvent.cs | Marked the event class as [Obsolete] . |
src/Aspire.Hosting.Redis/RedisBuilderExtensions.cs | Switched commander extension to BeforeResourceStartedEvent . |
src/Aspire.Hosting.MySql/MySqlBuilderExtensions.cs | Replaced subscribe call to use new event for phpMyAdmin. |
src/Aspire.Hosting.Kafka/KafkaBuilderExtensions.cs | Updated Kafka UI subscribe to BeforeResourceStartedEvent . |
Comments suppressed due to low confidence (7)
tests/Aspire.Hosting.Tests/WithUrlsTests.cs:56
- The test name
WithUrlsCallsCallbackAfterBeforeResourceStartedEvent
suggests it should subscribe toBeforeResourceStartedEvent
, but the code usesResourceEndpointsAllocatedEvent
. Either rename the test to match the new event or switch toBeforeResourceStartedEvent
if that was intended.
builder.Eventing.Subscribe<ResourceEndpointsAllocatedEvent>(projectA.Resource, (e, ct) =>
tests/Aspire.Hosting.Redis.Tests/AddRedisTests.cs:303
- After removing the obsolete publish of
AfterEndpointsAllocatedEvent
, this test no longer triggers the resource-specific event. Add aawait builder.Eventing.PublishAsync<BeforeResourceStartedEvent>(new(redisInsight, app.Services));
before asserting environment variables.
var redisInsight = Assert.Single(builder.Resources.OfType<RedisInsightResource>());
src/Aspire.Hosting/Orchestrator/ApplicationOrchestrator.cs:98
- This still publishes the obsolete
AfterEndpointsAllocatedEvent
. It should be replaced withResourceEndpointsAllocatedEvent
(or other resource-specific events) to align with the new deprecation model.
await _eventing.PublishAsync(afterEndpointsAllocatedEvent, context.CancellationToken).ConfigureAwait(false);
src/Aspire.Hosting.Redis/RedisBuilderExtensions.cs:172
- The variable
hostString
is no longer declared in scope because theif
block was removed. Restore declaration or conditional check to avoid a compilation error.
hostsVariableBuilder.Append(hostString);
src/Aspire.Hosting.Kafka/KafkaBuilderExtensions.cs:118
- [nitpick] The original check for
InternalEndpoint.IsAllocated
was removed. Consider re-introducing a check so you only configure the UI for resources whose endpoints are ready.
var endpoint = kafkaResource.InternalEndpoint;
src/Aspire.Hosting/Lifecycle/IDistributedApplicationLifecycleHook.cs:31
- Since
AfterEndpointsAllocatedEvent
is deprecated, mark this lifecycle hook method with[Obsolete]
to guide implementers toward the replacement events.
Task AfterEndpointsAllocatedAsync(DistributedApplicationModel appModel, CancellationToken cancellationToken = default)
tests/Aspire.Hosting.PostgreSQL.Tests/AddPostgresTests.cs:372
- This test was converted to
void
and no longer awaits event publishing. If you intend to publishBeforeResourceStartedEvent
forpgadmin
, mark the testasync Task
andawait
the publish call to ensure setup runs before assertions.
public void WithPgAdminAddsContainer()
src/Aspire.Hosting/ApplicationModel/AfterEndpointsAllocatedEvent.cs
Outdated
Show resolved
Hide resolved
…nt.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@@ -26,6 +26,7 @@ namespace Aspire.Hosting.ApplicationModel; | |||
/// </code> | |||
/// </example> | |||
/// </remarks> | |||
[Obsolete("The AfterEndpointsAllocatedEvent is deprecated and will be removed in a future version. Use the resource specific events BeforeResourceStartedEvent or ResourceEndpointsAllocatedEvent instead depending on your needs.")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Aaronontheweb @Alirexaa big change coming.
src/Aspire.Hosting/Lifecycle/IDistributedApplicationLifecycleHook.cs
Outdated
Show resolved
Hide resolved
@@ -240,48 +242,45 @@ private async Task ProcessUrls(IResource resource, CancellationToken cancellatio | |||
} | |||
} | |||
|
|||
private Task ProcessResourcesWithoutLifetime(AfterEndpointsAllocatedEvent @event, CancellationToken cancellationToken) | |||
private async Task ProcessResourcesWithoutLifetime(ResourceEndpointsAllocatedEvent @event, CancellationToken cancellationToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a sketchiest change 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s definitely the one that stood out the most, but at least with the current event behavior/timing it should behave the same.
Can you also deprecate |
Main headache there is that marking the interface method as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets get this in to see if there are any regressions
@balachir can you make sure to spend extra time on potential regressions here? These are all of the ui tools we have. |
@mitchdenny you should be aware of this change. @DamianEdwards you too. |
@aaronpowell heads up. Biggish change in 9.4 |
@v-elenafeng please see comments above. Please work with your team to do extra and focused ET when we validate this change for 9.4. And also prioritize this validation for early next week so that we can catch any issues soon. |
Woah this will have a bunch of ramifications. I'm working on a separate change to modify how URL processing works and that includes making custom resources responsible for the firing of their own |
This is necessary to support running persistent containers without proxies by default, as proxyless containers have async endpoint availability (if a random host port is used, the container resource has to be created before the endpoint is actually allocated if no proxy is used). The main headache is that lots of code assumes |
Description
In order to support proxyless persistent containers by default (and dynamic endpoint allocation in general), the
AfterEndpointsAllocatedEvent
is going to need to be deprecated. The current eventing model assumes that all endpoinst are allocated before any resources are created, but to properly support persistent containers, we'll have to break that assumption. This means that some endpoints may not become fully allocated until after resource creation starts.This PR marks
AfterEndpointsAllocatedEvent
as[Obsolete]
with instructions to use the resource specificBeforeResourceStartedEvent
orResourceEndpointsAllocatedEvent
events as appropriate. Additionally it replaces all internal usage ofAfterEndpointsAllocatedEvent
with one of the two previous events.The one remaining scenario that will need to be reworked is the
AfterEndpointsAllocatedAsync
callback inIDistributedApplicationLifecycleHook
. The only internal usage is inDevcontainerPortForwardingLifecycleHook
, but that will likely need to be rewritten to be event based too.Fixes # (issue)
Checklist
IDistributedApplicationLifecycleHook
usage)<remarks />
and<code />
elements on your triple slash comments?doc-idea
templatebreaking-change
templatediagnostic
template