71267870b0
refactor: remove log dependency, replace with custom macros
...
- Added custom logging macros (log_error!, log_warn!, log_info!, log_debug!)
- Implemented LogLevel enum and LOG_LEVEL static for runtime level control
- Exported macros with #[macro_export] for use across all modules
- Replaced all log:: calls in websocket_client.rs, health.rs, and version.rs
- Removed obsolete test code referencing old log crate
- Removed log dependency from Cargo.toml
- Fixed useless comparison warning in test
- Binary size: still 1.5M (no change - log was lightweight)
- Tests: 65 passing, 0 warnings
This completes the removal of 9 dependencies (thiserror, hostname, chrono,
base64, rand, ureq, tiny_http, anyhow, log). Dependency count: 19 → 10.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 17:31:12 -06:00
55fb691440
refactor: remove 4 more dependencies (rand, ureq, tiny_http, anyhow)
...
Removed dependencies:
- rand: Replaced with SystemTime-based random for ICMP ID/sequence
- ureq: Removed Docker Hub version checking (Watchtower handles updates)
- tiny_http: Replaced with raw TCP listener for /health endpoint
- anyhow: Replaced with std::error::Error trait
Benefits:
- Binary size: 2.3M → 1.5M (800KB reduction, 35% smaller!)
- Dependencies: 19 → 11 direct dependencies (-8 total)
- Tests: 80 → 67 (removed Docker Hub API tests)
- All tests passing
Custom implementations:
- ICMP random: Use nanosecond timestamp for ID/sequence
- Health endpoint: Simple HTTP/1.1 parser on raw TCP
- Error handling: type Result<T> = std::result::Result<T, Box<dyn Error>>
Total progress from initial state:
- Binary: 2.4M → 1.5M (37.5% reduction!)
- Dependencies removed: 8 (thiserror, hostname, chrono, base64, rand, ureq, tiny_http, anyhow)
2026-01-19 17:20:49 -06:00
0b3cc9121e
Add comprehensive unit test coverage (29.19%)
...
Add 73 unit tests covering all testable business logic:
- src/snmp/types.rs: 100% coverage (17/17 lines)
* SnmpError display formatting
* SnmpValue conversions (as_i64, as_f64)
- src/snmp/client.rs: 34.4% coverage (32/93 lines)
* OID parsing/formatting/validation
* SNMP value conversion for all types
* Error mapping from snmp crate
* Helper functions (starts_with, format_oid)
- src/ping.rs: 65.2% coverage (58/89 lines)
* ICMP checksum calculation and verification
* Echo request packet building
* Reply packet parsing (raw and IP-wrapped)
* IP header length extraction (IHL field)
* Error handling for invalid packets
- src/version.rs: 54.0% coverage (27/50 lines)
* Version parsing with optional 'v' prefix
* Version comparison and sorting
* Docker Hub response deserialization
* Latest version extraction from tags
- src/websocket_client.rs: 7.7% coverage (17/221 lines)
* SnmpValue to string conversion
* Agent ID generation
* Phoenix message serialization/deserialization
* Helper functions (get_uptime_seconds, get_local_ip)
- src/main.rs: 20.0% coverage (11/55 lines)
* SimpleLogger enabled() logic
* HTTP/HTTPS to WebSocket URL conversion
- .gitlab-ci.yml: Add 'cargo test' to CI pipeline
Uncovered code requires integration testing:
- Network I/O (WebSocket, HTTP, Docker Hub API)
- System privileges (raw ICMP sockets)
- External services (SNMP devices, WebSocket servers)
- Runtime initialization (tokio main, logger setup)
All 73 tests pass. No test failures.
2026-01-19 15:07:00 -06:00
967d317b69
Complete WebSocket migration for agent communication
...
Major architectural change from REST API polling to WebSocket-based
bidirectional communication:
**What Changed:**
- Agent now uses persistent WebSocket connection instead of REST API
- Server pushes SNMP query jobs to agent via Phoenix Channels
- Agent executes raw SNMP queries and returns results
- Removed complex polling/scheduling/buffering architecture
**New Files:**
- src/websocket_client.rs - WebSocket client with SNMP job execution
- Extended proto/agent.proto with WebSocket message types
**Modified Files:**
- src/main.rs - Simplified to connect and run WebSocket client
- src/health.rs - Simplified health endpoint (no storage needed)
- src/snmp/mod.rs - Export SnmpValue for WebSocket client
**Removed Files:**
- src/api_client.rs - Old REST API client
- src/config.rs - Old config types
- src/buffer/ - SQLite buffering (no longer needed)
- src/metrics/ - Old metric types
- src/poller/ - Polling/scheduling logic
- src/snmp/neighbor.rs - High-level neighbor discovery
**Dependencies:**
- Switched from native-tls to rustls for WebSocket TLS
- Uses tokio-tungstenite for WebSocket communication
- Protobuf for efficient binary message encoding
**Benefits:**
- Simpler agent architecture (~500 lines vs 5000+)
- Real-time job execution (<1s vs 60s polling)
- No duplicate SNMP profile logic
- No local storage/buffering complexity
- 68% smaller message payloads (protobuf vs JSON)
2026-01-16 17:57:41 -06:00
d00e3782c3
Remove unused health server methods
...
- Removed update_config_fetch_time() and record_error()
- These methods were not integrated with the scheduler
- Fixes cargo clippy dead_code warnings
2026-01-15 08:06:29 -06:00
f7ac5f48e8
Add health endpoint for agent monitoring
...
Added /health HTTP endpoint on port 8080 that returns:
- Agent status and version
- Uptime in seconds
- Pending metrics count
- Last error (if any)
Implementation:
- Uses lightweight tiny_http server in background thread
- Non-blocking health checks
- Returns JSON for easy integration with monitoring tools
- Ready for Kubernetes liveness/readiness probes
Example response:
{
"status": "healthy",
"version": "0.1.0",
"uptime_seconds": 3600,
"config_last_fetch": "2026-01-14T23:00:00Z",
"metrics_pending": 0,
"last_error": null
}
2026-01-14 18:46:25 -06:00