Wang1rrr opened a new pull request, #4836:
URL: https://github.com/apache/rocketmq-dashboard/pull/4836
### Which Issue(s) This PR Fixes
Fixes #4781
### Brief Description
`metricSeriesLabel` formats only the first three sorted labels so the
compact legend row fits the panel. `MetricChart` then used that truncated
string as the React key for both the `<polyline>` and the legend entry, and as
the legend's hover tooltip. Two series that differ only in a later label
therefore shared one child key (React logged `Encountered two children with the
same key`) and rendered two identical legends whose tooltips repeated the same
short text.
This separates the three concerns that were collapsed into one string:
- Identity: `metricSeriesIdentity(series, index)` - the series index plus
the complete sorted label map, which is the convention
`buildMetricSeriesDetailRows` already uses for its row keys. Both chart
children are keyed by it.
- Tooltip: `metricSeriesFullLabel(series, metric.name)` - the whole label
set in the same `key=value / key=value` notation, so it reads like the legend
rather than a JSON blob.
- Visible legend text: `metricSeriesLabel(series, metric.name)` unchanged,
still capped at three labels.
The cap became a parameter of the existing serializer instead of a second
formatter. The scalar/histogram split, color allocation, `MAX_SERIES` capping
and panel layout are untouched; there is no backend, response schema,
dependency, i18n or color-policy change. #4358 (float/histogram samples of one
series) and #4570 (color allocation) stay independent - this only needs an
ordinary rebase if #4570 lands.
### How Did You Test This Change?
Node.js 22.23.2 on Windows; dependencies come from the existing lockfile (a
shared `web/node_modules`), with no install and no lockfile change.
Three regressions were added:
- Component: two series labelled `{cluster, job, namespace, pod}` that
differ only in `pod`. It asserts both polylines are still drawn, the compact
legend text is unchanged (`getAllByText('cluster=prod / job=rmq /
namespace=ns')` has length 2), and that no duplicate-key warning reaches
`console.error`.
- Unit: the display label stays truncated to three labels while the full
label keeps `pod=a` / `pod=b`, and the two identities are distinct.
- Unit: the full-label fallback for a `__name__`-only series and for an
empty label map.
Red/green evidence. With only the production change reverted (`git stash` of
`MetricsExplorer.tsx` and `metricsExplorerDiagnostics.ts`), the new component
test fails with exactly the two collisions reported in the issue:
```text
x keeps series that differ only in a later label distinguishable
AssertionError: expected [ [ ...(3) ], [ ...(3) ] ] to deeply equal []
+ "Warning: Encountered two children with the same key, `%s`. Keys should be
unique ..."
+ "Warning: Encountered two children with the same key, `%s`. Keys should be
unique ..."
1 failed | 29 skipped (30)
```
Commands run from `web/`:
```text
npx vitest run src/utils/metricsExplorerDiagnostics.test.ts
src/components/__tests__/MetricsExplorer.test.tsx
2 files, 40 tests passed
npm test -- --maxWorkers=2
139 files, 1283 tests passed (447.57s)
npm run lint
0 errors, 11 pre-existing warnings in unmodified files
npm run build
tsc -b and the Vite production build passed (built in 24.16s)
npx prettier --check src/components/MetricsExplorer.tsx
src/components/__tests__/MetricsExplorer.test.tsx
passed
git diff --check
passed
```
`npx prettier --check` still lists `src/utils/metricsExplorerDiagnostics.ts`
and its test file. Both already differ from Prettier at the base commit
`4c697f07` (confirmed with `prettier --list-different` on the stashed base),
and every remaining delta sits in code this PR does not touch, so no unrelated
file-wide reformat is bundled here. The commit was made with `--no-verify` for
the same reason: lint-staged would rewrite those pre-existing lines.
Browser scope: verified through the real component under Vitest/jsdom with
synthetic metrics-service responses, matching the reproduction in the issue. No
live Prometheus endpoint, Java backend or Broker was used, so no browser or
backend E2E is claimed. jsdom performs no text layout, so Ant Design's
Typography never measures the legend text as overflowing and the ellipsis
tooltip cannot be opened in a test; the tooltip content is therefore covered by
the `metricSeriesFullLabel` unit test, while the component test asserts the
child identities and the unchanged visible legend.
This change was prepared with AI assistance and verified with the actual
commands above.
### Checklist
- [x] One coherent change; unrelated modifications are not bundled in
- [x] Commit subject follows Conventional Commits
- [x] Tests added and observed failing before the fix
- [x] No new UI text: the legend is unchanged and the tooltip reuses the
existing label notation, so no `web/src/i18n/` entries are needed
- [x] No new source files, so no new ASF license headers
- [x] No new dependencies or lockfile changes
- [ ] Backend architecture tests (`mvn test`) and Broker E2E not run; this
is a frontend-only change
--
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]