@@ -15,8 +15,9 @@ use url::Url;
1515use viaduct:: Request ;
1616
1717use crate :: {
18- client:: RemoteState , config:: BaseUrl , error:: Error , storage:: Storage , RemoteSettingsClient ,
19- RemoteSettingsConfig2 , RemoteSettingsContext , RemoteSettingsServer , Result ,
18+ client:: RemoteState , config:: BaseUrl , error:: Error , storage:: Storage ,
19+ telemetry:: RemoteSettingsTelemetryWrapper , RemoteSettingsClient , RemoteSettingsConfig2 ,
20+ RemoteSettingsContext , RemoteSettingsServer , Result ,
2021} ;
2122
2223/// Internal Remote settings service API
@@ -30,6 +31,7 @@ struct RemoteSettingsServiceInner {
3031 bucket_name : String ,
3132 app_context : Option < RemoteSettingsContext > ,
3233 remote_state : RemoteState ,
34+ telemetry : RemoteSettingsTelemetryWrapper ,
3335 /// Weakrefs for all clients that we've created. Note: this stores the
3436 /// top-level/public `RemoteSettingsClient` structs rather than `client::RemoteSettingsClient`.
3537 /// The reason for this is that we return Arcs to the public struct to the foreign code, so we
@@ -57,11 +59,16 @@ impl RemoteSettingsService {
5759 bucket_name,
5860 app_context : config. app_context ,
5961 remote_state : RemoteState :: default ( ) ,
62+ telemetry : RemoteSettingsTelemetryWrapper :: noop ( ) ,
6063 clients : vec ! [ ] ,
6164 } ) ,
6265 }
6366 }
6467
68+ pub fn set_telemetry ( & self , telemetry : RemoteSettingsTelemetryWrapper ) {
69+ self . inner . lock ( ) . telemetry = telemetry;
70+ }
71+
6572 pub fn make_client ( & self , collection_name : String ) -> Arc < RemoteSettingsClient > {
6673 let mut inner = self . inner . lock ( ) ;
6774 // Allow using in-memory databases for testing of external crates.
@@ -84,11 +91,16 @@ impl RemoteSettingsService {
8491
8592 /// Sync collections for all active clients
8693 pub fn sync ( & self ) -> Result < Vec < String > > {
94+ const TELEMETRY_SOURCE_POLL : & str = "settings-changes-monitoring" ;
8795 // Make sure we only sync each collection once, even if there are multiple clients
8896 let mut synced_collections = HashSet :: new ( ) ;
8997
9098 let mut inner = self . inner . lock ( ) ;
91- let changes = inner. fetch_changes ( ) ?;
99+ let changes_result = inner. fetch_changes ( ) ;
100+ if let Err ( ref e) = changes_result {
101+ inner. telemetry . report_sync_error ( e, TELEMETRY_SOURCE_POLL ) ;
102+ }
103+ let changes = changes_result?;
92104 let change_map: HashMap < _ , _ > = changes
93105 . changes
94106 . iter ( )
@@ -99,18 +111,27 @@ impl RemoteSettingsService {
99111 for client in inner. active_clients ( ) {
100112 let client = & client. internal ;
101113 let collection_name = client. collection_name ( ) ;
114+ let cid = format ! ( "{bucket_name}/{collection_name}" ) ;
102115 if let Some ( client_last_modified) = client. get_last_modified_timestamp ( ) ? {
103116 if let Some ( server_last_modified) = change_map. get ( & ( collection_name, & bucket_name) )
104117 {
105118 if client_last_modified == * server_last_modified {
106119 trace ! ( "skipping up-to-date collection: {collection_name}" ) ;
120+ inner. telemetry . report_up_to_date ( & cid, None ) ;
107121 continue ;
108122 }
109123 }
110124 }
111125 if synced_collections. insert ( collection_name. to_string ( ) ) {
112126 trace ! ( "syncing collection: {collection_name}" ) ;
113- client. sync ( ) ?;
127+ let start_time = std:: time:: Instant :: now ( ) ;
128+ let sync_result = client. sync ( ) ;
129+ let duration: u64 = start_time. elapsed ( ) . as_millis ( ) . try_into ( ) . unwrap_or ( 0 ) ;
130+ match & sync_result {
131+ Ok ( ( ) ) => inner. telemetry . report_success ( & cid, Some ( duration) ) ,
132+ Err ( e) => inner. telemetry . report_sync_error ( e, & cid) ,
133+ }
134+ sync_result?;
114135 }
115136 }
116137 Ok ( synced_collections. into_iter ( ) . collect ( ) )
0 commit comments