Skip to content

PromQL: implement dropping metric name#96741

Merged
nikitamikhaylov merged 5 commits intoClickHouse:masterfrom
vitlibar:promql-implement-dropping-metric-name
Feb 20, 2026
Merged

PromQL: implement dropping metric name#96741
nikitamikhaylov merged 5 commits intoClickHouse:masterfrom
vitlibar:promql-implement-dropping-metric-name

Conversation

@vitlibar
Copy link
Copy Markdown
Member

@vitlibar vitlibar commented Feb 12, 2026

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

PromQL: implement dropping metric name

Prometheus often drops the metric name after calling a function, for example see.
We should do the same.

Part of #89356

@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Feb 12, 2026

Workflow [PR], commit [86c4ca8]

Summary:

job_name test_name status info comment
Stateless tests (amd_ubsan, sequential) failure
03206_replication_lag_metric FAIL cidb, issue ISSUE CREATED
Integration tests (amd_asan, targeted) error IGNORED

@clickhouse-gh clickhouse-gh bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Feb 12, 2026
@vitlibar vitlibar requested a review from Copilot February 12, 2026 12:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Implements PromQL behavior of dropping the metric name (__name__) in query results and introduces a new time-series aggregate function to coalesce grid values, with accompanying SQL/integration tests and documentation.

Changes:

  • Add dropMetricName() transformation in PromQL-to-SQL conversion, tracking whether __name__ has already been dropped.
  • Introduce and register timeSeriesCoalesceGridValues(mode) aggregate function (with docs + stateless tests).
  • Update Prometheus protocol integration tests to expect dropped metric names and add duplicate-series error coverage.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/queries/0_stateless/03821_time_series_coalesce_grid_values.sql Adds stateless SQL coverage for timeSeriesCoalesceGridValues() modes and group-aware errors.
tests/queries/0_stateless/03821_time_series_coalesce_grid_values.reference Expected outputs for the new stateless test.
tests/integration/test_prometheus_protocols/test_evaluation.py Updates expectations for dropped __name__, adds multi-series/rate cases and error assertions, improves query helpers.
tests/integration/test_prometheus_protocols/prometheus_test_utils.py Adds expect_error flow to return error bodies for HTTP API calls.
src/Storages/TimeSeries/PrometheusQueryToSQL/dropMetricName.h Declares dropMetricName() helper for PromQL-to-SQL conversion.
src/Storages/TimeSeries/PrometheusQueryToSQL/dropMetricName.cpp Implements dropping __name__ by removing the tag and re-coalescing vector grids.
src/Storages/TimeSeries/PrometheusQueryToSQL/applyFunctionOverRange.cpp Applies dropMetricName() for most _over_time functions.
src/Storages/TimeSeries/PrometheusQueryToSQL/SQLQueryPiece.h Adds metric_name_dropped flag to avoid dropping __name__ multiple times.
src/AggregateFunctions/registerAggregateFunctions.cpp Registers the new time-series aggregate function.
src/AggregateFunctions/TimeSeries/AggregateFunctionTimeSeriesCoalesceGridValues.h Defines timeSeriesCoalesceGridValues() aggregate function implementation.
src/AggregateFunctions/TimeSeries/AggregateFunctionTimeSeriesCoalesceGridValues.cpp Factory/registration, parameter parsing, and type validation for the aggregate function.
docs/en/sql-reference/aggregate-functions/reference/timeSeriesCoalesceGridValues.md Adds user documentation for timeSeriesCoalesceGridValues().

@vitlibar vitlibar marked this pull request as draft February 12, 2026 12:48
@vitlibar vitlibar force-pushed the promql-implement-dropping-metric-name branch from 72704fa to f98a392 Compare February 12, 2026 14:29
@vitlibar vitlibar marked this pull request as ready for review February 12, 2026 14:31
@vitlibar vitlibar force-pushed the promql-implement-dropping-metric-name branch 2 times, most recently from 8b3a77a to fe1930a Compare February 12, 2026 15:25
@vitlibar vitlibar added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Feb 12, 2026
@vitlibar vitlibar force-pushed the promql-implement-dropping-metric-name branch 3 times, most recently from 2bbe0f4 to f49bb62 Compare February 12, 2026 16:05
@vitlibar vitlibar marked this pull request as draft February 12, 2026 16:16
@vitlibar vitlibar changed the title PromQL: implement dropping metric name [WIP] PromQL: implement dropping metric name Feb 12, 2026
@vitlibar vitlibar force-pushed the promql-implement-dropping-metric-name branch from f49bb62 to 73a8cf4 Compare February 13, 2026 10:41
@vitlibar vitlibar force-pushed the promql-implement-dropping-metric-name branch from 73a8cf4 to e663b1e Compare February 13, 2026 10:55
@vitlibar vitlibar changed the title [WIP] PromQL: implement dropping metric name PromQL: implement dropping metric name Feb 13, 2026
@vitlibar vitlibar requested a review from Copilot February 13, 2026 10:55
@vitlibar vitlibar force-pushed the promql-implement-dropping-metric-name branch from e663b1e to da4e8f1 Compare February 13, 2026 11:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

tests/integration/helpers/client.py:305

  • CommandRequest.get_error() now treats a process exit code 0 as “failed” if stderr is non-empty, and returns stderr instead of raising. This means query_and_get_error() can no longer guarantee the query actually failed (successful queries that emit warnings to stderr will be interpreted as an error), which can hide real regressions in integration tests. Consider keeping the strict returncode == 0 check (always raise) or explicitly detect ClickHouse exception output (e.g. by matching the standard Code: ... DB::Exception prefix) before accepting stderr as an error signal.
        if self.process.returncode == 0 and not self.remove_trash_from_stderr(stderr):
            raise QueryRuntimeException(
                "Client expected to be failed but succeeded! stdout: {}".format(stdout),
                self.process.returncode,
                stderr,
            )

        return stderr

@vitlibar vitlibar force-pushed the promql-implement-dropping-metric-name branch from da4e8f1 to 42ca95d Compare February 13, 2026 16:48
@vitlibar vitlibar force-pushed the promql-implement-dropping-metric-name branch from 42ca95d to 21af638 Compare February 13, 2026 20:27
@vitlibar vitlibar marked this pull request as ready for review February 13, 2026 20:36
@vitlibar vitlibar force-pushed the promql-implement-dropping-metric-name branch from 21af638 to 86c4ca8 Compare February 16, 2026 10:16
@vitlibar
Copy link
Copy Markdown
Member Author

Ready for review

}

case StoreMethod::VECTOR_GRID:
{
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.

Here is some explanation about this new function timeSeriesThrowDuplicateSeriesIf()

# | E - {"resultType": "matrix", "result": [{"metric": {}, "values": [[120, "0"], [135, "0.2"], [150, "0.1"], [165, "0.1"], [210, "0.3"]]}]}
# | E + {"resultType": "matrix", "result": [{"metric": {"__name__": "test"}, "values": [[120, "0"], [135, "0.2"], [150, "0.1"], [165, "0.1"], [210, "0.3"]]}]}
# | E ? ++++++++++++++++++
False,
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.

With dropping of the metric name some tests give the expected results now.

@nikitamikhaylov nikitamikhaylov added this pull request to the merge queue Feb 20, 2026
Merged via the queue into ClickHouse:master with commit 4918ce8 Feb 20, 2026
138 of 141 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants