Skip to content

Support PromQL functions changes() and resets() - #112352

Merged
nikitamikhaylov merged 3 commits into
ClickHouse:masterfrom
valerypetrov:promql/wire-changes-resets
Jul 31, 2026
Merged

nikitamikhaylov merged 3 commits into
ClickHouse:masterfrom
valerypetrov:promql/wire-changes-resets

Conversation

@valerypetrov

Copy link
Copy Markdown
Contributor

Related: #57545

Changelog category (leave one):

  • Experimental Feature

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

PromQL: implemented functions changes() and resets().

Description

changes(v range-vector) and resets(v range-vector) were rejected with Function 'changes' is not implemented / Function 'resets' is not implemented, even though the backing aggregate functions already existed and were registered.

The timeSeriesChangesToGrid/timeSeriesResetsToGrid aggregate functions (AggregateFunctionTimeseriesChanges.h, templated on an is_resets_ bool: curr != prev counts as a change, curr < prev counts as a reset) and their factory registration in AggregateFunctionTimeseriesHelpers.cpp were already present and correct. Only the PromQL-to-SQL dispatch table (applyFunctionOverRange.cpp's impl_map) was missing the two entries.

Added changes/resets to impl_map with drop_metric_name = true, matching rate/increase/delta's convention (not last_over_time's false): both functions produce a transition count with a different meaning than the input series, so the metric name is dropped, same as Prometheus.

Verified against Prometheus 3.5.0: identical results for changes()/resets() over both a monotonically increasing series and a series with decreases (resets).

Testing: new cases in tests/integration/test_prometheus_protocols/test_evaluation.py covering changes() and resets() over a plain range-vector selector, exercising both the "counts every transition" and "only counts decreases" semantics. This flips 12 queries of the PromQL compliance suite from unsupported to passed.

@nikitamikhaylov nikitamikhaylov added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Jul 28, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [554f782]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) FAIL
01666_merge_tree_max_query_limit FAIL cidb IGNORED
AST fuzzer (amd_debug) FAIL
Logical error: Can't set alias of A of B (STID: 1493-3ccb) FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR wires changes and resets into the existing PromQL range-function dispatcher, adds focused regression coverage in test_evaluation.py, and updates the public support-matrix docs for prometheusQuery and prometheusQueryRange. I did not find any remaining correctness, compatibility, or documentation issues in the current PR head.

Final Verdict

✅ No blocking or major issues found in the current diff.

@clickhouse-gh clickhouse-gh Bot added the pr-experimental Experimental Feature label Jul 28, 2026
The timeSeriesChangesToGrid/timeSeriesResetsToGrid aggregate functions
and their factory registration already existed; only the PromQL-to-SQL
dispatch table was missing the two entries. Both are value-transforming
functions (their result has a different meaning than the input series),
so drop_metric_name=true to match rate/increase/delta's convention.
@valerypetrov
valerypetrov force-pushed the promql/wire-changes-resets branch from bbb13fb to 58532cd Compare July 29, 2026 00:02
The dispatcher already accepts these two range functions but the
supported-function tables in prometheusQuery.md and
prometheusQueryRange.md still advertised the old set, so the docs
continued to imply they were unsupported.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
increase() has been dispatched in applyFunctionOverRange.cpp and covered
by test_evaluation.py for a while, but the Range support row in both
prometheusQuery.md and prometheusQueryRange.md never listed it.
@clickhouse-gh

clickhouse-gh Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.40% 86.40% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.50% 78.50% +0.00%

Changed lines: Changed C/C++ lines covered: 10/10 (100.00%) · Uncovered code

Full report · Diff report

@nikitamikhaylov nikitamikhaylov self-assigned this Jul 31, 2026
@nikitamikhaylov

Copy link
Copy Markdown
Member

@groeneai, investigate the test failures, classify them, and link the PRs with fixes.

@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Jul 31, 2026
Merged via the queue into ClickHouse:master with commit 13ff48c Jul 31, 2026
176 of 179 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... pr-experimental Experimental Feature 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