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 453ed59c0 fix(consumer): preserve proxy failures in stack diagnostics
(#6019)
453ed59c0 is described below
commit 453ed59c073d3f3a9e12ce491d68195f615f762f
Author: pilichoumao <[email protected]>
AuthorDate: Fri Nov 27 12:04:18 2026 +0800
fix(consumer): preserve proxy failures in stack diagnostics (#6019)
---
server/README.md | 10 ++
.../provider/apache/ProxyConsumerResolver.java | 53 +++++++++--
.../RocketMQConsumerDiagnosticsProvider.java | 37 ++++++--
.../group/ConsumerGroupControllerTest.java | 23 +++++
.../provider/apache/ProxyConsumerResolverTest.java | 86 +++++++++++++++++
.../RocketMQConsumerDiagnosticsProviderTest.java | 102 ++++++++++++++++++++-
web/src/i18n/translations.ts | 10 ++
.../pages/instance/__tests__/ConsumerPage.test.tsx | 37 ++++++++
web/src/pages/instance/consumer.tsx | 22 ++---
9 files changed, 348 insertions(+), 32 deletions(-)
diff --git a/server/README.md b/server/README.md
index e45e1e242..d7b312728 100644
--- a/server/README.md
+++ b/server/README.md
@@ -117,3 +117,13 @@ mvn -B -ntp -Dtest=AuthServiceTest test # 运行指定测试类;可替换为
禁止内部/商业版本号;禁用 `com.aliyun.openservices:ons-client`,客户端收发用开源
`rocketmq-client`;云厂商管控面走 OpenAPI SDK(`alibabacloud-rocketmq20220801` /
`tencentcloud-sdk-java-trocket`)。
+
+
+## 消费者线程栈诊断
+
+线程栈查询优先尝试所选实例的 Proxy,并保留直连客户端的 Broker 回退。
+只有查询路径明确未找到客户端时才返回 404;若 Proxy 查询失败且 Broker 未找到客户端,
+返回 502,表示无法确定诊断结果。该 502 只描述栈查询本身;实例解析等前置错误(例如实例不存在)
+在拿到 AdminClient 之前发生,保留各自的状态码与消息,实例不存在仍返回 404。
+取消查询保留线程中断并返回 503。
+成功响应中的空线程栈只表示客户端没有提供线程栈,不代表所有 Proxy 客户端都不支持采集。
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/ProxyConsumerResolver.java
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/ProxyConsumerResolver.java
index d0f254188..c8a338a22 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/ProxyConsumerResolver.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/ProxyConsumerResolver.java
@@ -36,6 +36,7 @@ import
org.apache.rocketmq.remoting.protocol.header.GetConsumerRunningInfoReques
import org.apache.rocketmq.studio.cluster.broker.MqAdminExtFactory;
import org.apache.rocketmq.studio.cluster.broker.RuntimeAdminClientResolver;
import org.apache.rocketmq.studio.common.util.MqResponseCodes;
+import org.apache.rocketmq.studio.common.exception.BusinessException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
@@ -143,21 +144,42 @@ public class ProxyConsumerResolver {
* answer, letting the caller fall back to the broker for directly
connected clients.
*/
public ConsumerRunningInfo resolveConsumerRunningInfo(String instanceId,
String group, String clientId) {
- for (String addr : discoverProxyAddresses(instanceId)) {
+ return resolveConsumerRunningInfoStatus(instanceId, group,
clientId).runningInfo();
+ }
+
+ public ConsumerRunningInfoResolution resolveConsumerRunningInfoStatus(
+ String instanceId, String group, String clientId) {
+ ProxyAddressResolution discovery =
discoverProxyAddressesStatus(instanceId);
+ if (!discovery.available()) {
+ return ConsumerRunningInfoResolution.unavailable();
+ }
+ boolean queryUnavailable = false;
+ for (String addr : discovery.addresses()) {
try {
- ConsumerRunningInfo runningInfo = queryProxyRunningInfo(addr,
group, clientId);
- if (runningInfo != null) {
- return runningInfo;
+ ConsumerRunningInfoResolution result =
queryProxyRunningInfoStatus(addr, group, clientId);
+ if (result.runningInfo() != null) {
+ return result;
}
+ queryUnavailable |= !result.available();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new BusinessException(503, "Consumer stack query
interrupted");
} catch (Exception e) {
+ queryUnavailable = true;
log.debug("Proxy consumer running info query failed for {}/{}
via {}: {}",
group, clientId, addr, e.getMessage());
}
}
- return null;
+ return queryUnavailable ? ConsumerRunningInfoResolution.unavailable()
+ : ConsumerRunningInfoResolution.available(null);
}
ConsumerRunningInfo queryProxyRunningInfo(String proxyAddr, String group,
String clientId) throws Exception {
+ return queryProxyRunningInfoStatus(proxyAddr, group,
clientId).runningInfo();
+ }
+
+ private ConsumerRunningInfoResolution queryProxyRunningInfoStatus(
+ String proxyAddr, String group, String clientId) throws Exception {
GetConsumerRunningInfoRequestHeader header = new
GetConsumerRunningInfoRequestHeader();
header.setConsumerGroup(group);
header.setClientId(clientId);
@@ -167,14 +189,19 @@ public class ProxyConsumerResolver {
RemotingCommand response =
remotingClient().invokeSync(proxyAddr, request,
PROXY_RUNNING_INFO_TIMEOUT_MILLIS);
if (response == null) {
- return null;
+ return ConsumerRunningInfoResolution.unavailable();
+ }
+ if (response.getCode() == ResponseCode.CONSUMER_NOT_ONLINE) {
+ return ConsumerRunningInfoResolution.available(null);
}
if (response.getCode() != ResponseCode.SUCCESS || response.getBody()
== null) {
log.info("Proxy {} cannot report running info for {}/{}: code={}
remark={}",
proxyAddr, group, clientId, response.getCode(),
response.getRemark());
- return null;
+ return ConsumerRunningInfoResolution.unavailable();
}
- return ConsumerRunningInfo.decode(response.getBody(),
ConsumerRunningInfo.class);
+ ConsumerRunningInfo info =
ConsumerRunningInfo.decode(response.getBody(), ConsumerRunningInfo.class);
+ return info == null ? ConsumerRunningInfoResolution.unavailable()
+ : ConsumerRunningInfoResolution.available(info);
}
List<String> discoverProxyAddresses(String instanceId) {
@@ -272,6 +299,16 @@ public class ProxyConsumerResolver {
static ConsumerConnectionResolution unavailable() { return new
ConsumerConnectionResolution(null, false); }
}
+ public record ConsumerRunningInfoResolution(ConsumerRunningInfo
runningInfo, boolean available) {
+ static ConsumerRunningInfoResolution available(ConsumerRunningInfo
runningInfo) {
+ return new ConsumerRunningInfoResolution(runningInfo, true);
+ }
+
+ static ConsumerRunningInfoResolution unavailable() {
+ return new ConsumerRunningInfoResolution(null, false);
+ }
+ }
+
private record ProxyAddressResolution(List<String> addresses, boolean
available) {
static ProxyAddressResolution available(List<String> addresses) {
return new ProxyAddressResolution(addresses, true); }
static ProxyAddressResolution unavailable() { return new
ProxyAddressResolution(List.of(), false); }
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQConsumerDiagnosticsProvider.java
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQConsumerDiagnosticsProvider.java
index 8569079af..d6d44cd48 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQConsumerDiagnosticsProvider.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/provider/apache/RocketMQConsumerDiagnosticsProvider.java
@@ -65,21 +65,37 @@ public class RocketMQConsumerDiagnosticsProvider implements
ConsumerDiagnosticsP
// Clients that connect through a proxy keep their channel on the
proxy and never register
// on a broker, so ask the proxy first; the broker only knows directly
connected clients
// and answers "not online" for everyone else.
- ConsumerRunningInfo viaProxy = proxyConsumerResolver == null
- ? null
- : proxyConsumerResolver.resolveConsumerRunningInfo(instanceId,
groupName, clientId);
- if (viaProxy != null) {
- return toStackTrace(groupName, clientId, viaProxy);
+ ProxyConsumerResolver.ConsumerRunningInfoResolution viaProxy =
proxyConsumerResolver == null
+ ?
ProxyConsumerResolver.ConsumerRunningInfoResolution.available(null)
+ :
proxyConsumerResolver.resolveConsumerRunningInfoStatus(instanceId, groupName,
clientId);
+ if (viaProxy.runningInfo() != null) {
+ return toStackTrace(groupName, clientId, viaProxy.runningInfo());
}
+ // A proxy that could not be queried cannot prove the client is
offline, so the broker's
+ // "client missing" answer no longer settles anything and the read
stays a gateway failure.
+ // That re-grading belongs to the stack lookup alone: it happens
inside the callback, once an
+ // admin client has already been handed out. Resolving the instance,
its credentials and the
+ // admin client itself run outside the callback, so their own status
codes and messages -
+ // "Instance not found" among them - are reported unchanged.
+ final boolean clientAvailabilityUnknown = !viaProxy.available();
+ MqAdminExtFactory.AdminAction<ConsumerStackTraceVO> lookupStack =
admin -> {
+ try {
+ return getConsumerStack(admin, groupName, clientId);
+ } catch (BusinessException e) {
+ if (clientAvailabilityUnknown && e.getCode() == 404) {
+ throw new BusinessException(502,
+ "Unable to determine consumer stack availability:
proxy query failed for " + clientId);
+ }
+ throw e;
+ }
+ };
if (StringUtils.hasText(instanceId)) {
- return runtimeAdminClientResolver.execute(instanceId,
- admin -> getConsumerStack(admin, groupName, clientId));
+ return runtimeAdminClientResolver.execute(instanceId, lookupStack);
}
if (!StringUtils.hasText(properties.getNamesrvAddr())) {
throw new BusinessException(503, "RocketMQ admin not connected");
}
- return adminFactory.execute(properties.getNamesrvAddr(), null,
- admin -> getConsumerStack(admin, groupName, clientId));
+ return adminFactory.execute(properties.getNamesrvAddr(), null,
lookupStack);
}
private ConsumerStackTraceVO getConsumerStack(MQAdminExt admin, String
groupName, String clientId) {
@@ -96,6 +112,9 @@ public class RocketMQConsumerDiagnosticsProvider implements
ConsumerDiagnosticsP
throw new BusinessException(404, notReachable(clientId));
}
throw diagnosticsFailure(groupName, clientId, e);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new BusinessException(503, "Consumer stack query
interrupted");
} catch (Exception e) {
throw diagnosticsFailure(groupName, clientId, e);
}
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/instance/group/ConsumerGroupControllerTest.java
b/server/src/test/java/org/apache/rocketmq/studio/instance/group/ConsumerGroupControllerTest.java
index 47c4bd6bd..c98a860ff 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/instance/group/ConsumerGroupControllerTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/instance/group/ConsumerGroupControllerTest.java
@@ -17,6 +17,7 @@
package org.apache.rocketmq.studio.instance.group;
+import org.apache.rocketmq.studio.common.exception.BusinessException;
import org.apache.rocketmq.studio.WebMvcAuthTestSupport;
import org.apache.rocketmq.studio.common.config.LegacyJackson2Config;
@@ -329,6 +330,28 @@ class ConsumerGroupControllerTest extends
WebMvcAuthTestSupport {
verify(consumerDiagnosticsService).getConsumerStack("instance-a",
"cg-orders", "client-1");
}
+ @Test
+ void consumerStackShouldSurfaceUnavailableDiagnosticsTest() throws
Exception {
+ when(consumerDiagnosticsService.getConsumerStack("instance-a",
"cg-orders", "client-1"))
+ .thenThrow(new BusinessException(502, "proxy query failed"));
+ mockMvc.perform(get("/api/groups/cg-orders/instances/client-1/stack")
+ .param("instanceId", "instance-a"))
+ .andExpect(status().isBadGateway())
+ .andExpect(jsonPath("$.code").value(502))
+ .andExpect(jsonPath("$.message").value("proxy query failed"));
+ }
+
+ @Test
+ void consumerStackShouldReportUnknownInstanceAsNotFoundTest() throws
Exception {
+ when(consumerDiagnosticsService.getConsumerStack("gone", "cg-orders",
"client-1"))
+ .thenThrow(new BusinessException(404, "Instance not found:
gone"));
+ mockMvc.perform(get("/api/groups/cg-orders/instances/client-1/stack")
+ .param("instanceId", "gone"))
+ .andExpect(status().isNotFound())
+ .andExpect(jsonPath("$.code").value(404))
+ .andExpect(jsonPath("$.message").value("Instance not found:
gone"));
+ }
+
@Test
void groupRuntimeDiagnosticsShouldPassSelectedInstance() throws Exception {
when(metadataService.getGroupProgress("instance-a",
"cg-orders")).thenReturn(List.of());
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/ProxyConsumerResolverTest.java
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/ProxyConsumerResolverTest.java
index c28a40041..57487a93a 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/ProxyConsumerResolverTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/ProxyConsumerResolverTest.java
@@ -22,6 +22,8 @@ import org.apache.rocketmq.remoting.protocol.RemotingCommand;
import org.apache.rocketmq.remoting.protocol.ResponseCode;
import org.apache.rocketmq.remoting.protocol.body.Connection;
import org.apache.rocketmq.remoting.protocol.body.ConsumerConnection;
+import org.apache.rocketmq.remoting.protocol.body.ConsumerRunningInfo;
+import org.apache.rocketmq.studio.common.exception.BusinessException;
import org.apache.rocketmq.studio.cluster.broker.MqAdminExtFactory;
import org.apache.rocketmq.studio.cluster.broker.RuntimeAdminClientResolver;
import org.apache.rocketmq.tools.admin.MQAdminExt;
@@ -35,6 +37,7 @@ import java.util.HashSet;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
@@ -167,4 +170,87 @@ class ProxyConsumerResolverTest {
assertThat(unavailable.connection()).isNull();
}
+
+ private NettyRemotingClient runningInfoClient(boolean twoProxies) throws
Exception {
+ ConsumerConnection syncer = new ConsumerConnection();
+ Connection first = new Connection();
+ first.setClientAddr("192.0.2.1:10911");
+ HashSet<Connection> connections = new HashSet<>(List.of(first));
+ if (twoProxies) {
+ Connection second = new Connection();
+ second.setClientAddr("192.0.2.2:10911");
+ connections.add(second);
+ }
+ syncer.setConnectionSet(connections);
+
when(adminExt.examineConsumerConnectionInfo("CID_DefaultHeartBeatSyncerTopic")).thenReturn(syncer);
+ NettyRemotingClient client = mock(NettyRemotingClient.class);
+ resolver.setRemotingClientForTest(client);
+ return client;
+ }
+
+ @Test
+ void runningInfoShouldDistinguishOfflineFromFailedResponsesTest() throws
Exception {
+ NettyRemotingClient client = runningInfoClient(false);
+ when(client.invokeSync(anyString(), any(RemotingCommand.class),
anyLong()))
+
.thenReturn(RemotingCommand.createResponseCommand(ResponseCode.CONSUMER_NOT_ONLINE,
"offline"))
+ .thenReturn(null)
+
.thenReturn(RemotingCommand.createResponseCommand(ResponseCode.SYSTEM_ERROR,
"failed"))
+
.thenReturn(RemotingCommand.createResponseCommand(ResponseCode.SUCCESS,
"missing body"));
+
+ assertThat(resolver.resolveConsumerRunningInfoStatus("instance-a",
"group", "client").available()).isTrue();
+ for (int i = 0; i < 3; i++) {
+ ProxyConsumerResolver.ConsumerRunningInfoResolution result =
+ resolver.resolveConsumerRunningInfoStatus("instance-a",
"group", "client");
+ assertThat(result.available()).isFalse();
+ assertThat(result.runningInfo()).isNull();
+ }
+ }
+
+ @Test
+ void runningInfoShouldKeepDiscoveryFailureUnavailableTest() throws
Exception {
+
when(adminExt.examineConsumerConnectionInfo("CID_DefaultHeartBeatSyncerTopic"))
+ .thenThrow(new IllegalStateException("discovery failed"));
+ assertThat(resolver.resolveConsumerRunningInfoStatus("instance-a",
"group", "client").available()).isFalse();
+ }
+
+ @Test
+ void runningInfoShouldUseSuccessfulProxyAfterAnotherFailsTest() throws
Exception {
+ NettyRemotingClient client = runningInfoClient(true);
+ ConsumerRunningInfo info = new ConsumerRunningInfo();
+ info.setJstack("worker TID: 1 STATE: RUNNABLE\n");
+ RemotingCommand success =
RemotingCommand.createResponseCommand(ResponseCode.SUCCESS, null);
+ success.setBody(info.encode());
+ when(client.invokeSync(anyString(), any(RemotingCommand.class),
anyLong()))
+ .thenThrow(new IllegalStateException("timeout"))
+ .thenReturn(success);
+
+ ProxyConsumerResolver.ConsumerRunningInfoResolution result =
+ resolver.resolveConsumerRunningInfoStatus("instance-a",
"group", "client");
+ assertThat(result.available()).isTrue();
+
assertThat(result.runningInfo().getJstack()).isEqualTo(info.getJstack());
+ }
+
+ @Test
+ void runningInfoShouldNotHideFailedProxyBehindOfflineProxyTest() throws
Exception {
+ NettyRemotingClient client = runningInfoClient(true);
+ when(client.invokeSync(anyString(), any(RemotingCommand.class),
anyLong()))
+ .thenThrow(new IllegalStateException("timeout"))
+
.thenReturn(RemotingCommand.createResponseCommand(ResponseCode.CONSUMER_NOT_ONLINE,
"offline"));
+ assertThat(resolver.resolveConsumerRunningInfoStatus("instance-a",
"group", "client").available()).isFalse();
+ }
+
+ @Test
+ void runningInfoShouldStopQueryingWhenInterruptedTest() throws Exception {
+ NettyRemotingClient client = runningInfoClient(true);
+ when(client.invokeSync(anyString(), any(RemotingCommand.class),
anyLong()))
+ .thenThrow(new InterruptedException("cancelled"));
+ try {
+ assertThatThrownBy(() ->
resolver.resolveConsumerRunningInfoStatus("instance-a", "group", "client"))
+ .isInstanceOf(BusinessException.class);
+ assertThat(Thread.currentThread().isInterrupted()).isTrue();
+ org.mockito.Mockito.verify(client).invokeSync(anyString(),
any(RemotingCommand.class), anyLong());
+ } finally {
+ Thread.interrupted();
+ }
+ }
}
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQConsumerDiagnosticsProviderTest.java
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQConsumerDiagnosticsProviderTest.java
index 6e2edea56..51dd2cd21 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQConsumerDiagnosticsProviderTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/provider/apache/RocketMQConsumerDiagnosticsProviderTest.java
@@ -38,8 +38,10 @@ import java.util.TimeZone;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -214,7 +216,7 @@ class RocketMQConsumerDiagnosticsProviderTest {
ConsumeMessageThread_1 TID: 7 STATE: RUNNABLE
ConsumeMessageThread_1
com.example.Listener.consume(Listener.java:20)
""");
- when(resolver.resolveConsumerRunningInfo("instance-a", "cg-orders",
"client-1")).thenReturn(runningInfo);
+ when(resolver.resolveConsumerRunningInfoStatus("instance-a",
"cg-orders",
"client-1")).thenReturn(ProxyConsumerResolver.ConsumerRunningInfoResolution.available(runningInfo));
org.springframework.test.util.ReflectionTestUtils.setField(provider,
"proxyConsumerResolver", resolver);
ConsumerStackTraceVO result = provider.getConsumerStack("instance-a",
"cg-orders", "client-1");
@@ -227,7 +229,7 @@ class RocketMQConsumerDiagnosticsProviderTest {
@Test
void getConsumerStackShouldFallBackToBrokerWhenNoProxyAnswersTest() throws
Exception {
ProxyConsumerResolver resolver =
org.mockito.Mockito.mock(ProxyConsumerResolver.class);
- when(resolver.resolveConsumerRunningInfo("instance-a", "cg-orders",
"client-1")).thenReturn(null);
+ when(resolver.resolveConsumerRunningInfoStatus("instance-a",
"cg-orders",
"client-1")).thenReturn(ProxyConsumerResolver.ConsumerRunningInfoResolution.available(null));
org.springframework.test.util.ReflectionTestUtils.setField(provider,
"proxyConsumerResolver", resolver);
ConsumerRunningInfo runningInfo = new ConsumerRunningInfo();
runningInfo.setJstack("PullMessageService TID: 9
STATE: WAITING\n");
@@ -261,4 +263,100 @@ class RocketMQConsumerDiagnosticsProviderTest {
.hasMessageContaining("Failed to get consumer stack for
client-1")
.satisfies(ex -> assertThat(((BusinessException)
ex).getCode()).isEqualTo(502));
}
+
+ private void proxyUnavailable() {
+ ProxyConsumerResolver resolver =
org.mockito.Mockito.mock(ProxyConsumerResolver.class);
+ when(resolver.resolveConsumerRunningInfoStatus("instance-a",
"cg-orders", "client-1"))
+
.thenReturn(ProxyConsumerResolver.ConsumerRunningInfoResolution.unavailable());
+ org.springframework.test.util.ReflectionTestUtils.setField(provider,
"proxyConsumerResolver", resolver);
+ }
+
+ @Test
+ void proxyFailureAndBrokerOfflineShouldRemainUnavailableTest() throws
Exception {
+ proxyUnavailable();
+ when(adminExt.getConsumerRunningInfo("cg-orders", "client-1", true))
+ .thenThrow(new
MQClientException(ResponseCode.CONSUMER_NOT_ONLINE, "not online"));
+
+ assertThatThrownBy(() -> provider.getConsumerStack("instance-a",
"cg-orders", "client-1"))
+ .isInstanceOf(BusinessException.class)
+ .hasMessageContaining("proxy query failed")
+ .satisfies(ex -> assertThat(((BusinessException)
ex).getCode()).isEqualTo(502));
+ }
+
+ @Test
+ void proxyFailureAndEmptyBrokerResultShouldRemainUnavailableTest() throws
Exception {
+ proxyUnavailable();
+ when(adminExt.getConsumerRunningInfo("cg-orders", "client-1",
true)).thenReturn(null);
+
+ assertThatThrownBy(() -> provider.getConsumerStack("instance-a",
"cg-orders", "client-1"))
+ .isInstanceOf(BusinessException.class)
+ .satisfies(ex -> assertThat(((BusinessException)
ex).getCode()).isEqualTo(502));
+ }
+
+ @Test
+ void proxyFailureShouldStillAllowDirectConsumerDiagnosticsTest() throws
Exception {
+ proxyUnavailable();
+ ConsumerRunningInfo runningInfo = new ConsumerRunningInfo();
+ runningInfo.setJstack("PullMessageService TID: 9 STATE: WAITING\n");
+ when(adminExt.getConsumerRunningInfo("cg-orders", "client-1",
true)).thenReturn(runningInfo);
+
+ assertThat(provider.getConsumerStack("instance-a", "cg-orders",
"client-1").getThreadCount())
+ .isEqualTo(1);
+ }
+
+ @Test
+ void interruptedBrokerQueryShouldPreserveInterruptionTest() throws
Exception {
+ when(adminExt.getConsumerRunningInfo("cg-orders", "client-1", true))
+ .thenThrow(new InterruptedException("cancelled"));
+ try {
+ assertThatThrownBy(() -> provider.getConsumerStack("instance-a",
"cg-orders", "client-1"))
+ .isInstanceOf(BusinessException.class)
+ .satisfies(ex -> assertThat(((BusinessException)
ex).getCode()).isEqualTo(503));
+ assertThat(Thread.currentThread().isInterrupted()).isTrue();
+ } finally {
+ Thread.interrupted();
+ }
+ }
+
+ /**
+ * An unknown instance is a request-level error raised while the broker
admin client is being
+ * resolved, before any stack lookup runs. A proxy that could not be asked
cannot turn it into a
+ * gateway failure, so the 404 and its instance-identifying message must
survive unchanged.
+ */
+ @Test
+ void proxyFailureShouldNotMaskUnknownInstanceAsBadGatewayTest() throws
Exception {
+ proxyUnavailable();
+ doThrow(new BusinessException(404, "Instance not found: instance-a"))
+ .when(runtimeAdminClientResolver).execute(anyString(), any());
+
+ assertThatThrownBy(() -> provider.getConsumerStack("instance-a",
"cg-orders", "client-1"))
+ .isInstanceOf(BusinessException.class)
+ .hasMessage("Instance not found: instance-a")
+ .satisfies(ex -> assertThat(((BusinessException)
ex).getCode()).isEqualTo(404));
+ verify(adminExt, never()).getConsumerRunningInfo(anyString(),
anyString(), anyBoolean());
+ }
+
+ /**
+ * The same reasoning covers the instance-level precondition errors the
resolver reports before
+ * handing out an admin client: their status code and message are not the
proxy's to rewrite.
+ */
+ @Test
+ void proxyFailureShouldNotMaskInstancePreconditionErrorsTest() {
+ proxyUnavailable();
+ doThrow(new BusinessException(422, "Instance has no admin credential
reference: legacy"))
+ .when(runtimeAdminClientResolver).execute(anyString(), any());
+
+ assertThatThrownBy(() -> provider.getConsumerStack("instance-a",
"cg-orders", "client-1"))
+ .isInstanceOf(BusinessException.class)
+ .hasMessage("Instance has no admin credential reference:
legacy")
+ .satisfies(ex -> assertThat(((BusinessException)
ex).getCode()).isEqualTo(422));
+
+ doThrow(new BusinessException(400, "Instance has no endpoint:
instance-a"))
+ .when(runtimeAdminClientResolver).execute(anyString(), any());
+
+ assertThatThrownBy(() -> provider.getConsumerStack("instance-a",
"cg-orders", "client-1"))
+ .isInstanceOf(BusinessException.class)
+ .hasMessage("Instance has no endpoint: instance-a")
+ .satisfies(ex -> assertThat(((BusinessException)
ex).getCode()).isEqualTo(400));
+ }
}
diff --git a/web/src/i18n/translations.ts b/web/src/i18n/translations.ts
index 6b367d28d..50d21c4e1 100644
--- a/web/src/i18n/translations.ts
+++ b/web/src/i18n/translations.ts
@@ -18,6 +18,16 @@
export type Lang = 'zh' | 'en';
const translations: Record<string, Record<Lang, string>> = {
+ 'consumer.stackCaptureFailed': { zh: '线程栈采集失败', en: 'Stack capture failed' },
+ 'consumer.stackCaptureRetry': {
+ zh: '请检查客户端连接后重试。',
+ en: 'Check the client connection and retry.',
+ },
+ 'consumer.stackEmpty': { zh: '客户端未返回线程栈', en: 'The client returned no thread
stack' },
+ 'consumer.stackEmptyHint': {
+ zh: '该客户端可能不支持线程栈采集,或本次响应不包含线程栈。',
+ en: 'The client may not support stack capture, or this response contains
no thread stack.',
+ },
// ─── Navigation ───
'nav.home': { zh: '首页', en: 'Home' },
'nav.dashboard': { zh: '监控面板', en: 'Dashboard' },
diff --git a/web/src/pages/instance/__tests__/ConsumerPage.test.tsx
b/web/src/pages/instance/__tests__/ConsumerPage.test.tsx
index bd8a2f406..cd5ec98e9 100644
--- a/web/src/pages/instance/__tests__/ConsumerPage.test.tsx
+++ b/web/src/pages/instance/__tests__/ConsumerPage.test.tsx
@@ -1537,6 +1537,43 @@ describe('Consumer page', () => {
).toBeInTheDocument();
});
+ it.each([
+ ['zh', '线程栈采集失败'],
+ ['en', 'Stack capture failed'],
+ ])(
+ 'shows a stack query failure in %s without claiming capture is
unsupported',
+ async (lang, label) => {
+ window.localStorage.setItem('rocketmq-studio-language', lang);
+ vi.mocked(consumerService.listConsumerGroupPage).mockResolvedValue(
+ groupPage([
+ {
+ ...group,
+ instances: [
+ {
+ clientId: 'client-1',
+ protocol: 'Remoting',
+ address: '10.0.0.1:39210',
+ subscribedTopics: [],
+ lastHeartbeat: '',
+ topicLag: {},
+ },
+ ],
+ },
+ ]),
+ );
+ vi.mocked(consumerService.getConsumerStack).mockRejectedValue(
+ new Error('proxy query failed'),
+ );
+ const user = userEvent.setup({ pointerEventsCheck: 0 });
+ renderWithProviders(<ConsumerPage />);
+ await user.click(await screen.findByRole('button', { name: /详情|Detail/i
}));
+ await user.click(await screen.findByRole('button', { name: /线程栈/ }));
+ expect(await screen.findByText(label)).toBeInTheDocument();
+ expect(screen.getByText('proxy query failed')).toBeInTheDocument();
+ expect(screen.queryByText('暂不支持采集该客户端的线程栈')).not.toBeInTheDocument();
+ },
+ );
+
it('renders the stack capture time in the viewer timezone from the
offset-less UTC wire format', async () => {
// The backend serializes LocalDateTime without an offset, so capturedAt
arrives as a UTC wall
// clock; parsing it as browser-local would shift the shown capture time
by the viewer's zone.
diff --git a/web/src/pages/instance/consumer.tsx
b/web/src/pages/instance/consumer.tsx
index 41b426e92..d5d6c832c 100644
--- a/web/src/pages/instance/consumer.tsx
+++ b/web/src/pages/instance/consumer.tsx
@@ -2444,6 +2444,13 @@ const ConsumerPageContent = ({
pagination={false}
size="small"
/>
+ ) : stackError !== null ? (
+ <Alert
+ type="error"
+ showIcon
+ message={t('consumer.stackCaptureFailed')}
+ description={stackError || t('consumer.stackCaptureRetry')}
+ />
) : selectedStack && selectedStack.threads.length > 0 ? (
selectedStack.threads.map((thread) => (
<Card
@@ -2478,19 +2485,8 @@ const ConsumerPageContent = ({
<Alert
type="info"
showIcon
- message="暂不支持采集该客户端的线程栈"
- description={
- <>
- <div>
- 经 Proxy 接入的客户端(gRPC、经 Proxy 的 Remoting)只在 Proxy
侧保持连接,Broker
- 看不到它们;而 Proxy 目前未开放线程栈采集接口,因此这类客户端暂时无法采集。 直连
- Broker 的客户端可正常查看。
- </div>
- {stackError && (
- <div style={{ marginTop: 8, color: 'rgba(0,0,0,0.45)'
}}>{stackError}</div>
- )}
- </>
- }
+ message={t('consumer.stackEmpty')}
+ description={t('consumer.stackEmptyHint')}
/>
)}
</Space>