Define a MetricsExporter interface#41
Conversation
This interface is compatible with OpenTelemetry-style logging and aggregation instrumentation. Ideally, this change itself is a no-op.
There was a problem hiding this comment.
Pull request overview
This PR refactors the ClickHouse-specific export logic behind a new StatsExporter interface, aiming to separate column classification (tags/metrics/records) from the wire-format (ClickHouse Block) implementation while keeping ClickHouse output identical.
Changes:
- Introduces a new
StatsExporterinterface for constructing/exporting batches with typed Tag/Metric/Record columns. - Refactors the existing ClickHouse exporter logic into a
ClickHouseExporterimplementation ofStatsExporter. - Updates the bgworker to include/use the renamed statistics exporter header and adjusts build ignores for CMake artifacts.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/worker/bgworker.cc |
Switches include to the new exporter header and updates timeout comment reference. |
src/export/stats_exporter.h |
Renames/repurposes the public C API header as “statistics exporter”. |
src/export/stats_exporter.cc |
Implements ClickHouseExporter + rewires batch export flow to use the interface and column classification. |
src/export/exporter_interface.h |
Adds the new StatsExporter interface used by the refactor and future OTel-style exporters. |
.gitignore |
Ignores in-source CMake artifacts (CMakeCache.txt, CMakeFiles/). |
Comments suppressed due to low confidence (5)
src/export/stats_exporter.cc:472
PschExportBatch()returnsexporter->NumExported()even whenCommitBatch()fails. Because events are dequeued before the commit, this reports a successful export to the caller (and the bgworker loop) even though nothing was inserted, causing silent data loss and defeating the backoff logic. Return 0 (or otherwise signal failure) whenCommitBatch()returns false, and only returnNumExported()on success.
src/export/stats_exporter.cc:132- In
CommitBatch(), the "connection not established" path returns false without incrementingconsecutive_failuresor callingPschRecordExportFailure(). This means repeated connection failures won’t trigger exponential backoff (and won’t show up in failure stats) unless an exception is thrown. Update this path to record the failure and advance the retry state consistently with the exception path.
src/export/stats_exporter.cc:218 - Column classification looks inconsistent with how the data is used and with the stated OTel semantics:
cmd_typeis low-cardinality and used as a GROUP BY dimension in the ClickHouse schema, but it’s currently exported as aRecordString(log-only). Consider classifyingcmd_typeas a Tag/Dimension so it can participate in metric aggregation without blowing up cardinality.
src/export/stats_exporter.cc:266 err_elevelis categorical (severity/level), but it’s currently modeled asMetricUInt8, which implies it will be treated like a numeric measurement/histogram in an OTel-style exporter. To avoid incorrect metric semantics, model this as a dimension (e.g., add aTagUInt8/TagStringvariant and export it as a tag) rather than a metric.
src/export/stats_exporter.cc:271appis currently exported as aRecordString, but the ClickHouse schema and docs useappas a primary filter / grouping dimension (e.g., GROUP BY app in MVs and example queries). If the intent is to preserve existing queryability when mapping to OTel metrics later, consider classifyingappas a Tag/Dimension (or make this configurable) and keep only truly high-cardinality fields (likeclient_addr) as records.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
This looks great.
At a glance these look sensible, but it might be easier to scan if the three types are grouped, rather than mixed. Easier to know where to put new stuff, too.
It looks like they're all simple measurements, no? They all appear to be named something like |
Extracts ClickHouse wire format (Block) assembly into a new interface.
This interface is compatible with OpenTelemetry-style logging and aggregation instrumentation.
This change is functionally a no-op. The ClickHouse output should remain identical. This change does not implement OpenTelemetry exporting; this will be done in a follow-up.
Critical Review Focus
Please scrutinize the classification of columns in
src/export/stats_exporter.cc:205-271.While ClickHouse treats all columns equally, OTel requires us to strictly distinguish between Dimensions, Measurements, and Logs to prevent memory explosions in the local agent. The columns are therefore categorized as follows:
Tag*(Dimensions):db_name,user).query_id).Metric*(Measurements):MetricFixedString: Special case. This counts occurrences of unique strings. Must be low cardinality (e.g.,err_sqlstate,wait_event_type), or it will blow up memory.Record*(Logs/Raw Data):query_text,error_message,query_id).