Skip to content

Eventhubs health check (retargeted for main)#4139

Merged
davidfowl merged 31 commits intomicrosoft:mainfrom
oising:eventhubs-healthcheck-main
Feb 11, 2025
Merged

Eventhubs health check (retargeted for main)#4139
davidfowl merged 31 commits intomicrosoft:mainfrom
oising:eventhubs-healthcheck-main

Conversation

@oising
Copy link
Copy Markdown
Contributor

@oising oising commented May 10, 2024

Original: #4050

Closes #3980

Microsoft Reviewers: Open in CodeFlow

@ghost ghost added the area-codeflow for labeling automated codeflow. intentionally a different color! label May 10, 2024
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label May 10, 2024
@eerhardt eerhardt requested a review from sebastienros May 17, 2024 22:13
Comment thread src/Components/Aspire.Azure.Messaging.EventHubs/EventHubsComponent.cs Outdated
Comment thread src/Components/Aspire.Azure.Messaging.EventHubs/EventHubsComponent.cs Outdated
@oising oising requested a review from eerhardt June 4, 2024 16:58
@eerhardt eerhardt requested a review from radical as a code owner July 10, 2024 16:17
Copy link
Copy Markdown
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, @oising!

I merged the latest main into this PR, and made some minor PR feedback. I think the product changes look good.

Is there a way we can write some tests for this functionality? I think that is all that is needed in order to merge this.

@radical radical added area-integrations Issues pertaining to Aspire Integrations packages and removed area-codeflow for labeling automated codeflow. intentionally a different color! labels Jul 24, 2024
@davidfowl
Copy link
Copy Markdown
Contributor

@eerhardt Do we still want this PR?

@eerhardt
Copy link
Copy Markdown
Member

@eerhardt Do we still want this PR?

Yes, I think so. Just looking for tests to be added.

@oising
Copy link
Copy Markdown
Contributor Author

oising commented Sep 12, 2024

@eerhardt Do we still want this PR?

Yes, I think so. Just looking for tests to be added.

I'm just back from vacation. I'll look at this over the weekend. /cc @davidfowl

@davidfowl
Copy link
Copy Markdown
Contributor

davidfowl commented Jan 14, 2025

@eerhardt eerhardt self-requested a review January 14, 2025 19:17
@eerhardt
Copy link
Copy Markdown
Member

We have this for the hosting integration but not the client integration?

https://github.com/dotnet/aspire/blob/66465d1e19f20616be209d4d77a019aa4b68ea75/src/Aspire.Hosting.Azure.EventHubs/AzureEventHubsExtensions.cs#L213

@eerhardt @sebastienros ?

Correct - we added it to the hosting integration when we did the emulator work. This PR is adding the health check to the client integration.

@danmoseley
Copy link
Copy Markdown
Member

having a go at the test. https://github.com/dotnet/aspire/compare/main...danmoseley:aspire:eventhubs-healthcheck-main2?expand=1

@danmoseley danmoseley force-pushed the eventhubs-healthcheck-main branch from e186474 to f05024c Compare February 7, 2025 23:43
@danmoseley
Copy link
Copy Markdown
Member

Some of the tests still failing and I haven't figured out why. It seems those components are not getting registered correctly. Might need help.

@danmoseley danmoseley added this to the 9.1 milestone Feb 9, 2025
[assembly: ConfigurationSchema("Aspire:Azure:Messaging:EventHubs:PartitionReceiver", typeof(AzureMessagingEventHubsPartitionReceiverSettings))]
[assembly: ConfigurationSchema("Aspire:Azure:Messaging:EventHubs:PartitionReceiver:ClientOptions", typeof(PartitionReceiverOptions))]

[assembly: ConfigurationSchema("Aspire:Azure:Messaging:EventHubs:EventHubBufferedProducerClient", typeof(AzureMessagingEventHubsBufferedProducerSettings))]
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.

@eerhardt I don't think this was ignored on purpose, correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The support for this client was added by someone other than myself, with a small PR. They weren't familiar with the codebase and I would say it's 99% sure they didn't know about this plumbing. I can't remember who it was, but it would probably show up in PRs if you search for that client type.

@davidfowl davidfowl merged commit 849f74a into microsoft:main Feb 11, 2025
Comment on lines +33 to +35
var producerClient = !string.IsNullOrEmpty(settings.ConnectionString) ?
new EventHubProducerClient(settings.ConnectionString, producerClientOptions) :
new EventHubProducerClient(settings.FullyQualifiedNamespace, settings.EventHubName, settings.Credential ?? new DefaultAzureCredential(), producerClientOptions);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This isn't great because it will create a new EventHubProducerClient instance each time the health is checked. EventHubProducerClient establishes an amqp connection, which isn't cheap.

I'm not sure, but I don't believe the client is getting disposed. So we might risk having memory issues here.

cc @oising @sebastienros

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's surprising -- I assumed CreateHealthCheck would be called once just to create it, and then subsequent calls happen on the return instance. Odd pattern?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TBH - I had this intuition at first as well. But unfortunately, that's not how HealthChecks works in ASP.NET Core.

See

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TBH - I had this intuition at first as well. But unfortunately, that's not how HealthChecks works in ASP.NET Core.

Urgh. What do you think of using the event hub REST API as a health check instead of instantiating heavy clients?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In my mind, the ideal health check follows this logic:
https://github.com/dotnet/aspire/tree/main/src/Components#health-checks. Specifically:

Consider whether the Health Check should reuse the same client object registered in DI by the component or not. Reusing the same client object has the advantages of getting the same configuration, logging, etc during the health check.

From @jsquire's comment here: Xabaril/AspNetCore.Diagnostics.HealthChecks#2258 (comment) The first bullet aligns the most with this thinking:

Is it something client-focused that indicates "yes, the processor is still functioning and attempting to read. If you have no events flowing, don't panic there's just no data in the partitions."

The closer we can get to seeing if the processor is still functioning, the better IMO.

I think we have a couple options:

  • Keep going down the route of using the producer client as the health check sentinel. But make it cached, so we aren't creating new heavy-weight clients
  • Use the REST API as a health check
  • Only have a health check for the producer client until we have a plan for health checks for consumer/receiver clients

For .NET Aspire 9.1, the top option feels like it is the path of least resistence. We already decided to use the producer client, let's just make it better.

Copy link
Copy Markdown
Contributor Author

@oising oising Feb 12, 2025

Choose a reason for hiding this comment

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

Definitely worth checking the other health checks for similar pitfalls... Lazy<T> all the things?

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

Labels

area-integrations Issues pertaining to Aspire Integrations packages azure Issues associated specifically with scenarios tied to using Azure azure-eventhubs Issues related to Azure Event Hubs integration community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EventHub component does not have health check

6 participants