Skip to content

chore: improve ClickHouse read connection pool settings / behavior - #3871

Merged
amokan merged 9 commits into
mainfrom
adammokan/o11y-2410-review-clickhouse-read-connection-pool-behavior
Aug 26, 2026
Merged

chore: improve ClickHouse read connection pool settings / behavior#3871
amokan merged 9 commits into
mainfrom
adammokan/o11y-2410-review-clickhouse-read-connection-pool-behavior

Conversation

@amokan

@amokan amokan commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

It became obvious when configuring labeled read clusters that the connection pool situation was not flexible enough to support us in production.

This PR makes some sane adjustments to that area:

  • Lowers the @ch_idle_interval from 5s -> 3s to reduce churn
  • Reworks the pool sizing for queries entirely:
    • pool_size config removed from ClickHouse backends as it was only used for queries and was not labeled appropriately in the UX
    • Adds read_pool_size config (default of 50) option. This is the single source of truth for read pool sizing for every scenario other than labeled read pools
    • Adds labeled_read_pool_size config (default 32) for labeled read clusters. The exception is that the default labeled read cluster will always use the read_pool_size value.
  • Adds new :pool_exhausted error handling
  • Slow-checkout log now includes a read_cluster with the relevant label for a value
  • Adds new [:logflare, :clickhouse, :read_pool, :checkout] telemetry event
  • Removes stale pool_size: 3 from config.exs

Also adds a version bump to 1.50.7

amokan added 3 commits August 24, 2026 14:25
…CH config UX (wasnt used for that anyhow); adds `read_pool_size` config option to CH backends with a default of 50; adds optional `labeled_read_pool_size` for non-default labeled read clusters
Comment thread lib/logflare_web/live/backends/read_cluster_urls_component.ex
Comment on lines +33 to +34
@read_pool_size 50
@labeled_read_pool_size 32

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.

Suggested change
@read_pool_size 50
@labeled_read_pool_size 32
@default_read_pool_size 50
@default_labeled_read_pool_size 32

"ClickHouse slow connection checkout: waited #{pool_ms}ms for a pool connection",
backend_id: backend_id
backend_id: backend_id,
read_cluster: label

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.

would be good to nest this under clickhouse.read_cluster

"ClickHouse slow connection checkout: waited #{pool_ms}ms for a pool connection",
backend_id: backend_id
backend_id: backend_id,
read_cluster: label

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.

Suggested change
read_cluster: label
clickhouse: %{read_cluster: label}

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.

So this gets a little funky on tests (and consistency) due to the dev/test env using the standard Logger which effectively drops the key because it returns nil for any value that does not have a String.Chars impl (like a map).

So what I did as a compromise is prefix these with clickhouse_ - so rather than read_cluster: label -> clickhouse_read_cluster: label.

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.

👍 ypu that works

@@ -15,7 +15,7 @@ defmodule LogflareWeb.Live.DisplayHelpers do
"""
def sanitize_backend_config(config) when is_map(config) do

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.

for future, probably want to let the Adaptor handle this declaration based on their config keys

amokan and others added 4 commits August 26, 2026 11:00
Addresses PR review feedback on `connection_manager.ex`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Addresses PR review feedback. Telemetry metadata stays flat since
`lib/telemetry.ex` tags on top-level `:read_cluster`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…gger calls in the same adaptor consistent with the same prefix
@amokan
amokan requested a review from Ziinc August 26, 2026 18:21
@amokan
amokan merged commit c4034cd into main Aug 26, 2026
13 checks passed
@amokan
amokan deleted the adammokan/o11y-2410-review-clickhouse-read-connection-pool-behavior branch August 26, 2026 20:13
amokan added a commit that referenced this pull request Aug 26, 2026
…nd-config-options-to-support-a

Resolves conflicts with #3871 (ClickHouse read connection pool changes):

- validate_config: keep `validate_query_user_pass/1`, adopt main's
  `read_pool_size`/`labeled_read_pool_size` validations in place of the
  removed `pool_size`.
- check_read_grant: adopt main's `clickhouse_`-prefixed logger metadata and
  rename our `query_user` key to `clickhouse_query_user` to match.
- open_api_schemas: keep `query_user`/`query_password`, take main's
  read pool fields.
- connection_manager_test / backends_live_test: both sides added independent
  tests at the same location; kept all of them.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants