-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Milestone
Description
Code Quality Issue
Several methods in the monitoring system have high cyclomatic complexity and are difficult to maintain, test, and debug.
Complex Methods Identified
1. _collect_detailed_session_metrics - 130+ lines
Location: tools/prometheus_exporter.py:396-565
Issues:
- Single method doing too many things
- Nested loops and complex conditionals
- Difficult to test individual pieces
- High cognitive load for developers
2. Multiple nested database queries
Problem: Business logic embedded in SQL queries
Proposed Refactoring
1. Extract Session Metrics Calculator
Create dedicated class for session calculations with single responsibility.
2. Extract Database Query Builder
Separate SQL queries from business logic for better testability.
3. Simplify Main Collection Method
Break down complex method into focused, testable components.
4. Extract Metric Setting Logic
Create reusable metric setting utilities.
Benefits
- Better testability
- Improved maintainability
- Code reusability
- Reduced complexity
Implementation Plan
- Phase 1: Extract calculator classes (2 hours)
- Phase 2: Simplify main method (1 hour)
- Phase 3: Add tests (1 hour)
Validation Criteria
- Cyclomatic complexity under 10
- Methods under 50 lines
- 90%+ test coverage
- All functionality preserved
Effort: 4 hours
References
- PR feat: Add comprehensive monitoring with Prometheus and Grafana #1
- Clean Code principles