mockforge_recorder/
sync_snapshots.rs1use crate::diff::ComparisonResult;
7use chrono::{DateTime, Utc};
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10use std::collections::HashMap;
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
14pub struct SnapshotData {
15 pub status_code: u16,
17 pub headers: HashMap<String, String>,
19 pub body: Vec<u8>,
21 pub body_json: Option<Value>,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27pub struct SyncSnapshot {
28 pub id: String,
30 pub endpoint: String,
32 pub method: String,
34 pub sync_cycle_id: String,
36 pub timestamp: DateTime<Utc>,
38 pub before: SnapshotData,
40 pub after: SnapshotData,
42 pub changes: ComparisonResult,
44 pub response_time_before: Option<u64>,
46 pub response_time_after: Option<u64>,
48}
49
50impl SyncSnapshot {
51 pub fn new(
53 endpoint: String,
54 method: String,
55 sync_cycle_id: String,
56 before: SnapshotData,
57 after: SnapshotData,
58 changes: ComparisonResult,
59 response_time_before: Option<u64>,
60 response_time_after: Option<u64>,
61 ) -> Self {
62 let id = format!(
63 "snapshot_{}_{}_{}",
64 endpoint.replace('/', "_").replace('{', "").replace('}', ""),
65 method.to_lowercase(),
66 uuid::Uuid::new_v4().to_string()[..8].to_string()
67 );
68
69 Self {
70 id,
71 endpoint,
72 method,
73 sync_cycle_id,
74 timestamp: Utc::now(),
75 before,
76 after,
77 changes,
78 response_time_before,
79 response_time_after,
80 }
81 }
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
86pub struct EndpointTimeline {
87 pub endpoint: String,
89 pub method: String,
91 pub snapshots: Vec<SyncSnapshot>,
93 pub response_time_trends: Vec<(DateTime<Utc>, Option<u64>)>,
95 pub status_code_history: Vec<(DateTime<Utc>, u16)>,
97 pub error_patterns: Vec<ErrorPattern>,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize)]
103pub struct ErrorPattern {
104 pub status_code: u16,
106 pub message_pattern: Option<String>,
108 pub occurrences: usize,
110 pub first_seen: DateTime<Utc>,
112 pub last_seen: DateTime<Utc>,
114}
115
116#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct EndpointEvolutionSummary {
119 pub endpoint: String,
121 pub method: String,
123 pub total_snapshots: usize,
125 pub total_changes: usize,
127 pub avg_response_time: Option<f64>,
129 pub most_common_status: Option<u16>,
131 pub field_change_frequency: HashMap<String, usize>,
133}