-
Notifications
You must be signed in to change notification settings - Fork 803
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
Add CassandraDb HealthCheck support #2174
base: master
Are you sure you want to change the base?
Conversation
@dotnet-policy-service agree |
I'd love to! But I haven't written any .NET code in years, and I'm not a maintainer of this project, sorry. FWIW the code LGTM. |
@sungam3r Could you review my PR? |
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.
Overall it's welcomed and high quality contribution. Thank you @djesusnet !
We need to agree on the shape of the API. Please see my comment and let me know what you think about it.
{ | ||
try | ||
{ | ||
var builder = Cluster.Builder().AddContactPoint(_options.ContactPoint); |
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.
With the current approach, we would build a new instance every time the health check would be invoked. Which I expect would be bad for performance and could even lead to some resource leaks (nothing is getting disposed here).
We have changed many of our health checks similar to what I described in #2040: for all the client instances that are thread-safe and should be used as singleton, we don't create our own instances, but expect it to be resolved from the DI (so the user registers a singleton and we just resolve).
I've done some quick web search, but have failed to find dependency injection best practices for working with the C# client of CassandarDb.
Should we just expect the users to inject the cluster into the DI and solve it?
For example this is what we do for MongoDB:
We allow the users to specify a Func<IServiceProvider, IMongoClient>
factory:
Line 33 in 36bf171
Func<IServiceProvider, IMongoClient>? clientFactory = default, |
when it's not specified, we just try to resolve it from the DI container:
Line 51 in 36bf171
IMongoClient client = clientFactory?.Invoke(sp) ?? sp.GetService<MongoClient>() ?? sp.GetRequiredService<IMongoClient>(); |
What this PR does / why we need it: Adds health check support for CassandraDb
Does this PR introduce a user-facing change?: It adds a new package to support CassandraDb health checks
Please make sure you've completed the relevant tasks for this PR, out of the following list: