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 af75e8001 fix(alert): bound a silence's instanceId to its column
(#6003)
af75e8001 is described below
commit af75e8001cbef80c717aede38363aaf5df761e37
Author: 烤化の初雪 <[email protected]>
AuthorDate: Fri Nov 27 12:13:10 2026 +0800
fix(alert): bound a silence's instanceId to its column (#6003)
---
.../studio/ops/alert/AlertSilenceService.java | 10 +++++++++-
.../studio/ops/alert/AlertSilenceServiceTest.java | 20 ++++++++++++++++++++
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertSilenceService.java
b/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertSilenceService.java
index c09036ccf..aad54b870 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertSilenceService.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertSilenceService.java
@@ -21,6 +21,7 @@ import org.apache.rocketmq.studio.audit.OperationAuditService;
import org.apache.rocketmq.studio.auth.AuthenticatedUserContext;
import org.apache.rocketmq.studio.common.domain.PageResult;
import org.apache.rocketmq.studio.common.exception.BusinessException;
+import org.apache.rocketmq.studio.common.util.TextBounds;
import org.springframework.stereotype.Service;
import java.time.DateTimeException;
@@ -58,9 +59,16 @@ public class AlertSilenceService {
if
(!request.getEndsAt().toInstant().isAfter(request.getStartsAt().toInstant())) {
throw new BusinessException(400, "Silence end time must be after
start time");
}
- if (request.getReason() != null && request.getReason().length() > 512)
{
+ if (request.getReason() != null &&
TextBounds.codePointCount(request.getReason()) > 512) {
throw new BusinessException(400, "Silence reason must not exceed
512 characters");
}
+ // The same bound the reason already had, for the column next to it:
instance_id is
+ // VARCHAR(128), and an over-long value reached the database, whose
rejection the API
+ // reported as a generic 500 - while the operator believed the window
was created.
+ if (request.getInstanceId() != null
+ && TextBounds.codePointCount(request.getInstanceId()) > 128) {
+ throw new BusinessException(400, "Silence instanceId must not
exceed 128 characters");
+ }
RecurrenceConfiguration recurrence = validateRecurrence(request);
AlertSilenceVO silence =
AlertSilenceVO.builder().domain(request.getDomain())
.ruleId(request.getRuleId()).instanceId(trimToNull(request.getInstanceId()))
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertSilenceServiceTest.java
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertSilenceServiceTest.java
index c0b35af86..4337f1b04 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertSilenceServiceTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertSilenceServiceTest.java
@@ -45,6 +45,26 @@ class AlertSilenceServiceTest {
@Mock
private OperationAuditService operationAuditService;
+ @Test
+ void createShouldRejectAnInstanceIdLongerThanItsColumnTest() {
+ AlertSilenceService service = new AlertSilenceService(repository,
operationAuditService);
+ LocalDateTime start = LocalDateTime.of(2026, 8, 22, 9, 0);
+ CreateAlertSilenceDTO request = new CreateAlertSilenceDTO();
+ request.setDomain(AlertDomain.BUSINESS);
+ request.setInstanceId("i".repeat(129));
+ request.setStartsAt(start.atOffset(ZoneOffset.UTC));
+ request.setEndsAt(start.plusHours(1).atOffset(ZoneOffset.UTC));
+
+ // instance_id is VARCHAR(128); without the bound the insert failed
with a data-too-long
+ // error that the API reported as a generic 500, and the operator
believed the maintenance
+ // window existed.
+ assertThatThrownBy(() -> service.create(request))
+ .isInstanceOf(BusinessException.class)
+ .hasMessage("Silence instanceId must not exceed 128
characters")
+ .satisfies(error -> assertThat(((BusinessException)
error).getCode()).isEqualTo(400));
+ org.mockito.Mockito.verify(repository,
org.mockito.Mockito.never()).save(any());
+ }
+
@Test
void createsInstanceScopedSilenceAndMatchesOnlyItsScopeTest() {
AlertSilenceService service = new AlertSilenceService(repository,
operationAuditService);