Repository navigation
fix(metrics): re-run the custom query when the dashboard instance changes - #4265
unbridled-41 wants to merge 1 commit into
Conversation
…nges The dashboard keeps one MetricsExplorer mounted and only swaps the instanceId prop. The reload effect re-runs the profile panels through loadAll, but nothing re-ran the custom query panel, so after switching instances it kept rendering the previous instance's PromQL result (or error) under the new instance until the user manually pressed refresh. When the selected data source drops out of the new instance's scope the existing fallback effect already re-runs both flows, so the new guarded effect skips that case instead of duplicating its request. Regression test: run a custom query against one instance, rerender with another instanceId, and assert the custom expression is queried again.
Verification evidence
|
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
Code changes look reasonable, but CLA has not been signed. Please sign the CLA before this PR can be merged.
Findings
No issues found. ✓
Automated review by RockteMQ-AI
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
Re-run the custom metrics query when the dashboard instance changes — clean, focused fix with proper transition guards and test coverage.
The lastInstanceIdRef pattern correctly detects instance transitions, and the scope guard (availableDataSources.some(...)) avoids duplicate requests when the fallback effect already handles the data source change. Test verifies the full re-render + re-query flow.
LGTM. ✓
Automated review by github-manager-bot
#4331) Incorporates ten related front-end fixes from the same author: - #4175 render the rule last-triggered time as UTC - #4189 keep the selected range when the metrics instance changes - #4245 reload the paginated group list after creating groups - #4249 edit topic configuration from the topic page - #4254 reset the silence form when the maintenance dialog is dismissed - #4263 export users against the committed search term - #4265 re-run the custom query when the dashboard instance changes - #4283 reset the queue browser pull indicators when the queue list reloads - #4285 surface the validation reason when a silence cannot be built - #4322 invalidate the in-flight connection query when the topic changes
|
Merged as part of #4331 — squashed into Your change here (re-running the custom query when the dashboard 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. |
Fixes #4264.
Problem / Evidence
The home dashboard mounts one
MetricsExplorerand only swaps theinstanceIdprop on an instance change (web/src/pages/home/dashboard.tsx:408, nokey). The reload effect (MetricsExplorer.tsx:648-671, keyed onloadAll, which changes identity withinstanceId) re-runs only the profile panels vialoadAll. Nothing re-runs or clears the custom query panel:runCustomQueryfires solely fromactivateDataSource, the data-source-scope fallback effect, the refresh button and direct user actions - none of which trigger for an instance change with the default source. The effect cleanup only invalidates in-flight requests (customRequestIdRef); thecustomPanelstate survives.Regression test red on 6c24d2e: run a custom query against
instance-11, rerender withinstance-22- the custom expression is never queried again (queryMetricscalls for it stay at 1), so the panel keeps rendering the previous instance's chart (or error) under the new instance until the user presses refresh.Root cause / Fix
Add a ref-guarded effect that re-runs the committed custom query (
appliedCustomPromql) with the currently selected range wheninstanceIdtransitions. It deliberately skips the case where the selected data source drops out of the new instance's scope: the existing fallback effect (lines 822-845) already re-runs bothloadAlland the custom query there, and skipping avoids duplicating its request. This mirrors the same-file pattern that fallback effect and the merged #3299 guards establish.Priority & scoring
PRIORITY 72 = 影响 28(监控面板在实例选择器已切换后仍展示旧实例的自定义查询结果,误导读数,需手动刷新恢复)+ 波及 12(仪表盘自定义查询面板一个面)+ 可复现 18(默认数据源下实例切换 100% 残留)+ 维护价值 14(#3299/#4189 同族治理,文件内已有同款重跑先例)。FIX_CONFIDENCE 85:修复镜像文件内 fallback effect 的既有语义,ref 守卫避免重复请求;与 #4189 的改动行不重叠。
Tests
MetricsExplorer > re-runs the committed custom query when the dashboard instance changes: red on unfixed code (Tests 1 failed | 25 passed) - custom expression queried exactly once after the instance switch; green after the fix (26 passed), the second call for the custom expression is asserted.MetricsExplorer.test.tsx26/26 passed (re-run after lint-staged reformat), including the pre-existing instance-switch fallback tests that pin the scope-drop path.npx vitest run): 982 tests, 980 passed, 2 failures - both are pre-existing load-fragile cases, not touched by this change's behavior (MetricsExplorer > restores profile, range, and source from query history, an existing test that passes isolated in the 26/26 module run;ConsumerPage > shows group health diagnostics..., isolated 31/31). A pristinenpx vitest runin a clean worktree at 6c24d2e measures 981 tests / 3 failures (NotificationDeliveriesPage x1, MetricsExplorer x1, ConsumerPage x1 - the same fragile family; the per-run fragile set varies), so this branch's 982 = 981 pristine + 1 new regression, and my new test passes in the full run.npx tsc -bclean,npx eslintclean on both touched files,npm run buildsucceeds (✓ built in 10.74s).Risk
Low: the effect only fires on an actual
instanceIdtransition (ref-guarded) and only when a custom query is committed. Two interactions are handled explicitly: the scope-drop path stays single-request (guard skips it), and on mount the ref equals the initial instance so no spurious run. If #4189 (range retention on instance switch) merges, the two compose - the custom query then re-runs with the retained range instead of the selected one; at this branch's base both use the selected range.