PromQL: implement dropping metric name#96741
PromQL: implement dropping metric name#96741nikitamikhaylov merged 5 commits intoClickHouse:masterfrom
Conversation
|
Workflow [PR], commit [86c4ca8] Summary: ❌
|
There was a problem hiding this comment.
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(). |
src/AggregateFunctions/TimeSeries/AggregateFunctionTimeSeriesCoalesceGridValues.h
Outdated
Show resolved
Hide resolved
src/AggregateFunctions/TimeSeries/AggregateFunctionTimeSeriesCoalesceGridValues.h
Outdated
Show resolved
Hide resolved
src/AggregateFunctions/TimeSeries/AggregateFunctionTimeSeriesCoalesceGridValues.h
Outdated
Show resolved
Hide resolved
src/AggregateFunctions/TimeSeries/AggregateFunctionTimeSeriesCoalesceGridValues.h
Outdated
Show resolved
Hide resolved
src/AggregateFunctions/TimeSeries/AggregateFunctionTimeSeriesCoalesceGridValues.cpp
Outdated
Show resolved
Hide resolved
docs/en/sql-reference/aggregate-functions/reference/timeSeriesCoalesceGridValues.md
Outdated
Show resolved
Hide resolved
72704fa to
f98a392
Compare
8b3a77a to
fe1930a
Compare
2bbe0f4 to
f49bb62
Compare
f49bb62 to
73a8cf4
Compare
73a8cf4 to
e663b1e
Compare
e663b1e to
da4e8f1
Compare
There was a problem hiding this comment.
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 == 0check (always raise) or explicitly detect ClickHouse exception output (e.g. by matching the standardCode: ... DB::Exceptionprefix) 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
src/Storages/TimeSeries/PrometheusQueryToSQL/dropMetricName.cpp
Outdated
Show resolved
Hide resolved
src/Storages/TimeSeries/PrometheusQueryToSQL/dropMetricName.cpp
Outdated
Show resolved
Hide resolved
da4e8f1 to
42ca95d
Compare
42ca95d to
21af638
Compare
21af638 to
86c4ca8
Compare
|
Ready for review |
| } | ||
|
|
||
| case StoreMethod::VECTOR_GRID: | ||
| { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
With dropping of the metric name some tests give the expected results now.
4918ce8
Changelog category (leave one):
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