Skip to content
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 ClickHouse HealthCheck support #2315

Merged
merged 7 commits into from
Dec 11, 2024
Merged

Conversation

smbecker
Copy link
Contributor

What this PR does / why we need it: Adds health check support for ClickHouse

Does this PR introduce a user-facing change?: It adds a new package to support ClickHouse health checks

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Unit tests passing
  • End-to-end tests passing
  • Extended the documentation
  • Provided sample for the feature

@github-actions github-actions bot added github_actions Pull requests that update Github_actions code docs labels Nov 11, 2024
Copy link
Collaborator

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

@smbecker big thanks for your contribution! It looks like a step in the right direction, we just need to clarify how ClickHouseConnection should be used to ensure we provide the right API and of course solve the copy-paste errors.

src/HealthChecks.ClickHouse/README.md Outdated Show resolved Hide resolved
{
try
{
await using var connection = _options.ConnectionFactory?.Invoke() ?? new ClickHouseConnection(_options.ConnectionString);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are the recommendations for using ClickHouseConnection? Namely:

  • is it thread safe?
  • does it have a built-in pool of connections? (when we execute new ClickHouseConnection(_options.ConnectionString), does it always create a new coonection?)

I need to get a better understanding of how it should be used before I approve the shape of the public API for this DB.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is it thread safe?

Looking at the code, instance methods on ClickHouseConnection do not appear to be thread-safe. However, commands do appear to be thread-safe in that they just execute HttpRequestMessages against the owned HttpClient.

does it have a built-in pool of connections?

It does not support pooling directly. However, when creating a ClickHouseConnection with a passed in HttpClient or IHttpClientFactory, you can take advantage of pooling within the HttpClient.

I could follow a similar pattern to Npgsql if/when this PR is merged.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@smbecker thank you for checking everything and contributing a PR!

Based on what you wrote and https://github.com/DarkWanderer/ClickHouse.Client/wiki/Connection-lifetime-&-pooling#recommendations:

If an application operates on large volumes of transactions and requires to create/destroy ClickHouseConnection objects often, it is recommended to use IHttpClientFactory or a static instance of HttpClient to manage connections

I wonder if we should do the following:

  1. Recommend the users to use IHttpClientFactory in the README.md and show an example that registers ClickHouseConnection factory method along with the IHttpClientFactory (people just copy this code most of the time, this is why I would like it to be the "right" way of doing things)
  2. Have a single extension method that takes a mandatory Func<IServiceProvider, ClickHouseConnection> connectionFactory argument. It allows the user to obtain all kinds of configuration options from the service provider and forces them to create ClickHouseConnection on their own.
public static IHealthChecksBuilder AddClickHouse(
    this IHealthChecksBuilder builder,
    Func<IServiceProvider, ClickHouseConnection> connectionFactory,
    string healthQuery = HEALTH_QUERY,
    Action<ClickHouseConnection>? configure = null,
    string? name = default,
    HealthStatus? failureStatus = default,
    IEnumerable<string>? tags = default,
    TimeSpan? timeout = default)

@smbecker what do you think?

Copy link
Collaborator

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

PTAL at my comments. Overall the PR is high quality contribution, I just want us to make sure we introduce the best API design from day one.

Again, thank you @smbecker !

{
try
{
await using var connection = _options.ConnectionFactory?.Invoke() ?? new ClickHouseConnection(_options.ConnectionString);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@smbecker thank you for checking everything and contributing a PR!

Based on what you wrote and https://github.com/DarkWanderer/ClickHouse.Client/wiki/Connection-lifetime-&-pooling#recommendations:

If an application operates on large volumes of transactions and requires to create/destroy ClickHouseConnection objects often, it is recommended to use IHttpClientFactory or a static instance of HttpClient to manage connections

I wonder if we should do the following:

  1. Recommend the users to use IHttpClientFactory in the README.md and show an example that registers ClickHouseConnection factory method along with the IHttpClientFactory (people just copy this code most of the time, this is why I would like it to be the "right" way of doing things)
  2. Have a single extension method that takes a mandatory Func<IServiceProvider, ClickHouseConnection> connectionFactory argument. It allows the user to obtain all kinds of configuration options from the service provider and forces them to create ClickHouseConnection on their own.
public static IHealthChecksBuilder AddClickHouse(
    this IHealthChecksBuilder builder,
    Func<IServiceProvider, ClickHouseConnection> connectionFactory,
    string healthQuery = HEALTH_QUERY,
    Action<ClickHouseConnection>? configure = null,
    string? name = default,
    HealthStatus? failureStatus = default,
    IEnumerable<string>? tags = default,
    TimeSpan? timeout = default)

@smbecker what do you think?

.github/workflows/healthchecks_clickhouse_ci.yml Outdated Show resolved Hide resolved
.github/workflows/healthchecks_clickhouse_ci.yml Outdated Show resolved Hide resolved
build/versions.props Outdated Show resolved Hide resolved
src/HealthChecks.ClickHouse/HealthChecks.ClickHouse.csproj Outdated Show resolved Hide resolved
src/HealthChecks.ClickHouse/HealthChecks.ClickHouse.csproj Outdated Show resolved Hide resolved
src/HealthChecks.ClickHouse/README.md Outdated Show resolved Hide resolved
@smbecker
Copy link
Contributor Author

I took your recommendations for the most part. Please take a look and let me know if I missed anything.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.65%. Comparing base (72d9abf) to head (8b98bd6).
Report is 12 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2315      +/-   ##
==========================================
- Coverage   66.88%   66.65%   -0.24%     
==========================================
  Files         268      255      -13     
  Lines        8730     8600     -130     
  Branches      631      617      -14     
==========================================
- Hits         5839     5732     -107     
+ Misses       2723     2702      -21     
+ Partials      168      166       -2     
Flag Coverage Δ
ApplicationStatus 28.67% <ø> (ø)
ArangoDb 28.30% <ø> (ø)
Aws.S3 15.52% <ø> (ø)
Aws.SecretsManager 15.82% <ø> (ø)
Aws.Sns 15.97% <ø> (ø)
Aws.Sqs 16.66% <ø> (ø)
Aws.SystemsManager 15.82% <ø> (ø)
Azure.IoTHub 13.82% <ø> (ø)
AzureApplicationInsights 16.56% <ø> (ø)
AzureBlobStorage ?
AzureDigitalTwin 37.15% <ø> (ø)
AzureEventHubs ?
AzureFileStorage ?
AzureKeyVault 30.48% <ø> (ø)
AzureQueueStorage ?
AzureSearch 17.60% <ø> (ø)
AzureServiceBus 72.48% <ø> (ø)
AzureTableStorage ?
Consul 24.32% <ø> (ø)
CosmosDb 29.45% <ø> (ø)
Dapr 14.50% <ø> (ø)
DynamoDb 13.29% <ø> (ø)
Elasticsearch 47.66% <ø> (ø)
EventStore 65.14% <ø> (ø)
EventStore.gRPC 25.51% <ø> (ø)
Gcp.CloudFirestore 13.33% <ø> (ø)
Gremlin 25.00% <ø> (ø)
Hangfire 12.10% <ø> (ø)
IbmMQ 30.76% <ø> (ø)
InfluxDB 15.54% <ø> (ø)
Kafka 23.52% <ø> (ø)
Kubernetes 41.54% <ø> (ø)
Milvus 16.78% <ø> (ø)
MongoDb 36.25% <ø> (+3.40%) ⬆️
MySql 33.33% <ø> (ø)
Nats 72.77% <ø> (ø)
Npgsql 44.22% <ø> (ø)
OpenIdConnectServer 42.48% <ø> (ø)
Oracle 63.92% <ø> (ø)
Prometheus.Metrics 29.80% <ø> (ø)
Publisher.ApplicationInsights 15.27% <ø> (ø)
Publisher.CloudWatch 20.33% <ø> (ø)
Publisher.Datadog 17.19% <ø> (ø)
Publisher.Prometheus 18.75% <ø> (ø)
Publisher.Seq 40.74% <ø> (ø)
Qdrant 18.25% <ø> (ø)
RabbitMQ 58.33% <ø> (+7.69%) ⬆️
Redis 68.47% <ø> (ø)
SendGrid 17.21% <ø> (ø)
SignalR 25.97% <ø> (ø)
SqlServer 30.43% <ø> (ø)
Sqlite 25.88% <ø> (ø)
System 43.58% <ø> (ø)
UI 65.87% <ø> (ø)
Uris 62.14% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

LGTM, thank you very much for your contribution @smbecker !

@adamsitnik adamsitnik merged commit e8730db into Xabaril:master Dec 11, 2024
55 of 56 checks passed
@adamsitnik adamsitnik added this to the 9.0 milestone Dec 11, 2024
@smbecker
Copy link
Contributor Author

Thanks for collaborating on it with me!

@smbecker smbecker deleted the sb-clickhouse branch December 11, 2024 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs github_actions Pull requests that update Github_actions code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants