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 d8d17a571 fix(ai): preserve alert rule instance scope (#7341)
d8d17a571 is described below
commit d8d17a571289e1390db250be2d41b6515b229539
Author: Yexi Xiang <[email protected]>
AuthorDate: Fri Nov 27 12:07:37 2026 +0800
fix(ai): preserve alert rule instance scope (#7341)
---
.../studio/ops/ai/tool/contract/alert/AlertRuleListItem.java | 6 ++++--
server/src/main/resources/tool-catalog/tools/alert.yaml | 3 +++
.../ai/tool/handler/alert/AlertRuleListToolHandlerTest.java | 12 ++++++++++++
.../ops/ai/tool/service/ToolOutputSchemaContractTest.java | 4 ++--
4 files changed, 21 insertions(+), 4 deletions(-)
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/ops/ai/tool/contract/alert/AlertRuleListItem.java
b/server/src/main/java/org/apache/rocketmq/studio/ops/ai/tool/contract/alert/AlertRuleListItem.java
index 203e187e2..8dc109028 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/ops/ai/tool/contract/alert/AlertRuleListItem.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/ops/ai/tool/contract/alert/AlertRuleListItem.java
@@ -32,7 +32,8 @@ public record AlertRuleListItem(
String duration,
List<String> channels,
boolean enabled,
- String description) {
+ String description,
+ String instanceId) {
public AlertRuleListItem {
channels = channels == null ? List.of() : channels;
@@ -49,6 +50,7 @@ public record AlertRuleListItem(
rule.getDuration(),
rule.getChannels(),
rule.isEnabled(),
- rule.getDescription());
+ rule.getDescription(),
+ rule.getInstanceId());
}
}
diff --git a/server/src/main/resources/tool-catalog/tools/alert.yaml
b/server/src/main/resources/tool-catalog/tools/alert.yaml
index 2d8572c2c..c2ad60516 100644
--- a/server/src/main/resources/tool-catalog/tools/alert.yaml
+++ b/server/src/main/resources/tool-catalog/tools/alert.yaml
@@ -76,5 +76,8 @@ tools:
type: boolean
description:
type: string
+ instanceId:
+ type: string
+ description: Studio Instance identifier; absent for a global
rule.
viewHint: table
deprecated: false
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/ops/ai/tool/handler/alert/AlertRuleListToolHandlerTest.java
b/server/src/test/java/org/apache/rocketmq/studio/ops/ai/tool/handler/alert/AlertRuleListToolHandlerTest.java
index c19a7bff9..ae815f1a3 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/ops/ai/tool/handler/alert/AlertRuleListToolHandlerTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/ops/ai/tool/handler/alert/AlertRuleListToolHandlerTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.rocketmq.studio.ops.ai.tool.handler.alert;
+import com.fasterxml.jackson.databind.ObjectMapper;
import
org.apache.rocketmq.studio.ops.ai.tool.contract.alert.AlertRuleListInput;
import org.apache.rocketmq.studio.ops.ai.tool.contract.alert.AlertRuleListItem;
import org.apache.rocketmq.studio.ops.ai.tool.contract.common.ListOutput;
@@ -65,6 +66,17 @@ class AlertRuleListToolHandlerTest {
.containsExactly("instance-b-tps");
}
+ @Test
+ void listProjectionShouldPreserveInstanceBindingInSerializedOutputTest()
throws Exception {
+ when(alertService.listRules()).thenReturn(List.of(
+ rule(2L, "instance-a-tps", "broker.tps.in", true,
"instance-a")));
+
+ String output = new ObjectMapper().writeValueAsString(handler.execute(
+ new AlertRuleListInput(null, null), context("instance-a")));
+
+ assertThat(output).contains("\"instanceId\":\"instance-a\"");
+ }
+
private static AlertRuleVO rule(
Long id, String name, String metric, boolean enabled, String
instanceId) {
return AlertRuleVO.builder()
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/ops/ai/tool/service/ToolOutputSchemaContractTest.java
b/server/src/test/java/org/apache/rocketmq/studio/ops/ai/tool/service/ToolOutputSchemaContractTest.java
index be0c9b259..ffc5a83c5 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/ops/ai/tool/service/ToolOutputSchemaContractTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/ops/ai/tool/service/ToolOutputSchemaContractTest.java
@@ -177,9 +177,9 @@ class ToolOutputSchemaContractTest {
// so a metric-less rule must still validate against the output schema
samples.put("rmq.alert.rule.list", List.of(new ListOutput<>(List.of(
new AlertRuleListItem(1L, "consumer-lag",
"consumer.lag.total", ">",
- 1000.0, "count", "5m", List.of("dingtalk"), true, "lag
alert"),
+ 1000.0, "count", "5m", List.of("dingtalk"), true, "lag
alert", INSTANCE),
new AlertRuleListItem(2L, "draft-rule", null, null,
- 0.0, null, null, List.of(), false, null)))));
+ 0.0, null, null, List.of(), false, null, null)))));
samples.put("rmq.litetopic.list", List.of(new ListOutput<>(List.of(
new LiteTopicListItem("chat/sess-", "ns-a", 12, 3, 120L,
3600L, "ACTIVE",