mockforge_http/handlers/
deceptive_canary.rs1use crate::middleware::DeceptiveCanaryState;
4use axum::extract::State;
5use axum::response::Json;
6use mockforge_core::deceptive_canary::DeceptiveCanaryConfig;
7use serde::{Deserialize, Serialize};
8use serde_json::{json, Value};
9
10#[derive(Debug, Deserialize)]
12pub struct UpdateCanaryConfigRequest {
13 pub config: DeceptiveCanaryConfig,
15}
16
17#[derive(Debug, Serialize)]
19pub struct CanaryStatsResponse {
20 pub success: bool,
22 pub stats: Value,
24 pub canary_percentage: f64,
26}
27
28pub async fn get_canary_config(State(state): State<DeceptiveCanaryState>) -> Json<Value> {
32 let config = state.router.config();
33 Json(json!({
34 "success": true,
35 "config": config,
36 }))
37}
38
39pub async fn update_canary_config(
43 State(_state): State<DeceptiveCanaryState>,
44 Json(request): Json<UpdateCanaryConfigRequest>,
45) -> Json<Value> {
46 Json(json!({
50 "success": true,
51 "message": "Configuration update requires router state management",
52 "config": request.config,
53 }))
54}
55
56pub async fn get_canary_stats(State(state): State<DeceptiveCanaryState>) -> Json<Value> {
60 let stats = state.router.stats();
61 let canary_percentage = stats.map(|s| s.canary_percentage()).unwrap_or(0.0);
62
63 Json(json!({
64 "success": true,
65 "stats": stats,
66 "canary_percentage": canary_percentage,
67 }))
68}