Skip to content

Read the metrics keys of system.all_metric_log by name - #127195

Merged
evillique merged 1 commit into
ClickHouse:masterfrom
evillique:fix-all-metric-log-keys
Oct 23, 2026
Merged

evillique merged 1 commit into
ClickHouse:masterfrom
evillique:fix-all-metric-log-keys

Conversation

@evillique

@evillique evillique commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Related: #112670
Related: #124016

The keys of metrics in the bucketed system.metric_log are an Enum16 numbered by the position of a metric, so most releases renumber them. system.all_metric_log casts the rotated metric_log_N tables to the current enum, which either fails with CANNOT_CONVERT_TYPE or silently shows the values under wrong metric names. Its metrics now has LowCardinality(String) keys, which are cast by name.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix reading metrics from system.all_metric_log with the bucketed schema of system.metric_log after an upgrade: it failed with CANNOT_CONVERT_TYPE or showed the values of older rows under wrong metric names.


Workflow [PR]
Sync PR [sync-upstream/pr/127195]

Version info

  • Merged into: 26.11.1.667-master (included in 26.11 and later)
  • Backported to: 26.10.4.205

@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c229920]

Summary: ✅


AI Review

Summary

The PR changes the metrics keys of bucketed system.all_metric_log to LowCardinality(String) so rotated tables can be read by metric name. The local fix leaves the cluster-plus-rotated-tables mode returning numeric strings instead of metric names.

Missing context / blind spots
  • ⚠️ The finding is based on tracing the current code. No local ClickHouse binary or build is available, and the targeted Praktika report exposed no per-test results. Running the combined-mode regression below would confirm the end-to-end output.
Findings

❌ Blockers

  • [P1] src/Interpreters/SystemLog.cpp:1556–1560: the remote merge loses names before this conversion. With both cluster and merge_rotated_tables configured, clusterAllReplicas executes an inner merge that independently infers its schema. StorageMerge::getColumnsDescriptionFromSourceTables uses getLeastSupertypeOrVariant; differing Enum16 key types unify to Int16, producing Map(Int16, Int64). Converting that result to the new string-keyed map yields keys such as '1' and '2', rather than the original metric names. Ensure each remote source's keys are converted by name before the inner merge unifies them. Inline finding.
Tests
  • ⚠️ Run the new rotated-table fixture on the existing cluster-plus-merge node (node1), explicitly configured with the bucketed schema, and assert the original metric names through system.all_metric_log. The added node3 test covers only local merging with an explicit schema.
Final Verdict

Status: ❌ Block. Preserve metric names through the inner remote merge and cover the combined mode with the focused regression above.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 21, 2026
@thevar1able thevar1able self-assigned this Oct 21, 2026
Comment on lines +1556 to +1560
ordinary_columns.modify("metrics", [](ColumnDescription & column)
{
const auto & map_type = typeid_cast<const DataTypeMap &>(*column.type);
column.type = std::make_shared<DataTypeMap>(
std::make_shared<DataTypeLowCardinality>(std::make_shared<DataTypeString>()), map_type.getValueType());

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.

❌ [P1] Preserve metric names before the remote merge unifies schemas

This changes the schema of the outer union table, but when both create_union_system_log_tables.cluster and merge_rotated_tables are enabled, its source is still clusterAllReplicas(..., merge('system', '^metric_log(_[0-9]+)?$')). That inner merge infers its schema independently; it does not receive these explicit columns.

For a live bucketed table plus a rotated table with different enum numbering, TableFunctionMerge::getActualTableStructure calls StorageMerge::getColumnsDescriptionFromSourceTables, whose getLeastSupertypeOrVariant produces Map(Int16, Int64) for the differing enum-keyed maps (getLeastSupertype treats enums as signed integers). Each child's keys therefore become integers before the outer conversion runs. The new string-keyed schema then turns those integers into strings: the row inserted by the new test is returned with keys '1' and '2', rather than CurrentMetric_Query and ProfileEvent_Query. The upgrade bug remains in this supported mode.

Please ensure the inner remote merge converts each source's keys by name before schema unification. Extend the regression to the existing cluster-plus-merge node (node1), explicitly using the bucketed schema and the same rotated-table fixture; node3 exercises only the local path, which bypasses inference because it receives the explicit schema.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed separately in #127583, which makes merge keep enum names: a combined enum when the tables number it consistently, LowCardinality(String) when the numbering conflicts.

@clickhouse-gh clickhouse-gh Bot added the comp-system-table system.* tables (introspection, system metadata, performance visibility). label Oct 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing c2299208f with master c6336c173 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 5fc445790; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

3 object files changed (+47.61 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Interpreters/SystemLog.cpp.o 4.90 MiB 4.94 MiB +47.60 KiB (+0.95%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

7 translation units recompiled, 27 s compile time in total, 7 of them have a recent master baseline.

Job report

@evillique
evillique added this pull request to the merge queue Oct 23, 2026
Merged via the queue into ClickHouse:master with commit 6a36363 Oct 23, 2026
353 of 354 checks passed
@evillique
evillique deleted the fix-all-metric-log-keys branch October 23, 2026 16:14
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 23, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 13, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 13, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 13, 2026
Backport #127195 to 26.10: Read the `metrics` keys of `system.all_metric_log` by name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-system-table system.* tables (introspection, system metadata, performance visibility). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants