This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/rocketmq-studio by this push:
new 21b505464 fix(alert): preserve large thresholds in Prometheus exports
(#6447)
21b505464 is described below
commit 21b505464f41d3be894f4d810a40a65bc15844ba
Author: Loyal-Young <[email protected]>
AuthorDate: Thu Oct 15 18:10:50 2026 +0800
fix(alert): preserve large thresholds in Prometheus exports (#6447)
---
.../rocketmq/studio/ops/alert/AlertService.java | 3 ++-
.../rocketmq/studio/ops/alert/AlertServiceTest.java | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertService.java
b/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertService.java
index 0308397d4..cf6b95a17 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertService.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertService.java
@@ -801,7 +801,8 @@ public class AlertService {
if (!Double.isFinite(threshold)) {
return "0";
}
- if (threshold == Math.rint(threshold)) {
+ // Long.MAX_VALUE rounds up to 2^63 as a double; the upper cast bound
is exclusive.
+ if (threshold == Math.rint(threshold) && threshold >= Long.MIN_VALUE
&& threshold < 0x1.0p63) {
return Long.toString((long) threshold);
}
return Double.toString(threshold);
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertServiceTest.java
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertServiceTest.java
index b128cf2f7..3c4621a62 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertServiceTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertServiceTest.java
@@ -242,6 +242,26 @@ class AlertServiceTest {
.contains("severity: critical");
}
+ @org.junit.jupiter.params.ParameterizedTest
+ @org.junit.jupiter.params.provider.ValueSource(doubles = {
+ 1e20, -1e20, 0x1.0p63, -0x1.0000000000001p63, Double.MAX_VALUE,
+ -Double.MAX_VALUE, 0x1.fffffffffffffp62, -0x1.0p63, 5000, 0.25})
+ void exportedThresholdRetainsItsFiniteNumericValueTest(double threshold)
throws Exception {
+ AlertRuleVO rule = AlertRuleVO.builder().name("Large threshold")
+
.metric("rocketmq_consumer_lag_messages").operator(">").threshold(threshold)
+ .duration("3m").enabled(true).build();
+ when(alertRepository.findAllRules()).thenReturn(List.of(rule));
+
+ JsonNode yaml = new ObjectMapper(new
YAMLFactory()).readTree(alertService.exportPrometheusRulesYaml());
+ String expression =
yaml.path("groups").get(0).path("rules").get(0).path("expr").asText();
+ String literal = expression.substring(expression.lastIndexOf(' ') + 1);
+
+ assertThat(Double.parseDouble(literal)).isEqualTo(threshold);
+ if (threshold == 0x1.0p63) {
+ assertThat(literal).isNotEqualTo(Long.toString(Long.MAX_VALUE));
+ }
+ }
+
@Test
void exportPrometheusRulesYamlShouldConvertConfiguredRulesTest() {
AlertRuleVO rule = AlertRuleVO.builder()