btlqql opened a new pull request, #7145:
URL: https://github.com/apache/rocketmq-dashboard/pull/7145
### Which Issue(s) This PR Fixes
- Fixes #5982
## What is the purpose of the change
The metrics explorer persisted its query history under one global
localStorage key
(`rocketmq-studio-metrics-query-history`), loaded once when the panel
mounted and cleared only by
the explicit button. Logout clears the auth store's own keys only, so the
next account on a shared
browser opened the drawer on the previous account's history — PromQL text,
profile and metric
names, instance ids, data-source keys and the queried windows — and could
re-run it.
`/ops/dashboard` has no admin gate, so every signed-in account reaches the
panel.
The history is now keyed by account, following the sibling per-account stores
(`web/src/utils/messageTraceTopicStorage.ts`).
`metricsQueryHistoryStorageKey(owner)` builds
`…:user-id:<id>` from the session's numeric id, falls back to
`…:username:<name>` when there is no
id, and returns the legacy global key only when no account is signed in at
all (a test, or the
first paint before the session is restored), so an unauthenticated panel
never invents a bucket
that every browser shares. `loadMetricsQueryHistory`,
`saveMetricsQueryHistory` and
`clearMetricsQueryHistory` take that owner, and the panel passes the one it
reads from the auth
store, memoized so the two query callbacks keep a stable dependency.
History already sitting under the old global key is deliberately not
migrated: its owner is
unknown, and migrating it would hand it to whoever signs in next — the
defect itself. A signed-in
account therefore starts empty once and keeps its own history from then on.
## Brief changelog
- `web/src/utils/metricsExplorerDiagnostics.ts`: add
`MetricsQueryHistoryOwner`,
`metricsQueryHistoryOwnerKey` and the exported
`metricsQueryHistoryStorageKey`; make
load/save/clear read and write the per-account key.
- `web/src/components/MetricsExplorer.tsx`: read `user`/`userId` from the
auth store, memoize the
history owner and pass it to the initial load, both history writes and the
clear action.
- `web/src/utils/metricsExplorerDiagnostics.test.ts`: regression test for
two accounts on the same
browser, plus the existing persistence cases moved onto an explicit
account.
## Verifying this change
- red: `cd web && npx vitest run
src/utils/metricsExplorerDiagnostics.test.ts` (regression test only,
on unmodified trunk) →
`AssertionError: expected [ { …(17) } ] to deeply equal []` at
`metricsExplorerDiagnostics.test.ts:506:45`, summary `Tests 1 failed | 24
passed (25)`
(log: `5982-history-red.log`)
- green: `cd web && npx vitest run
src/utils/metricsExplorerDiagnostics.test.ts
src/components/__tests__/MetricsExplorer.test.tsx`
→ `Test Files 2 passed (2)`, `Tests 80 passed (80)` (log:
`5982-history-green.log`)
- focused green: `npx vitest run
src/utils/metricsExplorerDiagnostics.test.ts -t 'does not hand'`
→ `Tests 1 passed | 24 skipped (25)`
- regressions run: `npx tsc -b` → exit 0 (log: `5982-tsc.log`)
Not run: the full `web` suite, `npm run lint`, CI, and no browser-level
sign-out/sign-in against a
running backend — the isolation is asserted at the storage layer and through
the panel's existing
component suite.
## Checklist
- [x] one issue, one PR: Fixes #5982
- [x] regression test added, red on trunk and green after the change
- [x] targeted suites re-run (util suite, `MetricsExplorer.test.tsx`, `tsc
-b`)
- [x] one coherent change, three files, no unrelated edits
- [ ] full `npm test` — not run (out of scope for this campaign)
--
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]