Repository navigation
Validate PromQL selector regex matchers - #104484
BadLiveware wants to merge 51 commits into
Conversation
Add the common PromQL compliance reporting and developer notes used by the follow-up TimeSeries PromQL lowering slices. Keep the parser compliance corpus expectation explicit for selectors Prometheus rejects.
Add focused Prometheus protocol tests for user-facing native lowering errors: unsupported-but-parseable functions and invalid date-function arity. These are semantic guardrails for clear errors, not broad coverage padding.
Avoid fork-local wording in the PromQL review base. These are ClickHouse PromQL regression cases and evidence requirements, not fork-specific artifacts.
Remove the standalone native histogram discovery Markdown note from the PromQL split branches.
Remove downstream promshim-specific evidence and non-goal language from the native PromQL lowering README so the note stays focused on ClickHouse review guidance.
Rewrite the native PromQL lowering notes around external SQL-transpiler measurements. Document measured and mixed SQL patterns with target PromQL shapes, pseudocode, and the ClickHouse-side validation expected for in-tree changes.
Replace external corpus row names with concrete PromQL expressions and query-range context in the native PromQL lowering notes.
There was a problem hiding this comment.
I dont know if you want things like this living in the repo, but this is a distillation for what I think are high value future optimizations(They were for querying from an external system). Other (mostly discarded) attempts are documented here for the transpiler https://github.com/BadLiveware/promshim-clickhouse/blob/main/docs/tier2-optimization-attempts.md
There are likely things in there that were discarded but may be more feasible to implement in ClickHouse itself rather than an outside system
There was a problem hiding this comment.
🕵 The README with the native-lowering notes is kept as-is in #123488 (which supersedes this PR); whether it should live in the repository is left to the reviewers there.
|
Workflow [PR], commit [c4588b6] Summary: ❌
AI ReviewSummaryThis PR tightens PromQL selector validation, adds regression/compliance coverage around matcher semantics, and documents the PromQL-to-SQL lowering work. The parser-side changes are mostly sound, but the current merge result still has one new Findings
Final VerdictStatus:
LLVM Coverage ReportMeasured on commit c4588b6.
Changed lines: Changed C/C++ lines covered: 71/71 (100.00%) · Uncovered code |
Match Prometheus parser behavior by requiring vector selectors to contain at
least one matcher that cannot match an empty label value. This prevents broad
selectors like `{job=~".*"}` or `{__name__=~".*"}` from silently selecting every
metric when the user likely intended an explicit non-empty constraint.
Users who intentionally want all real metrics can still use `{__name__=~".+"}`,
and empty-matching label matchers remain valid when combined with that explicit
metric-name matcher.
Deduplicate expanded compliance cases by query text before checking the `should_fail` expectation. A query listed once as expected success and once as expected failure is now reported as conflicting metadata instead of slipping through as two separate cases.
Mirror the upstream PromQL compliance corpus for label transformation invalid label-name cases. These cases should remain should-fail entries so ClickHouse acceptance of invalid destination labels stays visible as a rejection mismatch rather than being counted as expected coverage.
Master replaced the `PQT` alias with the full `PrometheusQueryTree` name in `applyFunctionOverRange.cpp`; update the fixed-range detection block accordingly. Co-Authored-By: Claude Fable 5 <[email protected]>
…fsets `error_pos` is a UTF-8 byte offset everywhere else in this parser, but the selector-validation errors passed `ctx->getStart()->getStartIndex()` through unconverted, so a query with multibyte text before the selector misreported `at position N`. Convert the `ParserRuleContext` overload of `getStartPos` through `convertCodePointPositionToByteOffset`, matching the terminal-node overload, and add a multibyte regression test covering all three selector-validation errors. Co-Authored-By: Claude Fable 5 <[email protected]>
Build profile diff (arm_release)Commit See the job log for details. |
…-base Resolve conflicts in `applyFunctionOverRange.cpp` and `applyOffset.cpp` by taking master's implementation of the fixed `@` modifier over range vectors, which supersedes the equivalent fix made in this branch, and keep both the new `start`/`end` label-name tests from master and this branch's selector validation tests in `gtest_PromQLParser.cpp`.
Master gained support for quoted selector identifiers (`{"foo", job="bar"}`),
which replaced `LabelMatcherContext::labelName` with `selectorIdentifier`, and
moved the `metric name must not be set twice` check inside the matcher loop.
The branch had reverted that work in an earlier merge, so the branch no longer
compiled against the current grammar.
Take master's version of `PrometheusQueryParsingUtil-antlr.cpp` and re-apply
this branch's selector validation on top of it: `matcherMatchesEmptyString`,
`validateSelectorHasNonEmptyMatcher` and `validateSelectorDoesNotSetMetricNameTwice`
now run after all matchers of an instant selector have been collected, and
report the error at the byte offset of the selector itself.
Also update the round-trip expectation for a selector with several in-brace
`__name__` matchers: master now formats the first one as a quoted metric name.
…it/promql-set-binary-operators' Conflicts resolved: - `PrometheusHTTPProtocolAPI.cpp`: keep this branch's deferred `PrometheusQueryTree` construction (moved below the time-argument parsing), together with master's `lookback_delta` handling. - `test_evaluation.py`: keep this branch's version. The base branch's latest master merge accidentally dropped `STALE_NAN`, `test_native_promql_error_paths`, `test_instant_selector_with_multiple_name_matchers`, `test_range_query_drops_stale_marker` and the `@`-modifier tests; everything the base branch adds to this file already comes from master and is present here.
…nary-operators
Conflicts resolved:
- `applyBinaryOperatorAnd/Or/Unless.cpp` and the new `applyBinaryOperatorSet.{h,cpp}`:
keep the deletions of this branch, which consolidates all three set operators into
`applySetBinaryOperator.cpp`. Master's per-step presence mask
(`groupBitOrForEach(arrayMap(x -> isNotNull(x), values))` instead of
`countForEach(values)`) is ported into `selectPresenceByJoinGroup` there, so
`applyBinaryOperatorSet.{h,cpp}` has no remaining users and is dropped too.
- `applyFunctionOverRange.cpp`: take master's `@`-modifier implementation
(`getFixedAtModifier`), which supersedes the equivalent one carried from ClickHouse#104484.
- `gtest_PromQLParser.cpp`: keep master's new `start`/`end` label tests and this
branch's expectation that a selector whose every matcher can match the empty string
is rejected.
Master reworked several parts of the PromQL lowering while this branch carried an earlier version of the same work from the shared base ClickHouse#104484. Take master's version of the overlapping code and keep only what is specific to this branch: - `PrometheusQueryParsingUtil-antlr.cpp`: master introduced the `selectorIdentifier` grammar rule (quoted label names and quoted metric names) and a lexer that validates multiline strings. Take master's file and re-apply on top of it the check that a vector selector has at least one matcher which cannot match an empty label value. - `applyOffset.cpp`: take master's `@`-modifier handling, to match master's `applyFunctionOverRange.cpp` taken during the merge. - `PrometheusHTTPProtocolAPI.cpp`, `StoragePrometheusQuery.cpp`: drop the cosmetic reordering of the `PrometheusQueryTree` construction and follow master.
|
🕵 @groeneai, the only red on this PR was |
|
Confirmed, #113589 covers this signature. The report normalizes the parameters; the concrete values in that run are That pins the instance to the provenance defect rather than only to the message:
The same message also fires from a second, unrelated root cause: random Two side notes on the links. #81738 is closed (completed 2026-04-10); the live tracker is #101325, which #113589 closes. And this abort is a per-run event rather than a property of a given tree: over the last 14 days the message has 51 rows across 14 check families and 39 distinct pull requests, 3 of them on master, most recently 2026-09-02 00:25 UTC. So a green re-run on the new head would not mean it is resolved. |
…-base # Conflicts: # src/Storages/TimeSeries/PrometheusQueryToSQL/finalizeSQL.cpp
…tor path The stale-marker handling used to live only in `finalizeSQL`: the result of `last_over_time` over an instant selector kept the stale markers in its `VECTOR_GRID`, and they were filtered out only when the query result was finalized. Every operator between the selector and the finalization decides whether a series is present at a step by the presence of its value (`isNotNull`, `countForEach`, `anyForEach`), so a series whose latest sample is a stale marker still participated in `count(foo)`, `group(foo)`, `foo and bar`, `foo or bar`, `foo unless bar`, `scalar(foo)` and so on. Now `fromSelector` replaces the stale markers with NULL immediately after `last_over_time`, before any other operator consumes the grid, and the finalization is back to the version on `master`. Range selectors still filter the stale markers out of the raw data, so `last_over_time(foo[1m])` keeps returning the latest non-stale sample, as in Prometheus. Added regression tests: a bare stale selector, the same selector composed with aggregations, set operators, arithmetic, `scalar` and `absent`, and the same in a range query. Addresses the AI review blocker in ClickHouse#104484 (comment) Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 @groeneai, investigate the failure: Stateless tests (arm_asan_ubsan, azure, parallel) on the previous head |
|
The fix is already merged, so no new PR from me is needed: @Michicosun's #118031 "Fix Crash during Traversal of Execution Graph" merged 2026-09-05T12:07:22Z as The failing build predates the fix by three days, so it could not contain it. The current head One related follow-up of mine is on your head as well: #119577 "Do not access ports from |
…-base Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PromQL Compliance ReportBaseline: S3 master
Extended support (upstream engine tests): native-histogram exclusions: 149; excluded assertions: 248; upstream Uploaded compliance JSON for this PR commit Baseline updateThis run reports 96.79% vs master baseline 96.47% ( |
|
🕵 Superseded by #123488. I merged |
Adds native PromQL selector validation plus shared test and review scaffolding for the native PromQL-to-SQL feature PRs: parser expectation coverage, ClickHouse PromQL regression corpus organization, native-lowering developer notes, and targeted native error-path tests.
The parser now follows Prometheus selector semantics: a vector selector must include at least one matcher that cannot match the empty string, so
{__name__=~".*"}is invalid because.*can match an empty metric name, and an outside metric name combined with an in-brace__name__matcher (foo{__name__="bar"}) is rejected. Invalid regular expressions in matchers are rejected at parse time. Keeping these as expected successes would make later compliance deltas misleading.The compliance harness could already observe and report errors, and the low-level query helpers could execute calls that are expected to fail. What was missing was a small focused evaluation helper that says: this ClickHouse PromQL query should fail with this error through both
prometheusQuerySQL and the HTTP API. This PR adds that negative-test shape and pins two current native-lowering errors: unsupported-but-parseable functions and wrong-arity calls.Further changes made while addressing review:
InstantSelector::toStringhoists the metric name in front of the braces only when there is exactly one__name__matcher, so valid selectors with multiple__name__matchers survive a round-trip.Float64valuecolumns;Float32tables lose the stale NaN payload at ingest and are a known limitation).@ <timestamp>keeps its fixed evaluation window:setEvaluationTimeno longer collapses a range-vector grid, and range-vector functions aggregate over the fixed range before spreading the result over the query grid.at position Nas a UTF-8 byte offset, consistent with the other parser errors.Split out from the integration draft #104271.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not for changelog.
Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/104484]