You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "unbridled-41 (via GitHub)" <gi...@apache.org> on 2026/09/09 06:10:45 UTC

[PR] fix(metrics): keep the selected range when the instance changes [rocketmq-dashboard]

unbridled-41 opened a new pull request, #4189:
URL: https://github.com/apache/rocketmq-dashboard/pull/4189

   {"body": "Fixes #4188.\n\n## Problem / Evidence\n\nOn the home dashboard, the Metrics Explorer below the cluster cards stays mounted while the \u5b9e\u4f8b selector changes (`dashboard.tsx:318` \u2014 `<MetricsExplorer instanceId={selectedInstanceId} />`, no remount key). The profile-loading effect re-runs on an instance change (its `loadAll` dependency closes over `runQuery`, which depends on `instanceId`) and reloads every panel \u2014 but it hardcoded `RANGE_OPTIONS[0]` (1h):\n\n- `MetricsExplorer.tsx` (before this fix, line 539): `void loadAll(initialProfile, RANGE_OPTIONS[0]);` \u2014 inside the effect that also runs on every instance change, not only on mount.\n- `rangeId` state (line 415) and the Segmented control (line ~762) keep showing the user's selection.\n\nRed test evidence (unfixed code, mocked `queryMetrics`, `Date.now` pinned):\n\n```\n\u00d7 reuses the selected range when the instance prop changes\nExpected (6h window): start 1799978400, step '2m'\nReceived (1h d
 efault): start 179996400, step '30s'   \u2190 reload after instance-1 \u2192 instance-2\n```\n\nSo right after an instance switch, a user who selected 6h sees one hour of data under a control labeled 6h.\n\n## Root cause / Fix\n\nThe effect reused the initial-default `RANGE_OPTIONS[0]` on the reload path, where a user selection already exists. Fix: keep the latest selected range in a ref (`rangeIdRef`, kept in sync like the adjacent `dataSourceKeyRef`) and resolve the reload's range from it; the 1h default still applies on the very first mount before any selection. No request-guard behavior changes (the sibling guards from PR #3299 are untouched).\n\n## Priority & scoring\n\nPRIORITY = 73 (\u5f71\u54cd 30: displayed range label and actual data window disagree after every instance switch on the home dashboard for non-default ranges; \u6ce2\u53ca\u8303\u56f4 13: the home dashboard explorer, all users switching instances; \u53ef\u590d\u73b0\u6027 20: deterministic, captured in a compon
 ent test; \u7ef4\u62a4\u4ef7\u503c 10: one-line semantic correction plus ref, follows the established ref pattern in the same file). FIX_CONFIDENCE = 88 (deterministic red\u2192green test; same-file ref precedent; risk limited to the reload path).\n\n## Tests\n\nRed (before the fix, same test, `rocketmq-studio` @ 0a596661):\n\n```\nnpx vitest run src/components/__tests__/MetricsExplorer.test.tsx -t \"reuses the selected range\"\n \u00d7 reuses the selected range when the instance prop changes 724ms\n   Expected: start 1799978400, step '2m'  (6h window)\n   Received: start 179996400, step '30s'  (1h default)\n```\n\nGreen (after the fix): `npx vitest run src/components/__tests__/MetricsExplorer.test.tsx` \u2192 **21/21 passed**. The new regression test `reuses the selected range when the instance prop changes` waits for the reload call to actually land (`toHaveBeenCalledTimes(3)`) before asserting the window, so it is deterministic (4 consecutive full-file runs + 1 shuffled run, all 
 21/21).\n\nFull web suite (`npx vitest run`): 945 tests, 944 passed, 1 failed \u2014 `ConsumerPage > shows group health diagnostics from subscriptions, progress and clients` (untouched file; isolated run with this change applied passes 31/31; the same file is the recurring load-flaky file in this sandbox, consistent with previous rounds).\n\n`tsc --noEmit` clean; `eslint` on both changed files 0 errors/0 warnings; `npm run build` \u2713 (9.08s).\n\n## Risk\n\nLow. The change only affects which range the reload uses; the initial mount path is unchanged (ref holds '1h' before any selection). The ref-sync effect follows the exact pattern of the adjacent `dataSourceKeyRef`.\n"}


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(metrics): keep the selected range when the instance changes [rocketmq-dashboard]

Posted by "unbridled-41 (via GitHub)" <gi...@apache.org>.
unbridled-41 commented on PR #4189:
URL: https://github.com/apache/rocketmq-dashboard/pull/4189#issuecomment-5602223452

   ## Merge & re-validation (base advanced to 0c54d985)
   
   The base branch advanced by 5 commits after this PR was opened — most notably #2677 (`d7cbf3ed`), which rewrote `web/src/components/MetricsExplorer.tsx` (+835/-137) and its test file (+291). GitHub therefore reported this branch as conflicting.
   
   Resolved by merging `origin/rocketmq-studio` into this branch as a merge commit (`f4484121`); no history rewrite, the original fix commit `29873660` is unchanged:
   
   - **Conflict**: exactly one hunk — the refs declaration block, where this PR's `rangeIdRef` declaration + sync effect collided with two refs newly added by upstream (`dataSourceNamesRef`, `pendingAuthReplayRef`). Resolution keeps both blocks; no logic was reworked.
   - **Fix survived the rewrite**: the profiles-effect change auto-merged cleanly, and the defect this PR fixes is still present in the new base (`loadAll(initialProfile, RANGE_OPTIONS[0])`), so the fix remains necessary. The regression test `reuses the selected range when the instance prop changes` passes on the merged result.
   
   Re-validation on the merged tree (base `0c54d985` + fix + merge):
   
   - `npx vitest run src/components/__tests__/MetricsExplorer.test.tsx` → **26/26 passed**, 3 consecutive isolated runs (26 upstream tests incl. the new history/CSV/auth-replay suites + the regression test from this PR).
   - Full web suite `npx vitest run` → 981 tests, 979 passed, 2 failed — `MetricsExplorer > requires credentials again when restoring a protected data source history item` and `ConsumerPage > shows group health diagnostics...`, both pass in isolation (26/26 and 31/31) and are load-flaky under full-suite parallelism (the same file has been the recurring flaky file in this sandbox; the MetricsExplorer case is upstream's own test, failing the same way on upstream code under load).
   - `npx tsc --noEmit` clean; `npx eslint` on both files 0 errors/0 warnings; `npm run build` succeeded (11.09s).
   - CI: as before, the upstream `CI (pull_request)` workflow ends in `startup_failure` for all branches (0 check-runs), so all suites were run locally.
   


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(metrics): keep the selected range when the instance changes [rocketmq-dashboard]

Posted by "unbridled-41 (via GitHub)" <gi...@apache.org>.
unbridled-41 commented on PR #4189:
URL: https://github.com/apache/rocketmq-dashboard/pull/4189#issuecomment-5596766014

   ## Verification evidence
   
   - **CI**: head SHA `298736606a4725ba33bc7270b6bf53264fcc527a` has exactly one workflow run — `CI (pull_request)`, conclusion `startup_failure`, 0 check-runs (upstream workflow fails before launching jobs; all `rocketmq-studio` branches show the same). Suites were therefore run locally.
   - **Red-light actual output** (before the fix, same test, `rocketmq-studio` @ 0a596661):
   
   ```
   × reuses the selected range when the instance prop changes 724ms
   Expected: start 1799978400, step '2m'  (6h window)
   Received: start 179996400, step '30s'  (1h default, the reload after instance-1 → instance-2)
   ```
   
   - **Module tests**: `npx vitest run src/components/__tests__/MetricsExplorer.test.tsx` → 21/21 passed after the fix. Determinism check: 4 consecutive full-file runs + 1 `--sequence.shuffle` run, all 21/21 (an earlier draft of this test asserted `toHaveBeenLastCalledWith` immediately after rerender without first waiting for the third call, which made it racy; the committed test waits for `toHaveBeenCalledTimes(3)` first — that racy draft was discarded, never committed).
   - **Full suite + baseline**: `npx vitest run` → 945 tests, 944 passed, 1 failed (`ConsumerPage > shows group health diagnostics from subscriptions, progress and clients`, untouched file). Isolated run of that file/test with this change applied: passed (load flakiness; the recurring flaky file in this sandbox across previous rounds).
   - **Build**: `npx tsc --noEmit` clean; `npx eslint` on both changed files 0 errors/0 warnings; `npm run build` succeeded (9.08s).
   - **Diff self-check** (`git show --numstat 29873660`): `web/src/components/MetricsExplorer.tsx` +12/−1, `web/src/components/__tests__/MetricsExplorer.test.tsx` +28/−0; total 2 files, +40/−1. No unrelated changes.
   


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(metrics): keep the selected range when the instance changes [rocketmq-dashboard]

Posted by "unbridled-41 (via GitHub)" <gi...@apache.org>.
unbridled-41 commented on PR #4189:
URL: https://github.com/apache/rocketmq-dashboard/pull/4189#issuecomment-5642629109

   ## Evidence-chain completion (head SHA + net diff self-check)
   
   The two earlier comments pin CI to the fix commit `29873660` and its per-commit numstat. This comment pins the same two items to the PR's **current head** (the base-advancing merge commit `f4484121`, resolved 2026-09-09 and described in the second comment above); the red→green, module, full-suite and build results there remain valid.
   
   **CI (current head)**: head SHA `f44841214adcfe2a3a7b61f938fa2e60cec4f673` has exactly one workflow run — "CI" (pull_request), run id 34354226069, conclusion `startup_failure` (created 2026-09-09T12:58:56Z); the check-runs API for the head commit returns `total_count=0`. The upstream workflow fails at startup for every branch, so no CI signal is available; all suites were run locally (re-validated on the merged tree: MetricsExplorer 26/26 ×3, tsc/eslint/build clean — see the merge comment).
   
   **Net diff self-check** (files API for this PR, cumulative vs `rocketmq-studio` @ `6c24d2ed`, 2 files, +40/−1 — identical to the fix commit's own numstat because the merge commit only resolves the declaration-hunk conflict and carries no additional edits):
   
   ```
   web/src/components/MetricsExplorer.tsx            +12/−1
   web/src/components/__tests__/MetricsExplorer.test.tsx  +28/−0
   ```
   
   No unrelated changes.
   


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(metrics): keep the selected range when the instance changes [rocketmq-dashboard]

Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins closed pull request #4189: fix(metrics): keep the selected range when the instance changes
URL: https://github.com/apache/rocketmq-dashboard/pull/4189


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(metrics): keep the selected range when the instance changes [rocketmq-dashboard]

Posted by "RockteMQ-AI (via GitHub)" <gi...@apache.org>.
RockteMQ-AI commented on PR #4189:
URL: https://github.com/apache/rocketmq-dashboard/pull/4189#issuecomment-5601978097

   ⚠️ **Merge conflict detected**
   
   This PR has conflicts with the `main` branch and cannot be merged. Please rebase or merge `main` into your branch and resolve the conflicts:
   
   ```bash
   git fetch origin
   git checkout fix/metrics-explorer-instance-range-sync
   git rebase origin/main
   # resolve conflicts, then:
   git push --force-with-lease
   ```
   
   This is a one-time reminder. Feel free to @mention me for a re-review after conflicts are resolved.
   
   ---
   *Automated notification by github-manager-bot*


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(metrics): keep the selected range when the instance changes [rocketmq-dashboard]

Posted by "RockteMQ-AI (via GitHub)" <gi...@apache.org>.
RockteMQ-AI commented on PR #4189:
URL: https://github.com/apache/rocketmq-dashboard/pull/4189#issuecomment-5597639650

   Verification complete. My applied diff matched the PR exactly; the tree is restored to clean state. Here's my review:
   
   ---
   
   ## Code Review: PR #4189 — fix(metrics): keep the selected range when the instance changes
   
   ### 1. Summary
   
   This PR fixes the Metrics Explorer on the home dashboard so that switching the 实例 (instance) selector reloads panels with the user's currently selected time range instead of silently resetting to the 1h default while the Segmented control still shows the picked range. The fix adds a `rangeIdRef` (synced via effect) and resolves the reload range from it, plus a regression test.
   
   ### 2. Verification Performed
   
   I independently reproduced the bug and verified the fix (applied the diff to a clean checkout at `3612602`):
   
   - **Premise confirmed**: `dashboard.tsx:318` renders `<MetricsExplorer instanceId={selectedInstanceId} />` with no remount key, and the re-run chain holds: `runQuery` depends on `instanceId` (`MetricsExplorer.tsx:480`) → `loadAll` depends on `runQuery` (line 515) → the profiles effect depends on `loadAll` (line 540), so it re-fires on every instance switch.
   - **Red state confirmed**: with only the test applied, the new test fails exactly as described (`start 179996400, step '30s'` — the 1h default).
   - **Green state confirmed**: 20/20 pass, stable across 3 consecutive full-file runs.
   - `tsc --noEmit` clean; `eslint` on both files 0 errors/warnings.
   - Full web suite: only the pre-existing `ConsumerPage.test.tsx` flake fails (passes 29/29 in isolation with this change applied) — untouched file, consistent with the PR's disclosure.
   
   ### 3. Issues Found
   
   - **[SUGGESTION]** Custom query panel is not refreshed on instance switch. The reload path (`MetricsExplorer.tsx:531-541`) calls `loadAll` but not `runCustomQuery`, so a previously applied custom PromQL result keeps showing the *old* instance's data until manually re-run — the same class of staleness this PR fixes for panels. Pre-existing behavior, out of scope here, but a natural follow-up (note the refresh button at line 776-779 does re-run it).
   
   - **[SUGGESTION]** PR description says the file suite is "21/21 passed"; the file at this base contains 20 tests (including the new one). Likewise full-suite counts differ slightly (945 claimed vs 923 here) — likely a different sandbox base. Cosmetic discrepancy only; the failure pattern (single unrelated ConsumerPage flake) matches.
   
   - **[SUGGESTION]** The `?? RANGE_OPTIONS[0]` fallback in the new lookup is technically unreachable (`rangeIdRef` is typed to `RANGE_OPTIONS` values), but it's harmless defensive parity with `handleRangeChange` (line 551) and `selectedRange` (line 436). No change needed.
   
   No critical or warning-level issues found. Specifically checked:
   
   - **Mount path unchanged**: `rangeId` initializes to `'1h'`, so `rangeIdRef` starts at `'1h'` and the first load still uses `RANGE_OPTIONS[0]` semantics.
   - **No race**: the reload reads `rangeIdRef.current` inside the `.then()` of `listMetricProfiles()`, i.e., after React has committed and the sync effect has run — the ref is always current at read time.
   - **Ref design is right**: adding `rangeId` to the effect deps would re-trigger profile fetching on every range change (duplicate requests); the ref avoids that. The dedicated sync effect is arguably more robust than the imperative sync used for `dataSourceKeyRef`.
   - **Test determinism**: waiting for `toHaveBeenCalledTimes(3)` before asserting avoids asserting before the reload lands; `localStorage` is cleared per-test in `src/test/setup.ts`; no cross-test leakage.
   - **Security**: no API, auth, or query-surface changes — only the `start`/`step` values of existing `queryMetrics`/`queryByDataSource` calls change.
   
   ### 4. Overall Assessment
   
   **APPROVE**
   
   Minimal, correct fix with a verified red→green regression test. The behavior now matches the refresh-all button (line 776), which already uses the selected range. The only notes are a pre-existing adjacent gap (custom panel staleness on instance switch) worth a follow-up issue, and trivial PR-description count discrepancies.
   


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(metrics): keep the selected range when the instance changes [rocketmq-dashboard]

Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins commented on PR #4189:
URL: https://github.com/apache/rocketmq-dashboard/pull/4189#issuecomment-5694552711

   Merged as part of #4331 — squashed into `rocketmq-studio` as `6334f9238`.
   
   Your change here (keeping the selected range when the metrics instance changes) is included.
   
   We grouped 11 of your related front-end fixes into a single commit so the history stays reviewable; the other PRs in the group are closed with the same note. Everything was cherry-picked onto the current baseline with you kept as the author, and your tests came along with the change.
   
   Thanks for the consistently well-tested patches.


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org