use std::collections::BTreeMap;
use serde::Serialize;
use crate::threshold::ThresholdReport;
#[derive(Serialize, Debug)]
pub struct RunReport {
pub version: u32,
pub run: RunMeta,
pub requests: RequestSummary,
pub latency: LatencyStats,
pub status_codes: BTreeMap<String, u64>,
pub response_stats: Option<ResponseStatsReport>,
pub curve_stages: Option<Vec<StageReport>>,
pub scenarios: Option<Vec<ScenarioReport>>,
pub thresholds: Option<ThresholdReport>,
}
#[derive(Serialize, Debug)]
pub struct RunMeta {
pub mode: String,
pub elapsed_ms: f64,
pub curve_duration_ms: Option<f64>,
pub template_generation_ms: Option<f64>,
}
#[derive(Serialize, Debug)]
pub struct RequestSummary {
pub total: usize,
pub ok: usize,
pub failed: usize,
#[serde(skip_serializing_if = "is_zero_usize")]
pub skipped: usize,
pub error_rate: f64,
pub throughput_rps: f64,
}
fn is_zero_usize(v: &usize) -> bool {
*v == 0
}
#[derive(Serialize, Debug)]
pub struct LatencyStats {
pub min_ms: f64,
pub p10_ms: f64,
pub p25_ms: f64,
pub p50_ms: f64,
pub p75_ms: f64,
pub p90_ms: f64,
pub p95_ms: f64,
pub p99_ms: f64,
pub max_ms: f64,
pub avg_ms: f64,
}
#[derive(Serialize, Debug)]
pub struct ResponseStatsReport {
pub responses_parsed: u64,
pub string_fields: BTreeMap<String, BTreeMap<String, u64>>,
pub float_fields: BTreeMap<String, FloatFieldSummary>,
pub mismatch_counts: BTreeMap<String, u64>,
}
#[derive(Serialize, Debug)]
pub struct FloatFieldSummary {
pub min: f64,
pub avg: f64,
pub p50: f64,
pub p95: f64,
pub p99: f64,
pub max: f64,
}
#[derive(Serialize, Debug)]
pub struct StageReport {
pub index: usize,
pub duration_ms: f64,
pub target_vus: u32,
pub ramp: String,
pub requests: usize,
pub ok: usize,
pub failed: usize,
pub error_rate: f64,
pub throughput_rps: f64,
pub latency: LatencyStats,
}
#[derive(Serialize, Debug)]
pub struct ScenarioReport {
pub name: String,
pub requests: RequestSummary,
pub latency: LatencyStats,
pub status_codes: BTreeMap<String, u64>,
pub steps: Vec<ScenarioStepReport>,
}
#[derive(Serialize, Debug)]
pub struct ScenarioStepReport {
pub name: String,
pub requests: RequestSummary,
pub latency: LatencyStats,
pub status_codes: BTreeMap<String, u64>,
}