feat: inline metrics with sparkline display - #45
Conversation
Add M key toggle to show CloudWatch metrics as sparklines in resource list. - metrics package: CloudWatch GetMetricData batch fetcher, sparkline renderer - MetricSpecProvider interface for resource-specific metric config - EC2 instances: CPUUtilization with 15m window - Ctrl+r reloads metrics when enabled
This comment was marked as resolved.
This comment was marked as resolved.
- P0: use effectiveMetricsEnabled to check spec before rendering - P1: load metrics after resources in resourcesLoadedMsg handler - P1: reset metricsEnabled/metricsData on resourceType switch - P1: add M:metrics hint to StatusLine with loading/on state - P1: consolidate ColumnWidth constant in metrics package - P3: show metricsLoading state in StatusLine
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
- Add explicit nil check for metricsData in buildTable - Add unit tests for sparkline and MetricData - Add package documentation for metrics - Add context cancellation check in batch loop
This comment was marked as resolved.
This comment was marked as resolved.
- Mark cloudwatch as direct dependency via go mod tidy - Add unit tests for cloudwatch.go (buildQueries, batch splitting, processResults)
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
- Add Unit field to MetricSpec for proper unit display (% for CPU, empty for counts) - Update RenderSparkline to accept unit parameter - Improve error logging with service/resource context - Add test for empty unit (Lambda invocations) Resource ID mapping verified safe: same slice passed to buildQueries/processResults
|
Thanks for the thorough review! Addressed in 37f7c25Critical Issues ✅
Should Fix ✅
Nice to Have (Deferred)
|
This comment was marked as resolved.
This comment was marked as resolved.
|
Fixed the race condition (1224038). Other items from review:
|
This comment was marked as resolved.
This comment was marked as resolved.
|
Addressed review suggestions (a787583):
Ready for merge. |
This comment was marked as resolved.
This comment was marked as resolved.
|
Fixed stale metrics race condition (28fb33f). Re: nil cmd in tea.Batch - Re: CloudWatch retry - can add in follow-up if throttling becomes an issue. Ready for merge. |
This comment was marked as resolved.
This comment was marked as resolved.
|
Addressed context cancellation check from review (2343503).
|
Pull Request Review: Inline CloudWatch Metrics with Sparkline DisplaySummaryThis PR adds inline CloudWatch metrics visualization with sparklines to the resource browser for EC2, RDS, and Lambda resources. The implementation is well-structured with good test coverage and thoughtful design choices. ✅ Strengths1. Code Quality & Architecture
2. Performance Considerations
3. Test Coverage
4. Documentation
🔍 Issues & RecommendationsHigh Priority1. Potential Memory Issue in Batch Processing The // Current: builds ALL queries upfront
queries := f.buildQueries(resourceIDs, spec) // Could be 10,000+ queries
// Recommendation: Build queries per batch to reduce memory footprint
for i := 0; i < len(resourceIDs); i += maxQueriesPerRequest {
end := min(i+maxQueriesPerRequest, len(resourceIDs))
batch := f.buildQueries(resourceIDs[i:end], spec)
// ... process batch
}2. Query ID Collision Risk Using simple index-based IDs ( Id: aws.String(fmt.Sprintf("m%d", i)) // Resets to m0 for each batchFix: Include batch offset in ID generation: Id: aws.String(fmt.Sprintf("m%d", batchOffset+i))Medium Priority3. Sparkline Rendering: Padding Logic The left-padding with 4. Missing Validation in buildQueries No validation that func (f *Fetcher) buildQueries(resourceIDs []string, spec *render.MetricSpec) ([]types.MetricDataQuery, error) {
if spec.Namespace == "" || spec.MetricName == "" {
return nil, fmt.Errorf("invalid metric spec: namespace and metric name required")
}
// ...
}5. Error Handling in Auto-Reload When auto-reload triggers metric refresh, errors are logged but not surfaced to the user. Consider showing a subtle indicator when metrics fail to load, especially for permission issues. Low Priority6. go.mod Organization The PR moves 7. Test: processResults Edge Case The test 8. Column Width Calculation The extra width distribution logic doesn't account for the metrics column when enabled. The last regular column gets 🔒 SecurityNo significant security concerns identified.
📊 Performance AnalysisAPI Call Efficiency:
Potential Concern: Large accounts with thousands of instances could see:
Recommendation: Consider adding a warning or limit when resource count > 1000. 🧪 Test Coverage AssessmentCoverage: Excellent (~94% estimated for new code) Covered:
Missing:
📝 Suggestions for Follow-up
✨ Overall AssessmentStatus: Approve with Minor Changes Recommended This is a well-implemented feature that adds significant value to the tool. The code quality is high, test coverage is comprehensive, and the implementation shows careful consideration of performance and UX. The issues identified are mostly minor improvements rather than blockers. Recommended Actions Before Merge:
Nice to Have:
Great work! This feature will significantly enhance the resource browsing experience. 🎉 |
Closes #32
Summary
Inline CloudWatch metrics with sparkline visualization in resource browser.
Supported Resources
Features
▁▂▃▄▅▆▇█(15m window, 1m resolution)Implementation
internal/metrics/package (cloudwatch.go, sparkline.go, types.go)MetricSpecProviderinterface for extensible resource metricsFollow-up
ECS/ELB support tracked in #47 (requires multi-dimension support)