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 b03d21c08 fix(alert): answer a rule update with the stored rule (#7136)
b03d21c08 is described below

commit b03d21c089bf7828cadbbc1600afcf658769412a
Author: btlqql <[email protected]>
AuthorDate: Mon Oct 26 20:34:35 2026 +0800

    fix(alert): answer a rule update with the stored rule (#7136)
    
    * fix(alert): answer a rule update with the stored rule
    updateRule returned the request-derived rule, so the edit response never 
carried lastTriggered: the repository deliberately keeps the stored fire 
history, and the Alerts page replaces the edited row with that response. A rule 
that had fired therefore flipped to "Never Triggered" until the list reloaded, 
while toggling the same rule brought the stamp back because the toggle path 
answers with the stored row. Read the stored rule back after the write and 
return it; the audit call and the [...]
---
 .../rocketmq/studio/ops/alert/AlertService.java       |  5 ++++-
 .../rocketmq/studio/ops/alert/AlertServiceTest.java   | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertService.java 
b/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertService.java
index 4ad25b59a..e962687cd 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertService.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/ops/alert/AlertService.java
@@ -220,7 +220,10 @@ public class AlertService {
             alertStateRepository.deleteByRuleId(id);
         }
         auditRule("UPDATE_ALERT_RULE", rule, null);
-        return rule;
+        // The write leaves the fields an update cannot carry (the fire 
history) untouched, so the
+        // response must describe the stored rule: echoing the request 
reported a triggered rule as
+        // never triggered until the list reloaded.
+        return alertRepository.findRuleById(id).orElse(rule);
     }
 
     @Transactional
diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertServiceTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertServiceTest.java
index c03192226..e4cb2840f 100644
--- 
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertServiceTest.java
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertServiceTest.java
@@ -1183,6 +1183,25 @@ class AlertServiceTest {
                 eq(null), eq("name=CPU Alert"), eq("SUCCESS"), eq(null));
     }
 
+    @Test
+    void updateRuleShouldReturnTheStoredRuleInsteadOfTheRequestTest() {
+        AlertRuleVO existing = AlertRuleVO.builder().id(1L).name("CPU 
Alert").metric("cpu_usage")
+                
.operator(">=").threshold(80.0).instanceId("local").enabled(true)
+                .lastTriggered("2026-09-30T08:00:00").build();
+        AlertRuleVO update = AlertRuleVO.builder().id(1L).name("CPU 
Alert").metric("cpu_usage")
+                
.operator(">=").threshold(90.0).instanceId("local").enabled(true).build();
+        AlertRuleVO stored = AlertRuleVO.builder().id(1L).name("CPU 
Alert").metric("cpu_usage")
+                
.operator(">=").threshold(90.0).instanceId("local").enabled(true)
+                .lastTriggered("2026-10-01T10:00:00").build();
+        
when(alertRepository.findRuleById(1L)).thenReturn(Optional.of(existing), 
Optional.of(stored));
+        when(alertRepository.replaceRule(update)).thenReturn(true);
+
+        AlertRuleVO result = alertService.updateRule(update);
+
+        assertThat(result.getLastTriggered()).isEqualTo("2026-10-01T10:00:00");
+        assertThat(result.getThreshold()).isEqualTo(90.0);
+    }
+
     @Test
     void updateRuleShouldRejectNullRequestTest() {
         assertThatThrownBy(() -> alertService.updateRule(null))

Reply via email to