mirror of
https://github.com/ptarmiganlabs/butler-sos.git
synced 2025-12-19 17:58:18 -05:00
3.0 KiB
3.0 KiB
InfluxDB Module - Refactored Architecture
This directory contains the refactored InfluxDB integration code, organized by version for better maintainability and testability.
Structure
influxdb/
├── shared/ # Shared utilities and helpers
│ └── utils.js # Common functions (getFormattedTime, processAppDocuments, writeToInfluxWithRetry, etc.)
├── v1/ # InfluxDB 1.x implementations (InfluxQL)
├── v2/ # InfluxDB 2.x implementations (Flux)
├── v3/ # InfluxDB 3.x implementations (SQL)
├── factory.js # Version router that delegates to appropriate implementation
└── index.js # Main facade providing consistent API
Refactoring Complete
All InfluxDB versions (v1, v2, v3) now use the refactored modular code.
Benefits:
- Modular, version-specific implementations
- Shared utilities reduce code duplication
- Unified retry logic with exponential backoff
- Comprehensive JSDoc documentation
- Better error handling and resource management
- Consistent patterns across all versions
Implementation Status
V1 (InfluxDB 1.x - InfluxQL)
✅ All modules complete:
- Health metrics
- Proxy sessions
- Butler memory usage
- User events
- Log events
- Event counts
- Queue metrics
V2 (InfluxDB 2.x - Flux)
✅ All modules complete:
- Health metrics
- Proxy sessions
- Butler memory usage
- User events
- Log events
- Event counts
- Queue metrics
V3 (InfluxDB 3.x - SQL)
✅ All modules complete:
- Health metrics
- Proxy sessions
- Butler memory usage
- User events
- Log events
- Event counts
- Queue metrics
Pending
- ⏳ Complete test coverage for all modules
- ⏳ Integration tests
- ⏳ Performance benchmarking
Usage
For Developers
When the feature flag is enabled, the facade in index.js will route calls to the refactored implementations. If a version-specific implementation is not yet complete, it automatically falls back to the original code.
// Imports work the same way
import { postHealthMetricsToInfluxdb } from './lib/influxdb/index.js';
// Function automatically routes based on feature flag
await postHealthMetricsToInfluxdb(serverName, host, body, serverTags);
Adding New Implementations
- Create the version-specific module (e.g.,
v3/sessions.js) - Import and export it in
factory.js - Update the facade in
index.jsto use the factory - Add tests in the appropriate
__tests__directory
Benefits
- Maintainability: Smaller, focused files instead of one 3000+ line file
- Testability: Each module can be tested in isolation
- Code Reuse: Shared utilities reduce duplication
- Version Management: Easy to deprecate old versions when needed
- Safe Migration: Feature flag allows gradual rollout
Original Implementation
The original implementation remains in /src/lib/post-to-influxdb.js and continues to work as before. This ensures no breaking changes during migration.