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 0927d5cfc fix(alert): compare signed zero thresholds numerically 
(#6445)
0927d5cfc is described below

commit 0927d5cfc664cb0bb1640e9e48b77efdbe281d4a
Author: Loyal-Young <[email protected]>
AuthorDate: Thu Oct 15 18:11:50 2026 +0800

    fix(alert): compare signed zero thresholds numerically (#6445)
---
 .../studio/ops/alert/AlertRuleEvaluator.java       |  4 ++--
 .../studio/ops/alert/AlertRuleEvaluatorTest.java   | 25 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertRuleEvaluator.java
 
b/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertRuleEvaluator.java
index 0eb6d495e..9806344f8 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertRuleEvaluator.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertRuleEvaluator.java
@@ -55,8 +55,8 @@ public class AlertRuleEvaluator {
             case ">=" -> value >= threshold;
             case "<" -> value < threshold;
             case "<=" -> value <= threshold;
-            case "==" -> Double.compare(value, threshold) == 0;
-            case "!=" -> Double.compare(value, threshold) != 0;
+            case "==" -> value == threshold;
+            case "!=" -> value != threshold;
             default -> false;
         };
     }
diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertRuleEvaluatorTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertRuleEvaluatorTest.java
index 89bab3f94..fbedb02b6 100644
--- 
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertRuleEvaluatorTest.java
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertRuleEvaluatorTest.java
@@ -19,6 +19,8 @@ package org.apache.rocketmq.studio.ops.alert;
 import org.apache.rocketmq.studio.cluster.metrics.MetricAvailability;
 import org.apache.rocketmq.studio.cluster.metrics.MetricSample;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
 
 import java.time.Instant;
 
@@ -98,6 +100,29 @@ class AlertRuleEvaluatorTest {
         assertThat(evaluator.evaluate(rule, 
sample(MetricAvailability.AVAILABLE, 0.9)).matches()).isFalse();
     }
 
+    @ParameterizedTest
+    @CsvSource({"0.0,-0.0,false", "-0.0,0.0,false", "0.0,-0.0,true", 
"-0.0,0.0,true"})
+    void numericEqualityTreatsBothZeroSignsEquallyTest(double value, double 
threshold, boolean percent) {
+        AlertRuleVO rule = 
AlertRuleVO.builder().domain(AlertDomain.CLUSTER).metric("broker.disk.usage_ratio")
+                .operator("==").threshold(threshold).thresholdUnit(percent ? 
"%" : null).enabled(true).build();
+        MetricSample zero = sample(MetricAvailability.AVAILABLE, value);
+
+        assertThat(evaluator.evaluate(rule, zero).conditionMet()).isTrue();
+        rule.setOperator("!=");
+        assertThat(evaluator.evaluate(rule, zero).conditionMet()).isFalse();
+    }
+
+    @Test
+    void equalityStillDistinguishesUnequalFiniteValuesTest() {
+        AlertRuleVO rule = 
AlertRuleVO.builder().domain(AlertDomain.CLUSTER).metric("broker.disk.usage_ratio")
+                .operator("==").threshold(0.5).enabled(true).build();
+        assertThat(evaluator.evaluate(rule, 
sample(MetricAvailability.AVAILABLE, 0.5)).conditionMet()).isTrue();
+        assertThat(evaluator.evaluate(rule, 
sample(MetricAvailability.AVAILABLE, 
Math.nextUp(0.5))).conditionMet()).isFalse();
+        rule.setOperator("!=");
+        assertThat(evaluator.evaluate(rule, 
sample(MetricAvailability.AVAILABLE, 0.5)).conditionMet()).isFalse();
+        assertThat(evaluator.evaluate(rule, 
sample(MetricAvailability.AVAILABLE, 
Math.nextUp(0.5))).conditionMet()).isTrue();
+    }
+
     private static MetricSample sample(MetricAvailability availability, Double 
value) {
         return new MetricSample("broker.disk.usage_ratio", 
AlertDomain.CLUSTER, "local", null, null, value,
                 availability, Instant.now());

Reply via email to