You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "zjncs (via GitHub)" <gi...@apache.org> on 2026/10/07 23:10:44 UTC

[PR] test(metrics): pin the range query selection grammar [rocketmq-dashboard]

zjncs opened a new pull request, #5716:
URL: https://github.com/apache/rocketmq-dashboard/pull/5716

   ### What
   
   `MetricQueryDTO` — the request shape of the Prometheus range query — had no test. This adds `MetricQueryDTOTest` with 7 tests pinning its selection grammar, enforced by the three `@AssertTrue` rules the REST layer actually runs.
   
   ### Why
   
   The grammar is a small state machine: a query is either a raw PromQL expression, or a profile/semantic pair — never both, never a semantic half. A wrong rule lets an ambiguous or empty query through to Prometheus, and each rule carries a distinct user-facing message an operator relies on to know *what* to fix.
   
   ### What is pinned
   
   - a raw PromQL expression alone is valid; a complete profile/semantic pair is valid;
   - **no selection at all** is rejected with `Metric query is required`;
   - **a half semantic selection** is rejected with `Metric profile and semantic metric are required together` — and, deliberately, **not** with `Metric query is required`: a half selection is an *incomplete* selection, not a missing one, and the error must say what is missing;
   - **a raw expression cannot be combined with any semantic selection** (either half or both);
   - a blank selection counts as absent;
   - the step is required and both time bounds must be positive.
   
   All rules are exercised both through the direct predicate calls and through the Jakarta validator, so the `@AssertTrue` wiring and the exact messages are pinned too.
   
   ### Verification
   
   - New tests on unmodified code: **7/7 green**, checkstyle clean (`mvn test -Dtest=MetricQueryDTOTest`).
   - Discriminating mutations on `MetricQueryDTO`, build result verified red each time:
     1. the bare semantic key dropped from the presence rule, so a half selection misreports as missing — red (caught only after the test was strengthened to distinguish *incomplete* from *missing*; the first draft's plain `contains()` assertion stayed green under the mutation — noted for transparency);
     2. the pairing rule dropped so halves pass — red;
     3. the exclusivity rule dropped so raw and semantic combine freely — red.
   - Restored: 7/7 green. Test-only change; no product code touched.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org