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

   ## 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.alertName()` sanitizes rule names by stripping 
non-alphanumeric characters, but does not validate that the resulting name 
starts with a valid character. Prometheus alert names must match 
`[a-zA-Z_:][a-zA-Z0-9_:]*` - they cannot start with a digit. If a user creates 
a rule named `"5xx Error Rate"`, the sanitized name becomes `"5xxErrorRate"`, 
which starts with a digit and is invalid in Prometheus.
   
   ### Steps to Reproduce
   
   - Create an alert rule named `"5xx Error Rate"`.
   - Export the Prometheus rules YAML.
   - Load the YAML into Prometheus.
   - Prometheus rejects the rules because `"5xxErrorRate"` does not match the 
valid alert name pattern.
   
   ### What Did You Expected to See?
   
   Alert names starting with a digit should be prefixed to make them valid.
   
   ### What Did You See Instead?
   
   Invalid alert name exported, causing Prometheus to reject the rules file.
   
   ### Additional Context
   
   **Affected file**: 
`server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertService.java`, 
method `alertName()`.
   
   **Fix**: Prefix names starting with a digit:
   
   ```java
   private String alertName(AlertRuleVO rule) {
       String alertName = hasText(rule.getName()) ? 
rule.getName().replaceAll("[^A-Za-z0-9_]", "") : "";
       if (alertName.isEmpty()) {
           return "RocketMQAlert";
       }
       if (Character.isDigit(alertName.charAt(0))) {
           alertName = "A_" + alertName;
       }
       return alertName;
   }
   ```
   


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