tju-yxq opened a new issue, #1431:
URL: https://github.com/apache/rocketmq-dashboard/issues/1431

   ## Bug Report
   
   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   - [x] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions) of this repository 
and believe that this is not a duplicate.
   - [x] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   ### Runtime platform environment
   
   OS: Ubuntu 20.04 / Any OS running RocketMQ Studio
   
   ### RocketMQ version
   
   branch: rocketmq-studio
   version: 5.3.2+
   Git commit id: f727341
   
   ### JDK Version
   
   OpenJDK 21
   
   ### Describe the Bug
   
   `AlertService.formatThreshold()` does not handle `NaN` or `Infinity` 
threshold values. Jackson deserializes JSON `"threshold": NaN` or `"threshold": 
Infinity` into primitive `double` fields by default, so a user can create an 
alert rule with an invalid threshold. The exported Prometheus YAML then 
contains invalid PromQL like `metric > NaN` or `metric > Infinity`, which 
Prometheus rejects when loading the rules file.
   
   ```java
   private String formatThreshold(double threshold) {
       if (threshold == Math.rint(threshold)) {
           return Long.toString((long) threshold);
       }
       return Double.toString(threshold);  // "NaN" or "Infinity" for invalid 
values
   }
   ```
   
   ### Steps to Reproduce
   
   1. Create an alert rule via API with `"threshold": NaN` (or `Infinity`).
   2. Export the Prometheus rules YAML.
   3. Load the YAML into Prometheus.
   4. Prometheus rejects the rules with a parse error on `NaN` or `Infinity`.
   
   ### What Did You Expect to See?
   
   Invalid threshold values (NaN, Infinity, negative infinity) should be 
rejected or replaced with a safe default (e.g., 0) during rule creation or 
export.
   
   ### What Did You See Instead?
   
   The invalid value is accepted and produces malformed PromQL in the exported 
YAML.
   
   ### Additional Context
   
   **Affected file**: 
`server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertService.java`, 
method `formatThreshold()`.
   
   **Fix**: Add a finiteness check in `formatThreshold`:
   
   ```java
   private String formatThreshold(double threshold) {
       if (!Double.isFinite(threshold)) {
           return "0";
       }
       if (threshold == Math.rint(threshold)) {
           return Long.toString((long) threshold);
       }
       return Double.toString(threshold);
   }
   ```
   
   This is a 3-line fix.
   


-- 
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