unbridled-41 opened a new pull request, #5891:
URL: https://github.com/apache/rocketmq-dashboard/pull/5891
### Which Issue(s) This PR Fixes
Fixes #5890
### Problem / Evidence
A native alert rule stores its threshold unit as the metric catalog's code -
`NativeAlertMetricCatalogService` returns `"messages"` for
`consumer.lag.total`/`topic.backlog.total`/`dlq.message.count`, `"seconds"` for
`consumer.delay.seconds`, `"ratio"`/`"%"` for the usage ratios - and the rules
table concatenated it raw:
```ts
// web/src/pages/ops/alerts.tsx:135 (before)
return `${rule.operator} ${rule.threshold}${rule.thresholdUnit ?? ''}`;
```
```ts
// web/src/pages/ops/alerts.tsx:219 (the dialog, the only place that
translated it)
const thresholdUnitLabel = (unit?: string | null) => {
if (unit === 'messages') return t('alerts.unitMessages');
if (unit === 'seconds') return t('alerts.unitSeconds');
if (unit === 'ratio') return t('alerts.unitRatio');
return unit;
};
```
so the Cluster/Business Alerts pages showed `> 12000messages` and `>
420seconds` - in both languages, for exactly the rules the dialog renders as `>
12000 条` / `> 420 秒`. The unit keys exist and are translated
(`web/src/i18n/translations.ts:1175-1177`); the table just never called them.
Observed before the fix (`npx vitest run
src/pages/ops/__tests__/AlertsPage.test.tsx`):
```
× translates the catalog unit code in the rules table
AssertionError: expected '> 12000messages' to be '> 12000 条'
```
### Root cause / Fix
The dialog's mapping was a closure inside the component while the table
renderer is a module-level exported function, so the translation never reached
the cell. Extract one exported `thresholdUnitText(unit, t)`, call it from the
dialog (`addonAfter`) and from the table (`formatThresholdCondition`'s new
third argument, defaulting to identity so existing callers behave as before),
and separate a word unit from the number the way the dialog's suffix does - a
percent sign stays attached.
### Priority and scoring
**PRIORITY 55** — impact 18/40 (wrong, untranslated text in a column
operators scan; the value itself is right), blast radius 16/20 (every native
rule with a unit, both languages, both alert pages), reproducibility 18/20
(deterministic, pinned by the new test), maintenance value 8/20 (one leaking
enum).
**FIX_CONFIDENCE 88** — the mapping and its keys already exist; only the
call site was missing.
### Tests
`cd web && npx vitest run src/pages/ops/__tests__/AlertsPage.test.tsx`
| Test | Before | After |
|---|---|---|
| `renders the stored catalog unit code as the label the dialog shows` |
FAIL `'> 12000messages'` | PASS (`> 12000 条`, `> 420 秒`, `> 85%`) |
| `translates the catalog unit code in the rules table` | FAIL | PASS |
`Test Files 1 passed (1), Tests 32 passed (32)`. `npx eslint` on both files
reports no errors; `npx tsc -b` passes.
### Risk
The table cell for a rule with a unit now contains a translated label and,
for word units, a separating space; rules without a unit and legacy ratio rules
without a stored unit render byte-identically (`> 85%` is pinned by an existing
case). The dialog's threshold field is unchanged, because its mapping now
resolves through the same helper.
--
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]