11use crate :: log:: Log ;
2- use datadog_sidecar:: service:: telemetry:: path_for_telemetry;
2+ use datadog_sidecar:: service:: telemetry:: { path_for_telemetry, TelemetryCachedClientShmData } ;
33
44use hashbrown:: { Equivalent , HashMap } ;
5- use std:: collections:: HashSet ;
65use std:: ffi:: CString ;
76use std:: path:: PathBuf ;
8- use std:: time:: { Duration , SystemTime } ;
7+ use std:: time:: Duration ;
98
109use datadog_ipc:: platform:: NamedShmHandle ;
1110use datadog_sidecar:: one_way_shared_memory:: { open_named_shm, OneWayShmReader } ;
@@ -255,10 +254,7 @@ pub unsafe extern "C" fn ddog_sidecar_telemetry_add_integration_log_buffer(
255254}
256255
257256pub struct ShmCache {
258- pub config_sent : bool ,
259- pub integrations : HashSet < Integration > ,
260- pub composer_paths : HashSet < PathBuf > ,
261- pub last_endpoints_push : SystemTime ,
257+ pub shared : TelemetryCachedClientShmData ,
262258 pub reader : OneWayShmReader < NamedShmHandle , CString > ,
263259}
264260
@@ -287,7 +283,7 @@ pub unsafe extern "C" fn ddog_sidecar_telemetry_config_sent(
287283 service : CharSlice ,
288284 env : CharSlice ,
289285) -> bool {
290- ddog_sidecar_telemetry_cache_get_or_update ( cache, service, env) . config_sent
286+ ddog_sidecar_telemetry_cache_get_or_update ( cache, service, env) . shared . config_sent
291287}
292288
293289unsafe fn ddog_sidecar_telemetry_cache_get_or_update < ' a > (
@@ -305,21 +301,13 @@ unsafe fn ddog_sidecar_telemetry_cache_get_or_update<'a>(
305301 if changed {
306302 buf = newbuf;
307303 } else {
308- cache. config_sent = false ;
309- cache. integrations . clear ( ) ;
310- cache. composer_paths . clear ( ) ;
311- cache. last_endpoints_push = SystemTime :: UNIX_EPOCH ;
304+ cache. shared = TelemetryCachedClientShmData :: default ( ) ;
312305 return ;
313306 }
314307 }
315308
316- if let Ok ( ( config_sent, integrations, composer_paths, last_endpoints_push) ) =
317- bincode:: deserialize :: < ( bool , HashSet < Integration > , HashSet < PathBuf > , SystemTime ) > ( buf)
318- {
319- cache. config_sent = config_sent;
320- cache. integrations = integrations;
321- cache. composer_paths = composer_paths;
322- cache. last_endpoints_push = last_endpoints_push;
309+ if let Ok ( shared) = bincode:: deserialize :: < TelemetryCachedClientShmData > ( buf) {
310+ cache. shared = shared;
323311 }
324312 }
325313 }
@@ -337,10 +325,7 @@ unsafe fn ddog_sidecar_telemetry_cache_get_or_update<'a>(
337325 let reader = OneWayShmReader :: < NamedShmHandle , _ > :: new ( open_named_shm ( & shm_path) . ok ( ) , shm_path) ;
338326 let cached_entry = cache. entry ( ShmCacheKey ( service_str. into ( ) , env_str. into ( ) ) ) . insert ( ShmCache {
339327 reader,
340- config_sent : false ,
341- integrations : HashSet :: new ( ) ,
342- composer_paths : HashSet :: new ( ) ,
343- last_endpoints_push : SystemTime :: UNIX_EPOCH ,
328+ shared : TelemetryCachedClientShmData :: default ( ) ,
344329 } ) . into_mut ( ) ;
345330
346331 refresh_cache ( cached_entry) ;
@@ -365,10 +350,10 @@ pub unsafe extern "C" fn ddog_sidecar_telemetry_filter_flush(
365350 . into_iter ( )
366351 . filter ( |action| match action {
367352 SidecarAction :: Telemetry ( TelemetryActions :: AddIntegration ( integration) ) => {
368- !cache_entry. integrations . contains ( integration)
353+ !cache_entry. shared . integrations . contains ( integration)
369354 }
370355 SidecarAction :: PhpComposerTelemetryFile ( path) => {
371- !cache_entry. composer_paths . contains ( path)
356+ !cache_entry. shared . composer_paths . contains ( path)
372357 }
373358 _ => true ,
374359 } )
@@ -392,5 +377,5 @@ pub unsafe extern "C" fn ddog_sidecar_telemetry_are_endpoints_collected(
392377 env : CharSlice ,
393378) -> bool {
394379 let cache_entry = ddog_sidecar_telemetry_cache_get_or_update ( cache, service, env) ;
395- cache_entry. last_endpoints_push . elapsed ( ) . map_or ( false , |d| d < Duration :: from_secs ( 1800 ) ) // 30 minutes
380+ cache_entry. shared . last_endpoints_push . elapsed ( ) . map_or ( false , |d| d < Duration :: from_secs ( 1800 ) ) // 30 minutes
396381}
0 commit comments