Repository navigation
fix(metrics): improve PromQL selector windows and counter queries - #4
Merged
Merged
Conversation
Generated-By: PostHog Desktop Task-Id: 52a64169-b741-47be-ab09-da69151123f8
Generated-By: PostHog Desktop Task-Id: 52a64169-b741-47be-ab09-da69151123f8
Generated-By: PostHog Desktop Task-Id: 52a64169-b741-47be-ab09-da69151123f8
frankh
marked this pull request as ready for review
September 15, 2026 09:53
Copy the range result instead of compacting the engine matrix in place, so the engine does not return the same point buffer to its pool twice. Restore the instant SQL fast paths: the internal default_rollup of an instant query reads the lookback window, so the fast path unwraps it to the selector. Range fast paths cannot reproduce automatic selector windows or MetricsQL counter calculations, so the dead range SQL paths are removed. Keep Prometheus functions that MetricsQL does not define by carrying their names through the MetricsQL parser. Leave the selector arguments of timestamp and absent untouched, use the library rollup argument index, and resolve implicit windows inside a subquery against the subquery step. Evaluate running_sum as a post-pass over the range result instead of a doubled subquery. Guard the rate divisor, record query stats after the NaN filter, and update README and PERFORMANCE for the paths that run. Generated-By: PostHog Desktop Task-Id: 46a47e68-6b45-4bbc-9303-303608734206
Contributor
Author
|
Pushed 400c43a with fixes for the review findings. Correctness
Fast paths
running_sum is a post-pass over the range result. It no longer doubles the scanned range and no longer requires Docs: README and PERFORMANCE describe the paths that run, including the one-step visibility of a single sample in a range query. Validation here: |
The ClickHouse e2e test evaluates running_sum inside quantile. The outermost running_sum still runs on the range result; a nested one runs as a subquery that spans the range from the aligned start. Generated-By: PostHog Desktop Task-Id: 46a47e68-6b45-4bbc-9303-303608734206
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
PromQL queries must return useful results when sample times do not match query steps. Short counter windows must include the previous sample, and counter increases must not estimate values at window edges.
Keep the PromQL-compatible API and add selected MetricsQL improvements for automatic query windows, counter calculations, and supported syntax extensions. Apply the same behavior to both ClickHouse storage formats. Preserve stale markers and return numeric constants as vectors.
Other functions and native histogram calculations retain Prometheus behavior. Automatic selectors and counter rollups use the evaluation engine and can read more raw samples. Existing query limits still apply.
Validation
go mod verify,make lint, andgo build ./....CH_SCHEMA_LAYOUT=current SNUFFLE_E2E_SKIP_DOCKER=1 make integration-test.CH_SCHEMA_LAYOUT=posthog SNUFFLE_E2E_SKIP_DOCKER=1 make integration-test.Both integration runs use real ClickHouse and include the full suite with race checks. Counter regression values also match VictoriaMetrics v1.152.0. The final documentation-only update passes
git diff --check.Created with PostHog Desktop