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 67e16a880 fix(consumer): retain measured aggregate backlog in health 
diagnostics (#7394)
67e16a880 is described below

commit 67e16a8809884f8be22e1dc6c664eeae0a9f62c9
Author: zmuxuny <[email protected]>
AuthorDate: Fri Nov 27 12:29:33 2026 +0800

    fix(consumer): retain measured aggregate backlog in health diagnostics 
(#7394)
---
 .../alert/AlertRuleEvaluationConcurrencyTest.java  |   9 +-
 web/src/api/metadata.ts                            |   2 +
 .../pages/instance/__tests__/ConsumerPage.test.tsx |  73 +++++++++
 web/src/utils/consumerGroupDiagnostics.test.ts     | 174 +++++++++++++++++++++
 web/src/utils/consumerGroupDiagnostics.ts          |  12 +-
 5 files changed, 261 insertions(+), 9 deletions(-)

diff --git 
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertRuleEvaluationConcurrencyTest.java
 
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertRuleEvaluationConcurrencyTest.java
index e64585ba9..679ba06a5 100644
--- 
a/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertRuleEvaluationConcurrencyTest.java
+++ 
b/server/src/test/java/org/apache/rocketmq/studio/ops/alert/AlertRuleEvaluationConcurrencyTest.java
@@ -103,13 +103,14 @@ class AlertRuleEvaluationConcurrencyTest {
     /**
      * Observes the management write actually waiting on the evaluation's row 
lock, instead of
      * inferring it from "still unfinished after a fixed delay" - a slow 
runner would pass such an
-     * assertion without ever reaching the statement. MySQL reports the wait in
-     * information_schema.innodb_trx, the dev/H2 profile in 
INFORMATION_SCHEMA.SESSIONS, so the
-     * check stays deterministic on both datasources and is skipped on neither.
+     * assertion without ever reaching the statement. MySQL reports live waits 
in
+     * performance_schema.data_lock_waits; polling innodb_trx faster than its 
100 ms idle cache
+     * refresh interval can keep returning an old snapshot. The dev/H2 profile 
uses
+     * INFORMATION_SCHEMA.SESSIONS, so neither datasource skips the check.
      */
     private boolean awaitManagementLockWait(long timeoutMillis) throws 
InterruptedException {
         String waitingSessions = "MySQL".equals(databaseProduct())
-                ? "SELECT COUNT(*) FROM information_schema.innodb_trx WHERE 
trx_state = 'LOCK WAIT'"
+                ? "SELECT COUNT(*) FROM performance_schema.data_lock_waits"
                 : "SELECT COUNT(*) FROM INFORMATION_SCHEMA.SESSIONS WHERE 
SESSION_STATE = 'BLOCKED'";
         long deadline = System.nanoTime() + 
TimeUnit.MILLISECONDS.toNanos(timeoutMillis);
         while (System.nanoTime() < deadline) {
diff --git a/web/src/api/metadata.ts b/web/src/api/metadata.ts
index 2b2d6042e..1d0a58a74 100644
--- a/web/src/api/metadata.ts
+++ b/web/src/api/metadata.ts
@@ -116,6 +116,8 @@ export interface ConsumerGroup {
   /** Confirmed online clients; -1 means the connection inventory is 
unavailable. */
   onlineInstances: number;
   totalLag: number;
+  /** Explicit false means the aggregate consumption statistics are 
unavailable. */
+  consumeStatsAvailable?: boolean;
   subscribedTopics: string[];
   subscriptionDataType: string;
   deliveryOrderType?: string;
diff --git a/web/src/pages/instance/__tests__/ConsumerPage.test.tsx 
b/web/src/pages/instance/__tests__/ConsumerPage.test.tsx
index 4fe8cbb24..55648ed3c 100644
--- a/web/src/pages/instance/__tests__/ConsumerPage.test.tsx
+++ b/web/src/pages/instance/__tests__/ConsumerPage.test.tsx
@@ -926,6 +926,79 @@ describe('Consumer page', () => {
     expect(screen.queryByText('SQL')).not.toBeInTheDocument();
   });
 
+  it.each([
+    { totalLag: 1_000, consumeStatsAvailable: true, partial: false, title: 
'Group 总堆积偏高' },
+    { totalLag: 10_000, consumeStatsAvailable: true, partial: false, title: 
'Group 总堆积过高' },
+    {
+      totalLag: 10_000,
+      consumeStatsAvailable: undefined,
+      partial: false,
+      title: 'Group 总堆积过高',
+    },
+    { totalLag: 10_000, consumeStatsAvailable: true, partial: true, title: 
'Group 总堆积过高' },
+  ])(
+    'shows measured aggregate backlog risk at $totalLag with availability 
$consumeStatsAvailable and partial queues $partial Test',
+    async ({ totalLag, consumeStatsAvailable, partial, title }) => {
+      const backloggedGroup: ConsumerGroup = {
+        ...group,
+        totalLag,
+        ...(consumeStatsAvailable === undefined ? {} : { consumeStatsAvailable 
}),
+        instances: [],
+      };
+      vi.mocked(consumerService.listConsumerGroupPage).mockResolvedValue(
+        groupPage([backloggedGroup]),
+      );
+      
vi.mocked(consumerService.refreshConsumerGroup).mockResolvedValue(backloggedGroup);
+      vi.mocked(consumerService.getConsumerSubscriptions).mockResolvedValue([
+        {
+          topic: 'remote-topic',
+          expression: '*',
+          type: 'TAG',
+          filterMode: 'TAG',
+          consistency: 'consistent',
+        },
+      ]);
+      vi.mocked(consumerService.getConsumerProgress).mockResolvedValue(
+        partial
+          ? [
+              {
+                topic: 'remote-topic',
+                broker: 'broker-a',
+                queueId: 0,
+                brokerOffset: 17,
+                consumerOffset: 0,
+                diffTotal: 17,
+              },
+              {
+                topic: 'remote-topic',
+                broker: 'broker-b',
+                queueId: 1,
+                brokerOffset: -1,
+                consumerOffset: -1,
+                diffTotal: -1,
+              },
+            ]
+          : [],
+      );
+      const user = userEvent.setup();
+      renderWithProviders(<ConsumerPage />);
+      const detailButton = await screen.findByRole('button', { name: /详情/ });
+      await expectInteractive(detailButton);
+      await user.click(detailButton);
+      const healthTab = await screen.findByRole('tab', { name: /健康诊断/ });
+      await expectInteractive(healthTab);
+      await user.click(healthTab);
+      const panel = await screen.findByRole('tabpanel', { name: /健康诊断/ });
+      await waitFor(() => 
expect(consumerService.getConsumerProgress).toHaveBeenCalled());
+      expect(await within(panel).findByText(title)).toBeInTheDocument();
+      expect(within(panel).getAllByText(title)).toHaveLength(1);
+      expect(within(panel).queryByText('未发现消费组健康风险')).not.toBeInTheDocument();
+      if (partial) {
+        expect(await within(panel).findByText('部分 Queue 
堆积不可用')).toBeInTheDocument();
+      }
+    },
+  );
+
   it('shows group health diagnostics from subscriptions, progress and 
clients', async () => {
     const riskyGroup: ConsumerGroup = {
       ...group,
diff --git a/web/src/utils/consumerGroupDiagnostics.test.ts 
b/web/src/utils/consumerGroupDiagnostics.test.ts
index 02402de34..d0c674bf3 100644
--- a/web/src/utils/consumerGroupDiagnostics.test.ts
+++ b/web/src/utils/consumerGroupDiagnostics.test.ts
@@ -282,3 +282,177 @@ describe('consumer group diagnostics', () => {
     expect(diagnostics.issues.map((item) => 
item.code)).toContain('NO_ACTIVE_CLIENTS_WITH_LAG');
   });
 });
+
+describe('measured group lag without queue observations', () => {
+  it.each([1_000, 10_000])('retains measured aggregate risk at %i messages', 
(totalLag) => {
+    const diagnostics = analyzeConsumerGroupHealth(
+      group({ totalLag, consumeStatsAvailable: true, instances: [] }),
+      [subscription()],
+      [],
+      { now: '2026-08-31T12:01:00Z' },
+    );
+    expect(diagnostics.summary.reportedLag).toBe(totalLag);
+    expect(diagnostics.issues).toContainEqual(
+      expect.objectContaining({
+        code: 'HIGH_GROUP_LAG',
+        severity: totalLag >= 10_000 ? 'critical' : 'warning',
+      }),
+    );
+  });
+});
+
+describe('independent backlog observations', () => {
+  it.each([
+    { totalLag: 10_000, queueLag: 17, expected: 'critical' },
+    { totalLag: 17, queueLag: 10_000, expected: 'critical' },
+    { totalLag: 10_000, queueLag: 10_000, expected: 'critical' },
+    { totalLag: -1, queueLag: 1_000, expected: 'warning' },
+  ])(
+    'uses positive evidence once for $totalLag / $queueLag',
+    ({ totalLag, queueLag, expected }) => {
+      const diagnostics = analyzeConsumerGroupHealth(
+        group({ totalLag, consumeStatsAvailable: true, instances: [] }),
+        [subscription()],
+        [queue({ diffTotal: queueLag })],
+      );
+      const findings = diagnostics.issues.filter((item) => item.code === 
'HIGH_GROUP_LAG');
+      expect(findings).toHaveLength(1);
+      expect(findings[0].severity).toBe(expected);
+    },
+  );
+
+  it.each([0, -1, Number.NaN, Number.POSITIVE_INFINITY])(
+    'does not invent high backlog from %s',
+    (totalLag) => {
+      const diagnostics = analyzeConsumerGroupHealth(
+        group({ totalLag, instances: [] }),
+        [subscription()],
+        [],
+      );
+      expect(diagnostics.issues.some((item) => item.code === 
'HIGH_GROUP_LAG')).toBe(false);
+    },
+  );
+
+  it('retains independent queue evidence when aggregate statistics are 
unavailable', () => {
+    const diagnostics = analyzeConsumerGroupHealth(
+      group({ totalLag: 10_000, consumeStatsAvailable: false, instances: [] }),
+      [subscription()],
+      [queue({ diffTotal: 1_000 })],
+    );
+    expect(diagnostics.issues.filter((item) => item.code === 
'HIGH_GROUP_LAG')).toEqual([
+      expect.objectContaining({ severity: 'warning' }),
+    ]);
+  });
+
+  it('does not trust an explicitly unavailable aggregate', () => {
+    const diagnostics = analyzeConsumerGroupHealth(
+      group({ totalLag: 10_000, consumeStatsAvailable: false, instances: [] }),
+      [subscription()],
+      [],
+    );
+    expect(diagnostics.issues.some((item) => item.code === 
'HIGH_GROUP_LAG')).toBe(false);
+  });
+});
+
+describe('measured aggregate regression controls', () => {
+  it.each([
+    { totalLag: 999, expected: undefined },
+    { totalLag: 1_000, expected: 'warning' },
+    { totalLag: 9_999, expected: 'warning' },
+    { totalLag: 10_000, expected: 'critical' },
+  ])('honors aggregate threshold boundaries at $totalLag Test', ({ totalLag, 
expected }) => {
+    // Older API objects omit the availability flag; a valid reported lag is 
still evidence.
+    const diagnostics = analyzeConsumerGroupHealth(
+      group({ totalLag, instances: [] }),
+      [subscription()],
+      [],
+    );
+    const findings = diagnostics.issues.filter((item) => item.code === 
'HIGH_GROUP_LAG');
+    expect(findings).toHaveLength(expected ? 1 : 0);
+    if (expected) expect(findings[0].severity).toBe(expected);
+    expect(diagnostics.summary.reportedLag).toBe(totalLag);
+  });
+
+  it.each([1_000, 10_000])(
+    'keeps measured aggregate evidence beside partial queues at %i Test',
+    (totalLag) => {
+      const diagnostics = analyzeConsumerGroupHealth(
+        group({ totalLag, consumeStatsAvailable: true, instances: [] }),
+        [subscription()],
+        [queue({ diffTotal: 17 }), queue({ queueId: 1, diffTotal: -1 })],
+      );
+      expect(diagnostics.summary).toMatchObject({
+        reportedLag: totalLag,
+        totalKnownLag: 17,
+        unknownQueueCount: 1,
+      });
+      expect(diagnostics.issues.filter((item) => item.code === 
'HIGH_GROUP_LAG')).toEqual([
+        expect.objectContaining({ severity: totalLag >= 10_000 ? 'critical' : 
'warning' }),
+      ]);
+      expect(diagnostics.issues.map((item) => 
item.code)).toContain('UNKNOWN_QUEUE_LAG');
+    },
+  );
+
+  it.each([-1, Number.NaN, Number.POSITIVE_INFINITY, 
Number.NEGATIVE_INFINITY])(
+    'preserves an unknown total and independent queue evidence for %s Test',
+    (totalLag) => {
+      const diagnostics = analyzeConsumerGroupHealth(
+        group({ totalLag, consumeStatsAvailable: true, instances: [] }),
+        [subscription()],
+        [queue({ diffTotal: 1_000 }), queue({ queueId: 1, diffTotal: -1 })],
+      );
+      expect(diagnostics.summary).toMatchObject({
+        reportedLag: null,
+        totalKnownLag: 1_000,
+        unknownQueueCount: 1,
+      });
+      expect(diagnostics.issues.filter((item) => item.code === 
'HIGH_GROUP_LAG')).toEqual([
+        expect.objectContaining({ severity: 'warning' }),
+      ]);
+    },
+  );
+
+  it('does not add overlapping aggregate and queue observations Test', () => {
+    const diagnostics = analyzeConsumerGroupHealth(
+      group({ totalLag: 9_000, consumeStatsAvailable: true, instances: [] }),
+      [subscription()],
+      [queue({ diffTotal: 9_000 })],
+    );
+    expect(diagnostics.issues.filter((item) => item.code === 
'HIGH_GROUP_LAG')).toEqual([
+      expect.objectContaining({ severity: 'warning' }),
+    ]);
+    expect(diagnostics.summary.reportedLag).toBe(9_000);
+  });
+
+  it.each([false, undefined])(
+    'retains queue-only risk with aggregate availability %s Test',
+    (consumeStatsAvailable) => {
+      const diagnostics = analyzeConsumerGroupHealth(
+        group({ totalLag: 0, consumeStatsAvailable, instances: [] }),
+        [subscription()],
+        [queue({ diffTotal: 10_000 })],
+      );
+      expect(diagnostics.issues.filter((item) => item.code === 
'HIGH_GROUP_LAG')).toEqual([
+        expect.objectContaining({ severity: 'critical' }),
+      ]);
+    },
+  );
+
+  it('uses configured aggregate thresholds without inventing queue 
observations Test', () => {
+    const diagnostics = analyzeConsumerGroupHealth(
+      group({ totalLag: 25, consumeStatsAvailable: true, instances: [] }),
+      [subscription()],
+      [],
+      { highLagThreshold: 10, criticalLagThreshold: 25 },
+    );
+    expect(diagnostics.issues.filter((item) => item.code === 
'HIGH_GROUP_LAG')).toEqual([
+      expect.objectContaining({ severity: 'critical' }),
+    ]);
+    expect(diagnostics.summary).toMatchObject({
+      queueCount: 0,
+      maxQueueLag: null,
+      totalKnownLag: 0,
+      reportedLag: 25,
+    });
+  });
+});
diff --git a/web/src/utils/consumerGroupDiagnostics.ts 
b/web/src/utils/consumerGroupDiagnostics.ts
index 83d923855..9cc0643df 100644
--- a/web/src/utils/consumerGroupDiagnostics.ts
+++ b/web/src/utils/consumerGroupDiagnostics.ts
@@ -227,7 +227,7 @@ const subscriptionIssues = (subscriptions: 
SubscriptionEntry[]): ConsumerGroupHe
 };
 
 const progressIssues = (
-  progress: QueueProgress[],
+  totalLag: number,
   knownQueueLags: number[],
   unknownQueueCount: number,
   options: Required<
@@ -237,11 +237,8 @@ const progressIssues = (
     >
   >,
 ): ConsumerGroupHealthIssue[] => {
-  if (progress.length === 0) return [];
-
   const issues: ConsumerGroupHealthIssue[] = [];
   const skew = lagSkewRatio(knownQueueLags);
-  const totalLag = knownQueueLags.reduce((sum, lag) => sum + lag, 0);
 
   if (unknownQueueCount > 0) {
     issues.push(
@@ -427,13 +424,18 @@ export const analyzeConsumerGroupHealth = (
   const totalKnownLag = knownLag(progress);
   const allQueuesKnown = progress.length > 0 && knownQueueLags.length === 
progress.length;
   const summaryReportedLag = reportedLag(group, allQueuesKnown ? totalKnownLag 
: null);
+  // Independently collected aggregate and queue observations may have 
different coverage.
+  const diagnosticLag = Math.max(
+    totalKnownLag,
+    group.consumeStatsAvailable !== false && isLagAvailable(group.totalLag) ? 
group.totalLag : 0,
+  );
   const unknownQueueCount = progress.length - knownQueueLags.length;
   const heartbeatAges = (group.instances ?? [])
     .map((client) => heartbeatAgeSeconds(client.lastHeartbeat, now))
     .filter((age): age is number => age !== null);
   const issues = [
     ...subscriptionIssues(subscriptions),
-    ...progressIssues(progress, knownQueueLags, unknownQueueCount, 
normalizedOptions),
+    ...progressIssues(diagnosticLag, knownQueueLags, unknownQueueCount, 
normalizedOptions),
     ...runtimeIssues(group, summaryReportedLag ?? totalKnownLag, now, 
normalizedOptions),
   ];
   const status = maxStatus(issues);

Reply via email to