fix: trigger metrics fetch on initial observability page load#553
Conversation
The metrics page used a ref-tracked JSON.stringify diff to decide whether filter values had changed before firing fetchMetrics. The ref was initialized to the live filter values at first render, so when the page mounted with env already resolved (URL has env, or environments resolve synchronously from cache) the first effect run compared current to itself, marked it unchanged, and skipped the fetch. The user then saw "no metrics data" until refreshing or changing a filter. useMetrics already guards its fetch on env + timeRange, so the manual diff was duplicating that guard. Drop the ref and let the effect's dep array do the work: fire when env, timeRange, canViewMetricsForEnv, or fetchMetrics identity changes, and rely on the hook's internal guard for the no-op case. HTTPMetricsSection keeps its own ref-pattern fetch; it's separately gated by useCiliumEnabled() and unaffected by this change. Signed-off-by: Rashad Sirajudeen <rashad@wso2.com>
📝 WalkthroughWalkthrough
ChangesMetrics Fetch Effect Refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
Metrics page sometimes loads empty until the user clicks Refresh or changes a filter. The
useEffectused apreviousFiltersRefinitialized from live first-render filter values, so when the page mounted withenvalready resolved (URL carries?env=..., or environments resolve from cache) the first diff was a no-op and the fetch was skipped.useMetricsalready guards on env + timeRange internally, so the manual diff was redundant. Drop the ref; let the effect's dep array (env,timeRange,canViewMetricsForEnv,fetchMetrics) trigger the fetch.Side effect: changing the custom date range now refetches automatically instead of needing Refresh.
HTTPMetricsSectionis untouched — separate component, separate ref, cilium gate intact.Test plan
?env=...in the URL.env(auto-select path).