1818
1919use std:: { collections:: HashMap , time:: Duration } ;
2020
21- use chrono:: { DateTime , Utc } ;
21+ use chrono:: { DateTime , NaiveDate , Utc } ;
2222use serde:: { Deserialize , Serialize } ;
2323use serde_json:: Value ;
2424use tokio:: sync:: { RwLock , mpsc} ;
@@ -36,7 +36,7 @@ use crate::{
3636 } ,
3737 metastore:: metastore_traits:: MetastoreObject ,
3838 query:: resolve_stream_names,
39- storage:: object_storage:: { alert_json_path, alert_state_json_path} ,
39+ storage:: object_storage:: { alert_json_path, alert_state_json_path, mttr_json_path } ,
4040} ;
4141
4242const RESERVED_FIELDS : & [ & str ] = & [
@@ -695,6 +695,32 @@ pub struct AggregatedMTTRStats {
695695 pub per_alert_stats : HashMap < String , MTTRStats > ,
696696}
697697
698+ /// Daily MTTR statistics for a specific date
699+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
700+ #[ serde( rename_all = "camelCase" ) ]
701+ pub struct DailyMTTRStats {
702+ /// Date in YYYY-MM-DD format
703+ pub date : NaiveDate ,
704+ /// Aggregated MTTR statistics for this date
705+ pub stats : AggregatedMTTRStats ,
706+ }
707+
708+ /// MTTR history containing array of daily MTTR objects
709+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
710+ #[ serde( rename_all = "camelCase" ) ]
711+ pub struct MTTRHistory {
712+ /// Array of daily MTTR statistics
713+ pub daily_stats : Vec < DailyMTTRStats > ,
714+ }
715+
716+ /// Query parameters for MTTR API endpoint
717+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
718+ #[ serde( rename_all = "camelCase" ) ]
719+ pub struct MTTRQueryParams {
720+ pub start_date : Option < String > ,
721+ pub end_date : Option < String > ,
722+ }
723+
698724impl AggregatedMTTRStats {
699725 /// Calculate aggregated MTTR stats from multiple alert state entries
700726 pub fn from_alert_states ( alert_states : Vec < AlertStateEntry > ) -> Self {
@@ -860,3 +886,13 @@ impl MetastoreObject for AlertConfig {
860886 alert_json_path ( self . id ) . to_string ( )
861887 }
862888}
889+
890+ impl MetastoreObject for MTTRHistory {
891+ fn get_object_id ( & self ) -> String {
892+ "mttr" . to_string ( )
893+ }
894+
895+ fn get_object_path ( & self ) -> String {
896+ mttr_json_path ( ) . to_string ( )
897+ }
898+ }
0 commit comments