Skip to content

Commit d5e45b0

Browse files
rrwang7Convex, Inc.
authored andcommitted
breakdown file bandwidth by tag (#30752)
GitOrigin-RevId: afd71770e3d201b3949303863626f5279945731f
1 parent 30c96b9 commit d5e45b0

File tree

6 files changed

+56
-11
lines changed

6 files changed

+56
-11
lines changed

crates/application/src/export_worker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ impl<RT: Runtime> ExportWorker<RT> {
487487
)
488488
.track_storage_egress_size(
489489
component_path.clone(),
490+
"snapshot_export".to_string(),
490491
file_stream.content_length as u64,
491492
);
492493
zip_snapshot_upload

crates/application/src/snapshot_import.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2154,7 +2154,11 @@ async fn import_storage_table<RT: Runtime>(
21542154
content_type,
21552155
entry.sha256,
21562156
)
2157-
.track_storage_ingress_size(component_path.clone(), file_size);
2157+
.track_storage_ingress_size(
2158+
component_path.clone(),
2159+
"snapshot_import".to_string(),
2160+
file_size,
2161+
);
21582162
num_files += 1;
21592163
if let Some(import_id) = import_id {
21602164
best_effort_update_progress_message(

crates/events/src/usage.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub enum UsageEvent {
7878
StorageBandwidth {
7979
id: String,
8080
component_path: Option<String>,
81+
tag: String,
8182
ingress: u64,
8283
egress: u64,
8384
},

crates/file_storage/src/core.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,11 @@ impl<RT: Runtime> TransactionalFileStorage<RT> {
302302
if let Ok(ref bytes) = bytes {
303303
let bytes_size = bytes.len() as u64;
304304
log_get_file_chunk_size(bytes_size, get_file_type);
305-
storage_call_tracker
306-
.track_storage_egress_size(component_path.clone(), bytes_size);
305+
storage_call_tracker.track_storage_egress_size(
306+
component_path.clone(),
307+
"get_range".to_string(),
308+
bytes_size,
309+
);
307310
}
308311
bytes
309312
}),
@@ -448,7 +451,7 @@ impl<RT: Runtime> FileStorage<RT> {
448451
content_type,
449452
sha256,
450453
)
451-
.track_storage_ingress_size(component_path, size as u64);
454+
.track_storage_ingress_size(component_path, "store".to_string(), size as u64);
452455
Ok(virtual_id)
453456
}
454457
}

crates/isolate/src/environment/action/storage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<RT: Runtime> TaskExecutor<RT> {
9292
content_type,
9393
sha256,
9494
)
95-
.track_storage_ingress_size(component_path, size as u64);
95+
.track_storage_ingress_size(component_path, "store".to_string(), size as u64);
9696

9797
Ok(storage_doc_id)
9898
}

crates/usage_tracking/src/lib.rs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,18 @@ pub trait StorageUsageTracker: Send + Sync {
269269
}
270270

271271
pub trait StorageCallTracker: Send + Sync {
272-
fn track_storage_ingress_size(&self, component_path: ComponentPath, ingress_size: u64);
273-
fn track_storage_egress_size(&self, component_path: ComponentPath, egress_size: u64);
272+
fn track_storage_ingress_size(
273+
&self,
274+
component_path: ComponentPath,
275+
tag: String,
276+
ingress_size: u64,
277+
);
278+
fn track_storage_egress_size(
279+
&self,
280+
component_path: ComponentPath,
281+
tag: String,
282+
egress_size: u64,
283+
);
274284
}
275285

276286
struct IndependentStorageCallTracker {
@@ -288,21 +298,33 @@ impl IndependentStorageCallTracker {
288298
}
289299

290300
impl StorageCallTracker for IndependentStorageCallTracker {
291-
fn track_storage_ingress_size(&self, component_path: ComponentPath, ingress_size: u64) {
301+
fn track_storage_ingress_size(
302+
&self,
303+
component_path: ComponentPath,
304+
tag: String,
305+
ingress_size: u64,
306+
) {
292307
metrics::storage::log_storage_ingress_size(ingress_size);
293308
self.usage_logger.record(vec![UsageEvent::StorageBandwidth {
294309
id: self.execution_id.to_string(),
295310
component_path: component_path.serialize(),
311+
tag,
296312
ingress: ingress_size,
297313
egress: 0,
298314
}]);
299315
}
300316

301-
fn track_storage_egress_size(&self, component_path: ComponentPath, egress_size: u64) {
317+
fn track_storage_egress_size(
318+
&self,
319+
component_path: ComponentPath,
320+
tag: String,
321+
egress_size: u64,
322+
) {
302323
metrics::storage::log_storage_egress_size(egress_size);
303324
self.usage_logger.record(vec![UsageEvent::StorageBandwidth {
304325
id: self.execution_id.to_string(),
305326
component_path: component_path.serialize(),
327+
tag,
306328
ingress: 0,
307329
egress: egress_size,
308330
}]);
@@ -492,16 +514,30 @@ impl FunctionUsageTracker {
492514
// For UDFs, we track storage at the per UDF level, no finer. So we can just
493515
// aggregate over the entire UDF and not worry about sending usage events or
494516
// creating unique execution ids.
517+
// Note: If we want finer-grained breakdown of file bandwidth, we can thread the
518+
// tag through FunctionUsageStats. For now we're just interested in the
519+
// breakdown of file bandwidth from functions vs external sources like snapshot
520+
// export/cloud backups.
495521
impl StorageCallTracker for FunctionUsageTracker {
496-
fn track_storage_ingress_size(&self, component_path: ComponentPath, ingress_size: u64) {
522+
fn track_storage_ingress_size(
523+
&self,
524+
component_path: ComponentPath,
525+
_tag: String,
526+
ingress_size: u64,
527+
) {
497528
let mut state = self.state.lock();
498529
metrics::storage::log_storage_ingress_size(ingress_size);
499530
state
500531
.storage_ingress_size
501532
.mutate_entry_or_default(component_path, |count| *count += ingress_size);
502533
}
503534

504-
fn track_storage_egress_size(&self, component_path: ComponentPath, egress_size: u64) {
535+
fn track_storage_egress_size(
536+
&self,
537+
component_path: ComponentPath,
538+
_tag: String,
539+
egress_size: u64,
540+
) {
505541
let mut state = self.state.lock();
506542
metrics::storage::log_storage_egress_size(egress_size);
507543
state

0 commit comments

Comments
 (0)