Skip to content

Compare instant vectors from the Prometheus reader regardless of series order in test_prometheus_protocols - #125937

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-test-multiple-instant-vectors-order
Oct 16, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-test-multiple-instant-vectors-order

Conversation

@groeneai

@groeneai groeneai commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Fix flaky integration test test_prometheus_protocols/test_evaluation.py::test_multiple_instant_vectors, which compared the series of an instant vector in a fixed order.

Description

test_multiple_instant_vectors failed on an unrelated PR (CI report): the Prometheus "reader", which reads from ClickHouse via RemoteRead, returned the two series of http_errors in the opposite order to the "receiver". No related open issue found.

An instant vector has no defined series order. ClickHouse answers RemoteRead without sorting the series, and Prometheus passes that order through for an instant vector (it sorts only matrices). Since #121924 the order varies between requests: locally the reader returned the series swapped in 80 of 600 requests with master 6caeb45 and in 0 of 600 with 5a7acf9, the commit before it. http_api_response_close_to compared the results by raw string or by position, so the test failed.

http_api_response_close_to gets ordered=True. With ordered=False the series of a vector result are sorted by labels on both sides before the comparison. Only the comparison of the reader with the receiver uses it. execute_query_in_prometheus now returns the receiver's result, and do_query_test compares it strictly with the expected one, so an order Prometheus defines (for example topk or the sort functions) is still checked. ClickHouse's own HTTP API and SQL results are still compared strictly. The unused expect_error parameter of execute_query_in_prometheus is removed.

Validation, with the master CI binary of the base commit: test_multiple_instant_vectors --count 50 fails 8 of 50 runs before the change and passes 100 of 100 after; the whole test_evaluation.py module passes (36/36). An offline replay of the CI payload shows that value, label, series-count, timestamp and expected-order differences are still detected.


Workflow [PR]
Sync PR [sync-upstream/pr/125937]

Version info

  • Merged into: 26.11.1.21-master (included in 26.11 and later)
  • Backported to: 26.10.2.43

…t_prometheus_protocols

test_multiple_instant_vectors failed on an unrelated PR (amd_tsan, targeted):
the Prometheus "reader", which gets its data from ClickHouse via RemoteRead,
returned the two `http_errors` series swapped relative to the "receiver".

An instant vector has no defined series order. ClickHouse answers RemoteRead
with `GROUP BY timeSeriesIdToGroup(id)` and no ORDER BY, so the series come
in the order the tags were read, and Prometheus v3.7.3 passes that order
through for an instant vector (only matrices are sorted). Since ClickHouse#121924 this
order varies between requests: locally the reader returned the series
swapped in 80/600 requests with master 6caeb45 and 0/600 with 5a7acf9, its
predecessor. `http_api_response_close_to` compared by raw string (eps == 0)
or by index (eps > 0), so an order-only difference failed the test.

`http_api_response_close_to` gets `ordered=True`; `ordered=False` sorts the
series of a "vector" result by labels on both sides first. It is used only
for the reader-vs-receiver comparison. `execute_query_in_prometheus` now
returns the receiver's result, and `do_query_test` compares that strictly
with the expected result, so an order PromQL defines (for example `topk`,
`bottomk` or the `sort` functions) is still checked against Prometheus.
ClickHouse's own results are still compared strictly. The unused
`expect_error` parameter of `execute_query_in_prometheus` is removed,
because the unordered comparison cannot compare error text.

With the master CI binary of the base commit, the test fails 8/50 runs
before the change and passes 100/100 after; the whole test_evaluation.py
module passes 36/36.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 findings in the first pass, 0 in the delta recheck after 1 fix round), plus my own review (2 findings + 1 nit).

# Sev Finding Verdict Evidence / action
1 ⚠️ The unordered comparison applied to every instant query, so an order PromQL defines (topk, sort*) was no longer checked against Prometheus AGREE, fixed @ a2c2f58 Only the reader-vs-receiver comparison ignores order; execute_query_in_prometheus returns the receiver's result and do_query_test compares it strictly with the expected one (offline replay: a wrong expected order is caught again)
2 ⚠️ execute_query_in_prometheus(expect_error=True) would JSON-decode plain error text AGREE, fixed @ a2c2f58 The unused parameter is removed; no caller passed it
3 ⚠️ The commit message referenced an unrelated PR by number AGREE, fixed @ a2c2f58 Commit message amended
4 💡 With ordered=False, a malformed series element raises instead of the helper returning False AGREE, not blocking Inputs are always the parsed data of a successful Prometheus response; the test fails either way

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261015-034538

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. An offline replay feeds the verbatim CI payload to the real execute_query_in_prometheus / do_query_test and reproduces the exact reader result: ... assertion on every run. End to end with the master CI binary: 8 of 50 runs fail on the unchanged tree.
b Root cause explained? Yes. ClickHouse answers RemoteRead without sorting the series, Prometheus passes that order through for an instant vector, and the order varies between requests since #121924 (0/600 swapped on 5a7acf9, 80/600 on 6caeb45). The reader-vs-receiver check compared by raw string or position, so an order-only difference failed the test.
c Fix matches root cause? Yes. Only the reader-vs-receiver comparison of an instant vector is order-insensitive; the test then checks the receiver's deterministic result. No bound widened, no tag added, no data reduced.
d Test intent preserved / new tests added? Yes. Values, labels, series count, timestamps and NaN/eps rules are still checked (negative controls in the replay). The expected order is still checked strictly against Prometheus (receiver) and ClickHouse. No new test: this fixes a flaky test.
e Both directions demonstrated? Yes. Replay: base fails, fix passes; dropping ordered=False or returning the reader's result fails again; a wrong expected order is still caught. End to end on the same binary: 8/50 failures before, 100/100 passes after.
f Fix is general across code paths? Yes. One call site carries the fix (reader vs receiver); ClickHouse-side comparisons stay strict by design; range queries are unaffected because Prometheus sorts matrices; the other modules compare single-series results.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Covered vector, matrix, scalar and empty results, eps 0 and above 0, NaN, and label-set identity. This is the only multi-series instant-vector expectation in the module.
h Backward compatible? (maintainer-approved exception only) Yes. ordered=True is the default; all 455 literal expectations compare identically to before.
i Invariants and contracts preserved? Yes. The function still returns a bool, matrices stay positional, and both sides go through the same JSON normalization.

Session id: cron:clickhouse-impl-slot-4:20261015-033400

@clickhouse-gh

clickhouse-gh Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a2c2f58]

Summary: ✅


AI Review

Summary

The PR fixes the flaky Prometheus instant-vector comparison by ignoring series order between the reader and receiver while preserving strict expected-result comparisons. No actionable findings. Offline validation passed 1,887 checks across 460 existing JSON fixtures and focused negative controls, reproducing the original CI failure on the base code and accepting it with the fix. The live integration suite was not rerun during this review.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 15, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @nikitamikhaylov, could you review this and add the can be tested label (I cannot add labels right now)? The reader-vs-receiver check in test_prometheus_protocols now ignores the series order of an instant vector, which RemoteRead does not define; the expected result is still compared strictly.

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 15, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 15, 2026
@alexey-milovidov alexey-milovidov self-assigned this Oct 16, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 16, 2026
Merged via the queue into ClickHouse:master with commit 239abff Oct 16, 2026
523 of 525 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 Oct 16, 2026
@PedroTadim

Copy link
Copy Markdown
Member

backporting to fix CI

@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 20, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 20, 2026
PedroTadim added a commit that referenced this pull request Oct 20, 2026
Backport #125937 to 26.10: Compare instant vectors from the Prometheus reader regardless of series order in test_prometheus_protocols
@clickhouse-gh clickhouse-gh Bot added comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... and removed comp-testing Test content only (no production code). labels Nov 22, 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-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants