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

   ## Problem
   
   The Prometheus YAML export silently fabricates fields for rules it cannot 
represent faithfully (`AlertService.java:811-814`, `:697-707`, `:725-728`): a 
blank `duration` exports `for: 5m` while Studio's own evaluation parses blank 
as `Duration.ZERO` (`AlertRuleDuration.java:24-25`) — the downloaded file 
alerts up to 5 minutes later than the on-screen rule; an unrecognized operator 
is silently rewritten to `>` and an invalid metric name to 
`rocketmq_consumer_lag_messages`. The operator exports a file whose behavior 
differs from the rule they believe they exported. The export already has the 
correct precedent for unruly rules: native metrics without an exporter 
equivalent are **skipped with a comment** (`AlertService.java:112-115`), not 
rewritten.
   
   ## Fix
   
   Mirror that precedent: emit the stored duration verbatim when it is valid; a 
blank duration omits `for:` (immediate firing, matching `Duration.ZERO` 
semantics); rules with an unsupported operator or an invalid metric name are 
skipped with a comment instead of exported with substituted defaults. Non-blank 
invalid durations keep the pinned 5m legacy fallback (existing test preserved).
   
   ## Verification
   
   - Four tests RED first (the `for: 5m` fabrication and the operator/metric 
substitutions), GREEN after: 
`exportPrometheusRulesYamlShouldOmitForWhenTheStoredDurationIsBlankTest`, 
`…SkipRulesWithAnUnsupportedOperatorTest`, 
`…SkipRulesWithoutAValidMetricNameTest`; the old 
`…ReplaceInvalidPrometheusFieldsTest` was rewritten to the skip contract.
   - GREEN: full alert suite — 465 tests, 0 failures. Verification note: alert 
tests run via `mvn -Dtest='org.apache.rocketmq.studio.ops.alert.**.*Test' 
-Dspring.profiles.active=dev test` from `server/` (the dev profile provides H2; 
a plain run needs MySQL, which is pre-existing behavior), JDK 21.
   
   ## Risk
   
   Deliberate behavior change: previously-exported fabricated rules now export 
honestly (verbatim or skipped). Rules that round-tripped cleanly are unaffected.


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to