@@ -4,9 +4,10 @@ use crate::memory_store::MemoryStore;
44use async_trait:: async_trait;
55use nativelink_error:: Error ;
66use nativelink_metric:: MetricsComponent ;
7+ use nativelink_proto:: build_event_stream:: File ;
78use nativelink_util:: buf_channel:: { DropCloserReadHalf , DropCloserWriteHalf } ;
89use nativelink_util:: health_utils:: { HealthStatus , HealthStatusIndicator } ;
9- use nativelink_util:: metrics:: { STORE_METRICS , StoreMetricAttrs , StoreType } ;
10+ use nativelink_util:: metrics:: { StoreMetricAttrs , StoreType , STORE_METRICS } ;
1011use nativelink_util:: store_trait:: {
1112 RemoveItemCallback , Store , StoreDriver , StoreKey , StoreLike , UploadSizeInfo ,
1213} ;
@@ -25,19 +26,26 @@ impl MetricsStore {
2526 #[ must_use]
2627 pub fn new ( inner : Arc < Store > , name : & str , store_type : StoreType ) -> Arc < Self > {
2728 let attrs = Arc :: new ( StoreMetricAttrs :: new_with_name ( store_type, name) ) ;
28- if should_add_remove_callback ( inner. clone ( ) ) {
29+ if let Some ( fs_store ) = inner. downcast_ref :: < FilesystemStore > ( None ) {
2930 #[ derive( Debug ) ]
3031 struct EvictionCallback {
3132 attrs : Arc < StoreMetricAttrs > ,
3233 }
3334 impl RemoveItemCallback for EvictionCallback {
34- fn callback < ' a > ( & ' a self , store_key : StoreKey < ' a > ) -> Pin < Box < dyn Future < Output =( ) > + Send + ' a > > {
35+ fn callback < ' a > (
36+ & ' a self ,
37+ _store_key : StoreKey < ' a > ,
38+ ) -> Pin < Box < dyn Future < Output = ( ) > + Send + ' a > > {
3539 Box :: pin ( async { STORE_METRICS . eviction_count . add ( 1 , self . attrs . eviction ( ) ) } )
3640 }
3741 }
38- if let Err ( e) = inner. register_remove_callback ( Arc :: new ( EvictionCallback { attrs : attrs. clone ( ) } ) ) {
42+ if let Err ( e) = inner. register_remove_callback ( Arc :: new ( EvictionCallback {
43+ attrs : attrs. clone ( ) ,
44+ } ) ) {
3945 tracing:: error!( "Failed to register remove callback: {:?}" , e) ;
4046 }
47+
48+ STORE_METRICS . store_size . record ( fs_store. get_len ( ) , & attrs. store_size ( ) ) ;
4149 }
4250
4351 Arc :: new ( Self {
@@ -103,6 +111,10 @@ impl StoreDriver for MetricsStore {
103111 . record ( duration_ms as f64 , & self . attrs . write_error ( ) ) ;
104112 }
105113
114+ if let Some ( fs_store) = self . inner . downcast_ref :: < FilesystemStore > ( None ) {
115+ STORE_METRICS . store_size . record ( fs_store. get_len ( ) , & self . attrs . store_size ( ) ) ;
116+ }
117+
106118 result
107119 }
108120
@@ -168,5 +180,4 @@ impl HealthStatusIndicator for MetricsStore {
168180
169181fn should_add_remove_callback ( store : Arc < Store > ) -> bool {
170182 store. downcast_ref :: < FilesystemStore > ( None ) . is_some ( )
171- || store. downcast_ref :: < MemoryStore > ( None ) . is_some ( )
172183}
0 commit comments