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 33b6ba234 fix(clients): mark a client list partial when a broker's 
group inventory was unreadable (#5960)
33b6ba234 is described below

commit 33b6ba2345697f8fae73f2e6c7ddee5d026c167c
Author: 烤化の初雪 <[email protected]>
AuthorDate: Fri Nov 27 12:14:46 2026 +0800

    fix(clients): mark a client list partial when a broker's group inventory 
was unreadable (#5960)
---
 .../provider/apache/RocketMQClientProvider.java    | 28 ++++++++++++---
 .../apache/RocketMQClientProviderTest.java         | 40 ++++++++++++++++++++++
 2 files changed, 63 insertions(+), 5 deletions(-)

diff --git 
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProvider.java
 
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProvider.java
index 9b9c68b9e..81a358da7 100644
--- 
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProvider.java
+++ 
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProvider.java
@@ -251,6 +251,7 @@ public class RocketMQClientProvider implements 
ClientProvider {
             MQAdminExt adminExt, String clusterId) {
         BrokerTopology topology = discoverBrokerTopology(adminExt, clusterId, 
"producer connections");
         Map<String, ClientConnectionVO> connections = new LinkedHashMap<>();
+        int attemptedBrokers = topology.brokerAddresses().size();
         int successfulBrokers = 0;
         for (String brokerAddress : topology.brokerAddresses()) {
             try {
@@ -261,9 +262,15 @@ public class RocketMQClientProvider implements 
ClientProvider {
                 log.warn("Failed to fetch producer connections from broker={}, 
skipping", brokerAddress, e);
             }
         }
-        if (!topology.brokerAddresses().isEmpty() && successfulBrokers == 0) {
+        if (attemptedBrokers > 0 && successfulBrokers == 0) {
             throw new BusinessException(502, "Failed to query producer 
connections from all brokers");
         }
+        if (successfulBrokers < attemptedBrokers) {
+            // A broker whose producer table could not be read hides every 
producer that only
+            // connects to it, so the rows that survived are partial too - the 
page's banner hangs
+            // off this flag, and without it a missing producer looks like one 
that is not running.
+            connections.values().forEach(connection -> 
connection.setPartial(true));
+        }
         return new ArrayList<>(connections.values());
     }
 
@@ -355,7 +362,8 @@ public class RocketMQClientProvider implements 
ClientProvider {
 
     private List<ClientConnectionVO> findConsumerConnections(MQAdminExt 
adminExt, String clusterId) {
         Map<String, ClientConnectionVO> result = new LinkedHashMap<>();
-        Map<ConsumerGroup, List<String>> groups = 
collectSubscriptionGroups(adminExt, clusterId);
+        SubscriptionGroupScan scan = collectSubscriptionGroups(adminExt, 
clusterId);
+        Map<ConsumerGroup, List<String>> groups = scan.groups();
         Map<String, List<String>> proxiesByBroker = new LinkedHashMap<>();
         int attemptedGroupQueries = 0;
         int successfulGroupQueries = 0;
@@ -401,7 +409,9 @@ public class RocketMQClientProvider implements 
ClientProvider {
         if (successfulGroupQueries < attemptedGroupQueries && 
result.isEmpty()) {
             throw new BusinessException(502, "Failed to query consumer 
connections from all groups");
         }
-        if (successfulGroupQueries < attemptedGroupQueries) {
+        if (!scan.complete() || successfulGroupQueries < 
attemptedGroupQueries) {
+            // A failed broker inventory drops whole groups (and their 
clients) from the list, so the
+            // rows that survived are as partial as the ones from a failed 
group query.
             result.values().forEach(connection -> connection.setPartial(true));
         }
         return new ArrayList<>(result.values());
@@ -440,7 +450,15 @@ public class RocketMQClientProvider implements 
ClientProvider {
     private record ConsumerGroup(String name, String cluster) {
     }
 
-    private Map<ConsumerGroup, List<String>> 
collectSubscriptionGroups(MQAdminExt adminExt, String clusterId) {
+    /**
+     * The groups visible on each broker, plus whether every broker answered. 
A broker whose
+     * subscription-group read fails hides all of its groups - and therefore 
every client that only
+     * connects to it - so the caller has to be able to say the scan was 
incomplete.
+     */
+    private record SubscriptionGroupScan(Map<ConsumerGroup, List<String>> 
groups, boolean complete) {
+    }
+
+    private SubscriptionGroupScan collectSubscriptionGroups(MQAdminExt 
adminExt, String clusterId) {
         Map<ConsumerGroup, List<String>> groups = new LinkedHashMap<>();
         BrokerTopology topology = discoverBrokerTopology(adminExt, clusterId, 
"consumer connections");
         int attemptedBrokerQueries = 0;
@@ -463,7 +481,7 @@ public class RocketMQClientProvider implements 
ClientProvider {
         if (attemptedBrokerQueries > 0 && successfulBrokerQueries == 0) {
             throw new BusinessException(502, "Failed to query subscription 
groups from all brokers");
         }
-        return groups;
+        return new SubscriptionGroupScan(groups, successfulBrokerQueries == 
attemptedBrokerQueries);
     }
 
     private ClientConnectionVO toConnectionVO(Connection connection, 
ClientType type, String groupOrTopic,
diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProviderTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProviderTest.java
index 7bd2a005c..4cdef3a40 100644
--- 
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProviderTest.java
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQClientProviderTest.java
@@ -258,6 +258,26 @@ class RocketMQClientProviderTest {
                 
.extracting(ClientConnectionVO::getClientId).containsExactly("direct");
     }
 
+    @Test
+    void aFailedSubscriptionGroupScanMarksTheConsumerRowsPartialTest() throws 
Exception {
+        ClusterInfo topology = clusterInfo("127.0.0.1:10911", 
"127.0.0.2:10911");
+        when(adminExt.examineBrokerClusterInfo()).thenReturn(topology);
+        when(adminExt.getAllSubscriptionGroup("127.0.0.1:10911", 5000L))
+                .thenReturn(subscriptionGroups("group-a"));
+        // The second broker's inventory is unreadable, so its groups (and 
their clients) are absent.
+        when(adminExt.getAllSubscriptionGroup("127.0.0.2:10911", 5000L))
+                .thenThrow(new RemotingConnectException("broker down"));
+        when(adminExt.examineConsumerConnectionInfo("group-a", 
"127.0.0.1:10911"))
+                .thenReturn(consumerConnections(connection("direct", 
"10.0.0.1:40000")));
+
+        List<ClientConnectionVO> rows = 
provider.findConnectionsAt("selected:9876", "cluster-a", "Consumer");
+
+        
assertThat(rows).extracting(ClientConnectionVO::getClientId).containsExactly("direct");
+        // The page's "partial scan" banner hangs off this flag; without it a 
missing consumer looks
+        // like a consumer that does not exist.
+        assertThat(rows.getFirst().isPartial()).isTrue();
+    }
+
     @Test
     void emptyPartialProxyInventoryIsAnErrorTest() throws Exception {
         prepareProxyGroup(adminExt, "127.0.0.1:10911", "10.0.0.8");
@@ -367,6 +387,26 @@ class RocketMQClientProviderTest {
         verify(runtimeAdminClientResolver, never()).execute(anyString(), 
any());
     }
 
+    @Test
+    void aFailedProducerTableReadMarksTheProducerRowsPartialTest() throws 
Exception {
+        Map<String, String> clusters = new HashMap<>();
+        clusters.put("10.0.0.11:10911", "cluster-a");
+        clusters.put("10.0.0.12:10911", "cluster-a");
+        
when(adminExt.examineBrokerClusterInfo()).thenReturn(clusterInfo(clusters));
+        Map<String, List<ProducerInfo>> data = new HashMap<>();
+        data.put("pg-order", List.of(new ProducerInfo(
+                "client-1", "10.0.0.21:49152", LanguageCode.JAVA, 500, 
1000L)));
+        when(adminExt.getAllProducerInfo("10.0.0.11:10911")).thenReturn(new 
ProducerTableInfo(data));
+        // The second broker's producer table is unreadable, so its producers 
never appear.
+        when(adminExt.getAllProducerInfo("10.0.0.12:10911"))
+                .thenThrow(new RemotingConnectException("broker down"));
+
+        List<ClientConnectionVO> connections = 
provider.findConnectionsAt("selected:9876", "cluster-a", "Producer");
+
+        
assertThat(connections).extracting(ClientConnectionVO::getClientId).containsExactly("client-1");
+        assertThat(connections.get(0).isPartial()).isTrue();
+    }
+
     @Test
     void connectionVersionShouldBeResolvedFromMQVersionCodeTest() throws 
Exception {
         Map<String, String> clusters = new HashMap<>();

Reply via email to