Repository navigation
feat(api): record ClickHouse version on proxy spans - #3843
Conversation
Adds hyperdx.clickhouse_proxy.clickhouse.version to /clickhouse-proxy server spans, so query errors and latency can be compared across ClickHouse upgrades. The version comes from a per-connection SELECT version() cached for a minute, started when a request arrives and read when it closes, so it never delays a query.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: c752d96 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
| const VERSION_TTL_MS = 60_000; | ||
| const VERSION_TIMEOUT_MS = 5_000; | ||
|
|
||
| const versionCache = new MetadataCache(); |
There was a problem hiding this comment.
🟡 P2 — Module-level version cache never evicts entries for connections that stop being used
MetadataCache (packages/common-utils/src/core/metadata.ts:331) only deletes an expired entry when get() is called again with the same key. Every ${id}|${host} pair ever proxied therefore stays in versionCache for the life of the pod, including deleted connections and every old host left behind by an edit (the key includes the host on purpose). On a long-lived multi-tenant API pod this grows without bound. Fix: use a bounded LRU/TTL map, or sweep expired entries when a new one is written.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| new MetadataCache(), | ||
| ).getServerVersion({ connectionId: connection.id }); | ||
| return version?.join('.') ?? ''; | ||
| } catch { |
There was a problem hiding this comment.
🟡 P2 — Recorded version is the parsed and padded tuple, not what SELECT version() returns
getServerVersion returns parseClickHouseVersion(...) (packages/common-utils/src/core/clickhouseVersion.ts:13), and that function keeps only four numeric parts and pads missing ones with 0. So 24.8.14.10459.altinitystable gets recorded as 24.8.14.10459, and 26.4 as 26.4.0.0. That contradicts the PR's own check that the attribute matches SELECT version(), and it merges vendor builds together. Fix: run SELECT version() directly in readVersion and store the raw string.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
PR Review
2 finding(s): 🔴 0 P0/P1 · 🟡 2 P2 · 🔵 0 P3 2 posted as inline comment(s) on the changed lines. Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides. |
E2E Test Results✅ All tests passed • 477 passed • 1 skipped • 1112s
Tests ran across 4 shards in parallel. |
Deep Review✅ No critical issues found. The feature is correctly non-blocking: 🟡 P2 — recommended
🔵 P3 nitpicks (7)
Reviewers (10): correctness, testing, maintainability, project-standards, reliability, performance, security, adversarial, kieran-typescript, previous-comments. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
/clickhouse-proxyserver spans now carry the ClickHouse server version ashyperdx.clickhouse_proxy.clickhouse.version, so query errors and latency can be grouped by version before and after a ClickHouse upgrade in Cloud. Until now no API or app span recorded the ClickHouse version.Key decisions
Metadata.getServerVersion, cached per connection (and host) for 60 seconds. The lookup starts when a proxied request arrives and the cached value is read when the response closes, so a query never waits on it. A failed lookup leaves the attribute off for a minute instead of being retried on every request.clickhouse_proxy.querySLI metric, followingagent_docs/observability.md: versions vary across customers, which suits spans better than metric series.Breaking changes
None. This adds a span attribute and changes no responses.
Other impact
SELECT version()per active connection per minute, and only while that connection is receiving proxied requests. It shows up in the customer'ssystem.query_logunder anhdx-api-query id.log_comment, becauseshouldSkipApplySettingsskips the settings step that adds query attribution. This already affects everygetServerVersionandgetSettingscall and needs its own fix.How to reproduce
Starting point:
yarn dev(needs the API).On this branch:
/clickhouse-proxy.POST /clickhouse-proxy/*server span for the second search and confirmhyperdx.clickhouse_proxy.clickhouse.versionmatchesSELECT version().Implementation detail
utils/clickhouseVersion.tskeeps the cache. Client construction sits inside thetry, so a bad host returns no version instead of an unhandled rejection.trackProxyOutcomestarts the lookup andfinishProxyOutcomereads it, next to the otherhyperdx.clickhouse_proxy.*attributes.SELECT version(), and the forwarding test leaves the lookup out of what it captured. New assertions: the version appears once it has been read, and is absent when the upstream refuses the connection.make dev-int FILE=clickhouseProxypasses (25 tests).Note
Low Risk
Observability-only span attribute with async, non-blocking version lookup; no API response or auth changes.
Overview
Adds
hyperdx.clickhouse_proxy.clickhouse.versionto/clickhouse-proxyserver spans so query outcomes and latency can be segmented by ClickHouse release (e.g. around upgrades).A new
cachedClickHouseVersionhelper runsSELECT version()viaMetadata.getServerVersion, caches it per connection and host for 60 seconds, and never blocks the proxied query: lookup starts whentrackProxyOutcomeseesreq._hdx_connection, and the cached value is applied when the response closes infinishProxyOutcome. Failed lookups are cached as empty for the TTL so unreachable servers are not hammered.Integration tests stub upstream
SELECT version()responses, exclude that traffic from forwarding captures, and assert the version attribute is set after cache warm-up and omitted when the upstream cannot be reached.Reviewed by Cursor Bugbot for commit c752d96. Bugbot is set up for automated code reviews on this repo. Configure here.