This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 17d5d97fe fix(alert): bound the rule text fields to their columns 
(#5991)
17d5d97fe is described below

commit 17d5d97fe170509c86fc8a1cd3abf83a8ad2652a
Author: 烤化の初雪 <[email protected]>
AuthorDate: Fri Nov 27 12:13:29 2026 +0800

    fix(alert): bound the rule text fields to their columns (#5991)
---
 .../studio/ops/alert/AlertRuleRequestDTO.java      | 11 ++++++++
 .../studio/ops/alert/AlertRuleRequestDTOTest.java  | 33 ++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertRuleRequestDTO.java
 
b/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertRuleRequestDTO.java
index c052372c1..d9c1deeb4 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertRuleRequestDTO.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertRuleRequestDTO.java
@@ -32,13 +32,17 @@ public class AlertRuleRequestDTO {
 
     private Long id;
     @NotBlank(message = "name is required")
+    @Size(max = 128, message = "name must not exceed 128 characters")
     private String name;
+    @Size(max = 128, message = "metric must not exceed 128 characters")
     private String metric;
     @Pattern(regexp = ">|>=|<|<=|==|!=|UNAVAILABLE", message = "operator is 
invalid")
     private String operator;
     private double threshold;
+    @Size(max = 32, message = "thresholdUnit must not exceed 32 characters")
     private String thresholdUnit;
     @Pattern(regexp = PROMETHEUS_DURATION_REGEXP, message = "duration is 
invalid")
+    @Size(max = 32, message = "duration must not exceed 32 characters")
     private String duration;
     @Pattern(regexp = "LAST|MAX|MIN|AVG|SUM", flags = 
Pattern.Flag.CASE_INSENSITIVE,
             message = "aggregation is invalid")
@@ -49,18 +53,25 @@ public class AlertRuleRequestDTO {
             @Pattern(regexp = "dingtalk|sms|email", flags = 
Pattern.Flag.CASE_INSENSITIVE,
                     message = "channel is unsupported") String> channels;
     private boolean enabled;
+    @Size(max = 512, message = "description must not exceed 512 characters")
     private String description;
+    @Size(max = 128, message = "brokerName must not exceed 128 characters")
     private String brokerName;
+    @Size(max = 128, message = "clusterName must not exceed 128 characters")
     private String clusterName;
     @Pattern(regexp = "critical|warning|info", flags = 
Pattern.Flag.CASE_INSENSITIVE,
             message = "severity is invalid")
     private String severity;
+    @Size(max = 128, message = "instanceId must not exceed 128 characters")
     private String instanceId;
+    @Size(max = 255, message = "consumerGroup must not exceed 255 characters")
     private String consumerGroup;
+    @Size(max = 255, message = "topic must not exceed 255 characters")
     private String topic;
     @Min(value = 1, message = "consecutiveSamples must be at least 1")
     private Integer consecutiveSamples;
     @Pattern(regexp = "(?:[0-9]+(?:ms|s|m|h|d|w|y))+", message = 
"reminderInterval is invalid")
+    @Size(max = 32, message = "reminderInterval must not exceed 32 characters")
     private String reminderInterval;
     @Size(max = 4000, message = "notificationTemplate must not exceed 4000 
characters")
     private String notificationTemplate;
diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertRuleRequestDTOTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertRuleRequestDTOTest.java
index cebe272a2..87b84ba1e 100644
--- 
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertRuleRequestDTOTest.java
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertRuleRequestDTOTest.java
@@ -65,6 +65,39 @@ class AlertRuleRequestDTOTest {
                         "channel is unsupported");
     }
 
+    @Test
+    void textFieldsShouldBeBoundedToTheirColumnsTest() {
+        AlertRuleRequestDTO request = new AlertRuleRequestDTO();
+        request.setName("n".repeat(129));
+        request.setDescription("d".repeat(513));
+        request.setConsumerGroup("g".repeat(256));
+        request.setTopic("t".repeat(256));
+        request.setThresholdUnit("u".repeat(33));
+
+        // The columns are name/metric/brokerName/clusterName/instanceId 128, 
description 512,
+        // consumerGroup/topic 255, thresholdUnit 32; without the bound the 
first check was the
+        // database write, which answers 500 instead of 400.
+        assertThat(validator.validate(request))
+                .extracting(violation -> violation.getMessage())
+                .containsExactlyInAnyOrder("name must not exceed 128 
characters",
+                        "description must not exceed 512 characters",
+                        "consumerGroup must not exceed 255 characters",
+                        "topic must not exceed 255 characters",
+                        "thresholdUnit must not exceed 32 characters");
+    }
+
+    @Test
+    void textFieldsAtTheirColumnWidthAreAcceptedTest() {
+        AlertRuleRequestDTO request = new AlertRuleRequestDTO();
+        request.setName("n".repeat(128));
+        request.setDescription("d".repeat(512));
+        request.setConsumerGroup("g".repeat(255));
+        request.setTopic("t".repeat(255));
+        request.setThresholdUnit("u".repeat(32));
+
+        assertThat(validator.validate(request)).isEmpty();
+    }
+
     @Test
     void durationShouldAcceptCompositePrometheusDurationTest() {
         AlertRuleRequestDTO request = new AlertRuleRequestDTO();

Reply via email to