feat(watch): add localized system stats to watch dashboard#160
Conversation
…dd full JSDoc blocks to comply with coding_style.md
|
Warning Review limit reached
More reviews will be available in 26 minutes and 30 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
Warning
|
| Layer / File(s) | Summary |
|---|---|
Docker system stats aggregation src/docker/containers.ts |
DockerSystemStats interface and getDockerSystemStats() export aggregate CPU percentage and memory usage/limit across running containers, with byte formatter and per-container helpers to compute CPU deltas and memory net of cache. |
Kubernetes cluster stats module src/kubernetes/pods.ts |
K8sClusterStats interface and getK8sClusterStats() export with parsing utilities for Kubernetes CPU/memory quantities. Aggregation prioritizes metrics-server node stats, falls back to pod stats, then native pod resource requests, and returns N/A when all sources fail. |
Dashboard UI integration src/ui/WatchDashboard.tsx |
Component adds k8sStats and dockerStats state, imports both fetcher functions, extends polling loop to refresh stats every 3 seconds, and renders CPU/memory values in separate Kubernetes and Docker panels with null fallback. |
Test suite src/__tests__/stats.test.ts |
Comprehensive Vitest suite mocks Docker and Kubernetes APIs and validates quantity parsing, byte formatting across binary and decimal units, Docker stats aggregation, and Kubernetes multi-source fallback behavior. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
🐰 Stats now bloom in kdm's display,
Docker and Kubernetes at play,
CPU, memory—watch them dance,
Three-second heartbeat; metrics prance,
No more jumping out to see the load!
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title clearly summarizes the main change: adding system stats display to the watch dashboard, which is the central objective across all file modifications. |
| Linked Issues check | ✅ Passed | The PR implements all core requirements from issue #117: Docker stats (CPU %, memory), Kubernetes stats (metrics-server with fallback to requests), graceful degradation, and reasonable update intervals (3 seconds). |
| Out of Scope Changes check | ✅ Passed | All changes are directly related to implementing system stats for Docker and Kubernetes sections as specified in issue #117; no unrelated modifications detected. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
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 @coderabbitai help to get the list of available commands and usage tips.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
… hit >95% patch coverage
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
src/docker/containers.ts (1)
125-137: ⚡ Quick winConsider logging errors for debugging visibility.
The catch block silently swallows errors when fetching container stats. While returning zero values is appropriate for graceful degradation, logging the error (at least at debug level) would help diagnose issues when containers fail to report stats.
🔍 Proposed enhancement
} catch { + logger.debug(`Failed to fetch stats for container ${containerId}`); return { cpuPercent: 0, memoryUsage: 0, limit: 0 }; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/docker/containers.ts` around lines 125 - 137, The fetchContainerStats function swallows errors silently; update the catch to capture the error (catch (err)) and log it for visibility before returning zeros—use the module logger if available (e.g., processLogger.debug or logger.debug), otherwise fall back to console.debug/console.error; keep the existing return { cpuPercent: 0, memoryUsage: 0, limit: 0 } for graceful degradation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/docker/containers.ts`:
- Around line 143-180: getDockerSystemStats currently uses the maximum
per-container limit (computed from results of fetchContainerStats) as
memoryLimit which misrepresents aggregate host capacity; change it to always
call docker.info() to obtain MemTotal and use that as memoryLimit (with a safe
fallback like 0) regardless of container limits, remove the maxLimit logic that
picks the largest container limit, and ensure the docker.info() call is awaited
and error-handled before returning the final { cpu, memoryUsage, memoryLimit }
in getDockerSystemStats.
In `@src/kubernetes/pods.ts`:
- Around line 78-97: The function parseK8sCpuQuantity currently treats any
unknown non-empty suffix as cores; update it so only the known suffixes
('n','u','m','' for cores) map to conversions and all other suffixes return 0.
In practice, modify the switch in parseK8sCpuQuantity to keep cases
'n','u','m','' as-is and change the default branch to return 0 (i.e., do not
multiply unknown suffixes by 1000), so malformed inputs like '100x' yield 0
instead of being treated as cores.
- Around line 211-223: The sumPodRequests function incorrectly adds init
container requests to app container requests; change it to only sum requests
from pod.spec?.containers (exclude pod.spec?.initContainers) so
sumPodRequests(pod) uses getContainerRequests only for app containers, leaving
init containers out of the native-fallback estimate (this keeps Running pods
correct and is conservative for Pending pods).
- Around line 104-135: In parseK8sMemoryQuantity, currently unknown suffixes
fall through to being treated as raw bytes; change the logic to return 0 when a
non-empty, unrecognized suffix is present. Specifically, inside function
parseK8sMemoryQuantity after extracting suffix, allow empty suffixes to be
treated as bytes (return val), handle known binaryPower (Ki/Mi/...) and
decimalPower (k/M/...) as before, and if suffix is non-empty and not found in
either map return 0; update references to suffix and the
binaryPower/decimalPower checks accordingly.
---
Nitpick comments:
In `@src/docker/containers.ts`:
- Around line 125-137: The fetchContainerStats function swallows errors
silently; update the catch to capture the error (catch (err)) and log it for
visibility before returning zeros—use the module logger if available (e.g.,
processLogger.debug or logger.debug), otherwise fall back to
console.debug/console.error; keep the existing return { cpuPercent: 0,
memoryUsage: 0, limit: 0 } for graceful degradation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 61b8acc2-08e3-42ec-bf00-1fa5ee0f2289
📒 Files selected for processing (4)
src/__tests__/stats.test.tssrc/docker/containers.tssrc/kubernetes/pods.tssrc/ui/WatchDashboard.tsx
…ed suffix fallbacks, and exclude initContainers
…t.each to satisfy CodeScene quality gates
… prevent silent render suppression in CI
82545b1 to
6e9cccd
Compare
There was a problem hiding this comment.
Code Health Improved
(1 files improve in Code Health)
Our agent can fix these. Install it.
Gates Passed
3 Quality Gates Passed
View Improvements
| File | Code Health Impact | Categories Improved |
|---|---|---|
| WatchDashboard.tsx | 9.55 → 10.00 | Complex Method |
Quality Gate Profile: The Bare Minimum
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.
Closes #117
Description
This PR introduces system resource stats (CPU and Memory) directly into the
kdm watchdashboard:Summary by CodeRabbit
New Features
Tests