From 4c14721dfc2b11805432725111beec1f30466e95 Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Sat, 25 Apr 2026 01:32:34 +0300 Subject: [PATCH] feat: Add error statistics, sync control, and detailed health check API endpoints - Add GET /v1/errors endpoint to retrieve error statistics (total/types/last error) - Add POST /v1/sync/start endpoint to start background sync - Add GET /v1/health/detailed endpoint for detailed health checks (redis/sync/memory status) --- apps/charging-engine/src/api.rs | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/apps/charging-engine/src/api.rs b/apps/charging-engine/src/api.rs index 3a078c1..4b8cd1d 100644 --- a/apps/charging-engine/src/api.rs +++ b/apps/charging-engine/src/api.rs @@ -437,3 +437,47 @@ pub async fn engine_uptime( "uptime_seconds": uptime.as_secs(), }))) } + +/// GET /v1/errors +/// Get error statistics +pub async fn get_error_stats( + State(state): State, +) -> ChargingResult> { + let errors = state.charging_engine.get_error_statistics().await + .with_context("Failed to get error statistics")?; + + Ok(Json(serde_json::json!({ + "total_errors": errors.total_errors, + "error_types": errors.error_types, + "last_error": errors.last_error, + }))) +} + +/// POST /v1/sync/start +/// Start background sync +pub async fn start_sync( + State(state): State, +) -> ChargingResult> { + state.charging_engine.start_background_sync().await + .with_context("Failed to start background sync")?; + + Ok(Json(serde_json::json!({ + "status": "sync_started", + }))) +} + +/// GET /v1/health/detailed +/// Get detailed health check +pub async fn detailed_health_check( + State(state): State, +) -> ChargingResult> { + let health = state.charging_engine.health_check().await + .with_context("Failed to get health check")?; + + Ok(Json(serde_json::json!({ + "redis_connected": health.redis_connected, + "active_sync": health.active_sync, + "last_sync": health.last_sync, + "memory_usage": health.memory_usage, + }))) +}