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 50710962e fix: pending-question stream guard, ARMS bearer token and
alerting API docs (#5289)
50710962e is described below
commit 50710962ea6a8df907a64c405ee5e8a1903916e9
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 11:46:43 2026 +0800
fix: pending-question stream guard, ARMS bearer token and alerting API docs
(#5289)
Integration batch (same author Frun1na): #5269 alerting design API docs +
#5277 ARMS raw bearer token + #5289 keep pending question when run never
admitted.
---
docs/studio-native-alerting-design.md | 22 +++++++-----
.../AbstractPrometheusCompatibleMetricsSource.java | 8 ++++-
.../rocketmq/studio/settings/SettingsService.java | 11 ++++++
.../metrics/MultiBackendMetricsSourceTest.java | 41 +++++++++++++++++++++
web/src/pages/ai/hooks/useAgentRun.test.ts | 42 ++++++++++++++++++++++
web/src/pages/ai/hooks/useAgentRun.ts | 15 +++++---
6 files changed, 125 insertions(+), 14 deletions(-)
diff --git a/docs/studio-native-alerting-design.md
b/docs/studio-native-alerting-design.md
index bbddc7004..e95e76bb2 100644
--- a/docs/studio-native-alerting-design.md
+++ b/docs/studio-native-alerting-design.md
@@ -294,21 +294,25 @@ Silences match `domain`, rule ID, instance ID, and
optional resource labels. The
## APIs
-The two rule menus keep separate endpoints so their domain cannot be
accidentally changed by a client. Both delegate to the same `AlertRuleService`.
+The two rule menus keep separate endpoints so their domain cannot be
accidentally changed by a client. Both delegate to the same `AlertService`.
```text
-GET/POST/PUT /api/business-alert-rules
-GET/POST/PUT /api/cluster-alert-rules
-POST /api/business-alert-rules/{id}/test
-POST /api/cluster-alert-rules/{id}/test
-
-GET /api/system-alerts?domain=&status=&severity=&instanceId=&page=
-POST /api/system-alerts/{id}/acknowledge
+GET /api/business-alert-rules/page
+POST /api/business-alert-rules/create
+POST /api/business-alert-rules/update
+POST /api/business-alert-rules/test
+GET /api/cluster-alert-rules/page
+POST /api/cluster-alert-rules/create
+POST /api/cluster-alert-rules/update
+POST /api/cluster-alert-rules/test
+
+GET /api/system-alerts?level=&domain=&instanceId=&transition=
+POST /api/system-alerts/acknowledge
GET/POST /api/alert-silences
DELETE /api/alert-silences/{id}
GET /api/alert-collector-status
-GET /api/alert-metric-catalog?instanceId=&domain=
+GET /api/native-alert-metrics?instanceId=&domain=
```
Existing `/api/alert-rules/export` remains as a compatibility endpoint for
users who deliberately export rules to Prometheus. It must not be used by the
native evaluator.
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/cluster/metrics/AbstractPrometheusCompatibleMetricsSource.java
b/server/src/main/java/org/apache/rocketmq/studio/cluster/metrics/AbstractPrometheusCompatibleMetricsSource.java
index 4e8bcf396..a8d9e6ff9 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/cluster/metrics/AbstractPrometheusCompatibleMetricsSource.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/cluster/metrics/AbstractPrometheusCompatibleMetricsSource.java
@@ -216,7 +216,13 @@ public abstract class
AbstractPrometheusCompatibleMetricsSource implements Metri
throw new
PrometheusException(HttpStatus.SERVICE_UNAVAILABLE.value(),
backendLabel() + " bearer authentication is
incomplete");
}
- headers.setBearerAuth(settings.getBearerToken());
+ if (backendType() == MetricsBackendType.ARMS) {
+ // ARMS V1 token auth matches the Authorization header
exactly; a "Bearer "
+ // prefix breaks it (Aliyun ARMS HTTP API docs:
Authorization: {Token}).
+ headers.set("Authorization", settings.getBearerToken());
+ } else {
+ headers.setBearerAuth(settings.getBearerToken());
+ }
}
default -> throw new
PrometheusException(HttpStatus.SERVICE_UNAVAILABLE.value(),
"Unsupported " + backendLabel() + " authentication mode: "
+ settings.getAuthType());
diff --git
a/server/src/main/java/org/apache/rocketmq/studio/settings/SettingsService.java
b/server/src/main/java/org/apache/rocketmq/studio/settings/SettingsService.java
index 8fd16dc17..9fe309835 100644
---
a/server/src/main/java/org/apache/rocketmq/studio/settings/SettingsService.java
+++
b/server/src/main/java/org/apache/rocketmq/studio/settings/SettingsService.java
@@ -406,12 +406,23 @@ public class SettingsService {
if (!StringUtils.hasText(request.getBearerToken())) {
throw new IllegalArgumentException("Bearer authentication
requires token");
}
+ if (isArmsDataSource(request.getType())) {
+ // ARMS V1 token auth matches the Authorization header
exactly; a "Bearer "
+ // prefix breaks it (Aliyun ARMS HTTP API docs: Authorization:
{Token}).
+ headers.set("Authorization", request.getBearerToken().trim());
+ return;
+ }
headers.setBearerAuth(request.getBearerToken().trim());
return;
}
throw new IllegalArgumentException("Unsupported data source
authentication: " + request.getAuth());
}
+ private boolean isArmsDataSource(String type) {
+ return "arms".equals(type == null ? null
+ : type.replaceAll("\\s+", "").toLowerCase(Locale.ROOT));
+ }
+
private String normalizeAuth(String auth) {
if (!StringUtils.hasText(auth)) {
return AUTH_NONE;
diff --git
a/server/src/test/java/org/apache/rocketmq/studio/cluster/metrics/MultiBackendMetricsSourceTest.java
b/server/src/test/java/org/apache/rocketmq/studio/cluster/metrics/MultiBackendMetricsSourceTest.java
index cd49a949c..b78d914a5 100644
---
a/server/src/test/java/org/apache/rocketmq/studio/cluster/metrics/MultiBackendMetricsSourceTest.java
+++
b/server/src/test/java/org/apache/rocketmq/studio/cluster/metrics/MultiBackendMetricsSourceTest.java
@@ -118,6 +118,18 @@ class MultiBackendMetricsSourceTest {
assertAuthorization("bearer", "user", "password", "token", "Bearer
token");
}
+ @Test
+ void armsBearerAuthenticationSendsTheRawToken() {
+ // ARMS V1 token auth matches the Authorization header exactly; a
"Bearer " prefix
+ // breaks it — the Aliyun ARMS HTTP API docs specify Authorization:
{Token} (raw).
+ assertArmsAuthorization("bearer", "token", "token");
+ }
+
+ @Test
+ void prometheusBearerAuthenticationKeepsTheBearerPrefix() {
+ assertAuthorization("bearer", "user", "password", "token", "Bearer
token");
+ }
+
@Test
void authenticationModeShouldRejectMissingRequiredCredentials() {
assertAuthenticationFailure("basic", "user", null, null,
@@ -158,6 +170,35 @@ class MultiBackendMetricsSourceTest {
});
}
+ private void assertArmsAuthorization(String authType, String bearerToken,
+ String expectedAuthorization) {
+ AtomicReference<String> authorization = new AtomicReference<>();
+ server.createContext(MetricsBackendType.ARMS.getQueryPath(), exchange
-> {
+
authorization.set(exchange.getRequestHeaders().getFirst("Authorization"));
+ respond(exchange, 200, """
+
{"status":"success","data":{"resultType":"matrix","result":[]}}
+ """);
+ });
+
+ MetricsSourceSettings settings = MetricsSourceSettings.builder()
+ .backendType(MetricsBackendType.ARMS)
+ .baseUrl(baseUrl)
+ .authType(authType)
+ .bearerToken(bearerToken)
+ .build();
+ new ArmsMetricsSource(restClientBuilder, objectMapper, settings) {
+ @Override
+ protected void validateQueryHost(String url) {
+ if (url != null && url.startsWith(baseUrl)) {
+ return;
+ }
+ super.validateQueryHost(url);
+ }
+ }.query(query());
+
+ assertThat(authorization.get()).isEqualTo(expectedAuthorization);
+ }
+
private MetricsSource loopbackPrometheusSource(MetricsDataSourceConfig
config) {
MetricsSourceSettings settings = MetricsSourceSettings.builder()
.backendType(MetricsBackendType.PROMETHEUS)
diff --git a/web/src/pages/ai/hooks/useAgentRun.test.ts
b/web/src/pages/ai/hooks/useAgentRun.test.ts
index 4f7ece3ea..8d02f405c 100644
--- a/web/src/pages/ai/hooks/useAgentRun.test.ts
+++ b/web/src/pages/ai/hooks/useAgentRun.test.ts
@@ -308,6 +308,48 @@ describe('useAgentRun', () => {
expect(result.current.isStreaming).toBe(false);
});
+ it('keepsThePendingUserBubbleWhenTheStreamFailsBeforeAdmissionTest', async
() => {
+ const refetchTimeline = vi.fn().mockResolvedValue(undefined);
+ const { result } = render({ refetchTimeline });
+
+ let sent!: Promise<void>;
+ await act(async () => {
+ sent = result.current.send(7, { message: '这个问题还会在吗' });
+ });
+ expect(result.current.pendingUserMessage).toBe('这个问题还会在吗');
+
+ // The stream dies before any frame (e.g. connection refused): the run was
never admitted,
+ // so the refetched transcript has no user row and the question must stay
on screen.
+ await act(async () => {
+ openedStreams[0].fail(new Error('connection refused'));
+ await flushFrame();
+ await sent;
+ });
+
+ expect(refetchTimeline).toHaveBeenCalledTimes(1);
+ expect(result.current.pendingUserMessage).toBe('这个问题还会在吗');
+ });
+
+
it('clearsThePendingUserBubbleWhenTheRunWasAdmittedBeforeTheStreamFailedTest',
async () => {
+ const refetchTimeline = vi.fn().mockResolvedValue(undefined);
+ const { result } = render({ refetchTimeline });
+
+ let sent!: Promise<void>;
+ await act(async () => {
+ sent = result.current.send(7, { message: '已入废的问题' });
+ });
+ await act(async () => {
+ openedStreams[0].emit(runStarted());
+ openedStreams[0].fail(new Error('stream broken mid-run'));
+ await flushFrame();
+ await sent;
+ });
+
+ // Admission happened, so the refetched transcript carries the persisted
user row: the
+ // optimistic twin must go instead of painting the question twice.
+ expect(result.current.pendingUserMessage).toBeNull();
+ });
+
it('clearsTheStoppingStateWhenTheStreamDiesWithoutTerminalFramesTest', async
() => {
const refetchTimeline = vi.fn().mockRejectedValue(new Error('timeline
unavailable'));
const { result } = render({ refetchTimeline });
diff --git a/web/src/pages/ai/hooks/useAgentRun.ts
b/web/src/pages/ai/hooks/useAgentRun.ts
index 01e205643..a70353e6b 100644
--- a/web/src/pages/ai/hooks/useAgentRun.ts
+++ b/web/src/pages/ai/hooks/useAgentRun.ts
@@ -165,13 +165,16 @@ export function useAgentRun(
*/
const [pendingUserMessage, setPendingUserMessage] = useState<string |
null>(null);
- const generationRef = useRef(0);
- const streamRequestIdRef = useRef(0);
+ const generationRef = useRef(0); const streamRequestIdRef = useRef(0);
const chatInFlightRef = useRef(false);
const runEndedRef = useRef(true);
const abortControllerRef = useRef<AbortController | null>(null);
const frameRef = useRef<number | null>(null);
const runIdRef = useRef<number | null>(null);
+ // Whether the in-flight run was admitted server-side: the `run_started`
frame is the proof. A
+ // stream that died before any frame arrived never admitted the run, so the
transcript cannot
+ // have gained the user row and the optimistic question must stay on screen.
+ const admittedRef = useRef(false);
const conversationIdRef = useRef<number | null>(conversationId);
// Callbacks arrive as fresh closures on every render; keeping them in a ref
is what lets `send`,
@@ -207,6 +210,7 @@ export function useAgentRun(
switch (event.type) {
case 'run_started':
+ admittedRef.current = true;
runIdRef.current = event.runId;
setRunId(event.runId);
optionsRef.current.onRunStarted?.(event);
@@ -293,8 +297,10 @@ export function useAgentRun(
// refetch swaps the live bubble for its persisted twin, which is what
displays it.
setLastRunTokensPerSecond(speedTrackerRef.current.tokensPerSecond());
// The refetched transcript now renders the persisted user row; drop the
optimistic twin in
- // the same commit so it never paints twice.
- setPendingUserMessage(null);
+ // the same commit so it never paints twice. When the stream failed
WITHOUT a `run_started`
+ // frame the run was never admitted: the transcript cannot have gained
the user row, so the
+ // optimistic question stays instead of vanishing from the screen.
+ if (streamFailure === null || admittedRef.current)
setPendingUserMessage(null);
blocksRef.current = [];
scheduleTick();
},
@@ -331,6 +337,7 @@ export function useAgentRun(
cancelFrame();
blocksRef.current = [];
+ admittedRef.current = false;
speedTrackerRef.current = createStreamSpeedTracker();
// A fresh run starts: the speed of the previous one no longer belongs
to the bubble on
// screen once this run's answer lands.