Add graceful shutdown and health HTTP endpoint - #3
Conversation
…covery, task execution Complete implementation of the SigOps infrastructure agent in Rust: - config.rs: CLI args + env vars via clap (server URL, agent ID, tenant, token, interval) - discovery.rs: Host info collection + tool discovery (systemctl, docker, kubectl, curl, etc.) - heartbeat.rs: HTTP heartbeat client with JSON payload to SigOps server - executor.rs: Task execution engine with 4 built-in tools: - sigops.restart: Service restart with input sanitization - sigops.http: HTTP requests via curl - sigops.condition: Numeric expression evaluation - sigops.wait: Timed delay with 3600s max - main.rs: Tokio async runtime, heartbeat loop, tracing logging Infrastructure: - GitHub Actions CI (Rust toolchain + cache + build + test + clippy) - 18 unit tests, all passing - Cargo.lock committed for reproducible builds Dependencies: tokio, reqwest, serde, clap, tracing, uuid, hostname, thiserror https://claude.ai/code/session_016BNDbB5ERJFsXQZiuL6tL1
- Graceful shutdown: handles SIGTERM and SIGINT, cleanly stops heartbeat loop - Health endpoint: GET /health on port 9100 returns JSON status - Uses shared AtomicBool shutdown flag across all async tasks - 22 tests passing, clippy clean https://claude.ai/code/session_016BNDbB5ERJFsXQZiuL6tL1
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe PR adds a health monitoring endpoint, implements Slack notification tool support, introduces graceful shutdown handling with signal management, and refactors the main runtime to manage multiple concurrent tasks. CI testing scope is expanded to cover all targets. Changes
Sequence DiagramssequenceDiagram
participant Client
participant HealthServer as Health Server
participant Heartbeat Task
Client->>HealthServer: HTTP GET /health
HealthServer->>HealthServer: Serialize JSON status
HealthServer->>Client: HTTP 200 + status JSON
Note over HealthServer: Checks shutdown flag periodically
Client->>HealthServer: [idle]
Heartbeat Task->>Heartbeat Task: Monitor shutdown flag
Heartbeat Task->>HealthServer: [shutdown signal received]
HealthServer->>HealthServer: Accept loop exits gracefully
sequenceDiagram
participant Client
participant Executor as Executor Task
participant curl as curl Command
Client->>Executor: execute("sigops.notify_slack", {channel, message, webhookUrl})
Executor->>Executor: Validate channel & message
Executor->>Executor: Build Slack JSON payload
Executor->>curl: POST JSON via curl
curl->>curl: Send HTTP request
curl->>Executor: Return status code in stdout
Executor->>Executor: Parse HTTP status
Executor->>Client: Return {ok, channel, status}
sequenceDiagram
participant OS as OS/Signal Handler
participant Main as Main Runtime
participant HeartbeatTask as Heartbeat Task
participant HealthTask as Health Task
Main->>HeartbeatTask: Spawn async task
Main->>HealthTask: Spawn health server task
Main->>Main: Listen for SIGINT/SIGTERM
OS->>Main: Signal received (Ctrl-C or SIGTERM)
Main->>Main: Set shutdown flag (Arc<AtomicBool>)
HeartbeatTask->>HeartbeatTask: Detect shutdown flag
HealthTask->>HealthTask: Detect shutdown flag & exit loop
Main->>HeartbeatTask: Wait (timeout 5s)
Main->>HealthTask: Wait (timeout 5s)
HeartbeatTask->>Main: Task complete
HealthTask->>Main: Task complete
Main->>Main: Exit gracefully
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
Summary
Test plan
cargo test— 22 tests passingcargo clippy— zero warningshttps://claude.ai/code/session_016BNDbB5ERJFsXQZiuL6tL1
Summary by CodeRabbit
New Features
Tests
Chores