unbridled-41 opened a new pull request, #5447:
URL: https://github.com/apache/rocketmq-dashboard/pull/5447
## Problem / Evidence
An alert rule created on a native metric is saved without its unit, so the
rule list renders `> 12000` and a notification template's `${thresholdUnit}`
expands to nothing.
- `web/src/pages/ops/alerts.tsx:1152-1158` — picking a metric stores the
unit in the form: `nativeRatioMetrics.has(metric) ? '%' :
(metricInfo?.thresholdUnit ?? '')`, and the input's `addonAfter` renders it
(`:1246`).
- `web/src/pages/ops/alertRulePayload.ts:61` (pre-fix) — the payload builder
ignored that field and re-derived the unit from `thresholdUnits`, a map of the
five built-in metric names only:
```ts
thresholdUnit: thresholdUnits[metric] ?? '',
```
The native catalog's metrics (`consumer.lag.total`, `consumer.lag.queue`,
`topic.backlog.total`, `dlq.message.count` → `messages`;
`consumer.delay.seconds` → `seconds`,
`NativeAlertMetricCatalogService.java:29-46`) are not in that map, so `''` was
submitted and stored; `thresholdUnitLabel` (`alerts.tsx:219-225`) already knows
how to render `messages`/`seconds`, it simply never received them.
Reproduction: `/ops/alerts` → 新建规则 → instance + 消费积压总量 (unit shown in the
input) → threshold 12000 → save → the row shows `> 12000` with no unit; an edit
of the same rule shows the unit again, because the form re-derives it.
## Root cause / Fix
The form's resolved unit was thrown away in favour of a map that only covers
the legacy metric names:
```ts
thresholdUnit: thresholdUnits[metric] ?? values.thresholdUnit ?? '',
```
The map stays authoritative for the five names it knows — so a stale unit
left over from another metric pick still cannot survive (pinned by
`alerts.test.ts > overwrites stale units when a metric changes`) — while every
other metric keeps the unit the form resolved.
## Priority & scoring
PRIORITY 50 = 影响 18 (the saved rule loses the unit shown at authoring time,
in the list and in notification templates) + 波及 5 (alert rule create/update) +
可复现 20 (deterministic for every native metric) + 维护价值 7.
FIX_CONFIDENCE 80: a one-line precedence change plus a focused unit test;
the pre-existing overwrite test still passes unchanged.
## Tests
```
cd web && npx vitest run src/pages/ops/__tests__/alertRulePayload.test.ts
src/pages/ops/__tests__/alerts.test.ts
```
- Red before the fix: `keeps the unit the form resolved for a native metric`
and `keeps a ratio metric percentage` fail (`expected '' to be '%'`).
- Green after: `Tests 8 passed (8)`; the whole ops suite: `Test Files 12
passed (12) | Tests 102 passed (102)`.
- `npx tsc -b` and `npx eslint` on both files: clean.
## Risk
Low. Only the precedence between two unit sources changes; a rule whose
metric is one of the five built-in names keeps exactly the previous behaviour.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]