1+ use crate :: app_metrics;
12use crate :: di_service;
23use crate :: remotefs:: { LocalDirRemoteFs , RemoteFile , RemoteFs } ;
34use crate :: util:: lock:: acquire_lock;
@@ -25,6 +26,7 @@ pub struct S3RemoteFs {
2526 bucket : std:: sync:: RwLock < Bucket > ,
2627 sub_path : Option < String > ,
2728 delete_mut : Mutex < ( ) > ,
29+ cube_host : String ,
2830}
2931
3032impl fmt:: Debug for S3RemoteFs {
@@ -48,6 +50,7 @@ impl S3RemoteFs {
4850 region : String ,
4951 bucket_name : String ,
5052 sub_path : Option < String > ,
53+ cube_host : String ,
5154 ) -> Result < Arc < Self > , CubeError > {
5255 let key_id = env:: var ( "CUBESTORE_AWS_ACCESS_KEY_ID" ) . ok ( ) ;
5356 let access_key = env:: var ( "CUBESTORE_AWS_SECRET_ACCESS_KEY" ) . ok ( ) ;
@@ -61,6 +64,7 @@ impl S3RemoteFs {
6164 bucket,
6265 sub_path,
6366 delete_mut : Mutex :: new ( ( ) ) ,
67+ cube_host,
6468 } ) ;
6569 spawn_creds_refresh_loop ( key_id, access_key, bucket_name, region, & fs) ;
6670 Ok ( fs)
@@ -138,6 +142,15 @@ impl RemoteFs for S3RemoteFs {
138142 remote_path : & str ,
139143 ) -> Result < u64 , CubeError > {
140144 {
145+ app_metrics:: REMOTE_FS_OPERATION_CORE . add_with_tags (
146+ 1 ,
147+ Some ( & vec ! [
148+ "operation:upload_file" . to_string( ) ,
149+ "driver:s3" . to_string( ) ,
150+ format!( "cube_host:{}" , self . cube_host) ,
151+ ] ) ,
152+ ) ;
153+
141154 let time = SystemTime :: now ( ) ;
142155 debug ! ( "Uploading {}" , remote_path) ;
143156 let path = self . s3_path ( remote_path) ;
@@ -188,6 +201,14 @@ impl RemoteFs for S3RemoteFs {
188201
189202 fs:: create_dir_all ( & downloads_dir) . await ?;
190203 if !local_file. exists ( ) {
204+ app_metrics:: REMOTE_FS_OPERATION_CORE . add_with_tags (
205+ 1 ,
206+ Some ( & vec ! [
207+ "operation:download_file" . to_string( ) ,
208+ "driver:s3" . to_string( ) ,
209+ format!( "cube_host:{}" , self . cube_host) ,
210+ ] ) ,
211+ ) ;
191212 let time = SystemTime :: now ( ) ;
192213 debug ! ( "Downloading {}" , remote_path) ;
193214 let path = self . s3_path ( remote_path) ;
@@ -216,6 +237,14 @@ impl RemoteFs for S3RemoteFs {
216237 }
217238
218239 async fn delete_file ( & self , remote_path : & str ) -> Result < ( ) , CubeError > {
240+ app_metrics:: REMOTE_FS_OPERATION_CORE . add_with_tags (
241+ 1 ,
242+ Some ( & vec ! [
243+ "operation:delete_file" . to_string( ) ,
244+ "driver:s3" . to_string( ) ,
245+ format!( "cube_host:{}" , self . cube_host) ,
246+ ] ) ,
247+ ) ;
219248 let time = SystemTime :: now ( ) ;
220249 debug ! ( "Deleting {}" , remote_path) ;
221250 let path = self . s3_path ( remote_path) ;
@@ -251,6 +280,14 @@ impl RemoteFs for S3RemoteFs {
251280 }
252281
253282 async fn list_with_metadata ( & self , remote_prefix : & str ) -> Result < Vec < RemoteFile > , CubeError > {
283+ app_metrics:: REMOTE_FS_OPERATION_CORE . add_with_tags (
284+ 1 ,
285+ Some ( & vec ! [
286+ "operation:list" . to_string( ) ,
287+ "driver:s3" . to_string( ) ,
288+ format!( "cube_host:{}" , self . cube_host) ,
289+ ] ) ,
290+ ) ;
254291 let path = self . s3_path ( remote_prefix) ;
255292 let bucket = self . bucket . read ( ) . unwrap ( ) . clone ( ) ;
256293 let list = cube_ext:: spawn_blocking ( move || bucket. list_blocking ( path, None ) ) . await ??;
0 commit comments