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 777e179a7 fix(dashboard): stop counting the topics the broker 
generates for its cluster (#6859)
777e179a7 is described below

commit 777e179a7c9e48b1861655c9125678f3b971007a
Author: bai mengxuan <[email protected]>
AuthorDate: Fri Nov 27 12:24:16 2026 +0800

    fix(dashboard): stop counting the topics the broker generates for its 
cluster (#6859)
---
 .../studio/common/util/SystemTopicFilter.java      | 26 ++++++++++++++++++++++
 .../provider/apache/RocketMQDashboardProvider.java | 12 +++++-----
 .../studio/common/util/SystemTopicFilterTest.java  | 23 +++++++++++++++++++
 3 files changed, 56 insertions(+), 5 deletions(-)

diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/common/util/SystemTopicFilter.java
 
b/server/src/main/java/org/apache/rocketmq/studio/common/util/SystemTopicFilter.java
index db2458ec1..cafd68827 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/common/util/SystemTopicFilter.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/common/util/SystemTopicFilter.java
@@ -16,6 +16,7 @@
  */
 package org.apache.rocketmq.studio.common.util;
 
+import org.apache.rocketmq.common.MixAll;
 import org.apache.rocketmq.common.topic.TopicValidator;
 
 import java.util.Set;
@@ -64,4 +65,29 @@ public final class SystemTopicFilter {
     public static boolean isSystem(String topicName) {
         return isSystem(topicName, Set.of());
     }
+
+    /**
+     * Returns {@code true} for the topics the broker generates for the 
cluster itself: the
+     * cluster's own topic (named after {@code brokerClusterName}) and its 
reply topic
+     * ({@code <brokerClusterName>_REPLY_TOPIC}, one queue each). The broker 
registers both with
+     * {@link TopicValidator#addSystemTopic} when it starts, but that set 
lives in the broker's own
+     * JVM: a Studio process does not inherit it, so it has to apply the two 
names itself. Only the
+     * owning cluster's names are matched - a user topic that merely ends in 
the reply suffix, or
+     * carries another cluster's name, stays a user topic.
+     *
+     * @param topicName   the topic name, may be {@code null}
+     * @param brokerNames optional set of broker names; topics matching a 
broker name
+     *                    are also considered system topics (may be empty)
+     * @param clusterName the owning cluster, may be {@code null} when it is 
unknown
+     * @return {@code true} if the topic is a system topic
+     */
+    public static boolean isSystem(String topicName, Set<String> brokerNames, 
String clusterName) {
+        if (isSystem(topicName, brokerNames)) {
+            return true;
+        }
+        if (clusterName == null || clusterName.isEmpty()) {
+            return false;
+        }
+        return clusterName.equals(topicName) || 
MixAll.getReplyTopic(clusterName).equals(topicName);
+    }
 }
diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQDashboardProvider.java
 
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQDashboardProvider.java
index f49f3fbe4..f3b201821 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQDashboardProvider.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQDashboardProvider.java
@@ -297,13 +297,15 @@ public class RocketMQDashboardProvider implements 
DashboardProvider {
                     if (topicConfig == null || 
topicConfig.getTopicConfigTable() == null) {
                         markCountUnavailable(topicCountsUnavailableClusters, 
clusterName);
                     } else {
-                        // A broker's self-named stats topic (e.g. "broker-a") 
is not a user topic;
-                        // pass the owning cluster's broker names so 
SystemTopicFilter can rule it out.
+                        // A broker's self-named stats topic (e.g. "broker-a") 
is not a user topic,
+                        // and neither are the two topics the broker generates 
for the cluster
+                        // itself; pass the owning cluster and its broker 
names so
+                        // SystemTopicFilter can rule all of them out.
                         Set<String> owningBrokerNames = clusterName == null
                                 ? Set.of()
                                 : clusterAddrTable.getOrDefault(clusterName, 
Set.of());
                         for (String topic : 
topicConfig.getTopicConfigTable().keySet()) {
-                            if (isSystemTopic(topic, owningBrokerNames)) {
+                            if (isSystemTopic(topic, owningBrokerNames, 
clusterName)) {
                                 continue;
                             }
                             allTopics.add(topic);
@@ -569,8 +571,8 @@ public class RocketMQDashboardProvider implements 
DashboardProvider {
         return SystemTopicFilter.isSystem(topic);
     }
 
-    private boolean isSystemTopic(String topic, Set<String> brokerNames) {
-        return SystemTopicFilter.isSystem(topic, brokerNames);
+    private boolean isSystemTopic(String topic, Set<String> brokerNames, 
String clusterName) {
+        return SystemTopicFilter.isSystem(topic, brokerNames, clusterName);
     }
 
     private boolean isSystemGroup(String group) {
diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/common/util/SystemTopicFilterTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/common/util/SystemTopicFilterTest.java
index 4a03c2fd9..f9ce2da79 100644
--- 
a/server/src/test/java/org/apache/rocketmq/studio/common/util/SystemTopicFilterTest.java
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/common/util/SystemTopicFilterTest.java
@@ -46,4 +46,27 @@ class SystemTopicFilterTest {
         assertThat(SystemTopicFilter.isSystem("BenchmarkTestOrders", 
brokerNames)).isFalse();
         assertThat(SystemTopicFilter.isSystem("SCHEDULE_TOPIC_orders", 
brokerNames)).isFalse();
     }
+
+    @Test
+    void shouldRecognizeTheTopicsTheBrokerGeneratesForItsOwnClusterTest() {
+        Set<String> brokerNames = Set.of("broker-prod-a");
+        String clusterName = "DefaultCluster";
+
+        // Both are created by TopicConfigManager#registerSystemTopicConfig 
and registered as system
+        // topics there, but in the broker's own JVM, so the studio has to 
rule them out itself.
+        assertThat(SystemTopicFilter.isSystem("DefaultCluster", brokerNames, 
clusterName)).isTrue();
+        assertThat(SystemTopicFilter.isSystem("DefaultCluster_REPLY_TOPIC", 
brokerNames, clusterName)).isTrue();
+
+        // Only the owning cluster's names are matched: the reply suffix 
alone, or another
+        // cluster's name, still describes a user topic.
+        assertThat(SystemTopicFilter.isSystem("orders_REPLY_TOPIC", 
brokerNames, clusterName)).isFalse();
+        assertThat(SystemTopicFilter.isSystem("StagingCluster", brokerNames, 
clusterName)).isFalse();
+        assertThat(SystemTopicFilter.isSystem("StagingCluster_REPLY_TOPIC", 
brokerNames, clusterName)).isFalse();
+        assertThat(SystemTopicFilter.isSystem("orders", brokerNames, 
clusterName)).isFalse();
+
+        // The base rules keep working, and an unknown cluster adds no names.
+        assertThat(SystemTopicFilter.isSystem("RMQ_SYS_TRANS_HALF_TOPIC", 
brokerNames, null)).isTrue();
+        assertThat(SystemTopicFilter.isSystem("DefaultCluster", brokerNames, 
null)).isFalse();
+        assertThat(SystemTopicFilter.isSystem("DefaultCluster", brokerNames, 
"")).isFalse();
+    }
 }

Reply via email to