Skip to content

Commit 583ec19

Browse files
Sujay JayakarConvex, Inc.
authored andcommitted
Revert "Revert "make storage egress and ingress usage component aware (#29846)" (#29883)" (#29917)
GitOrigin-RevId: dab054fa2ecc8da07854bab1234d479c17ea9f04
1 parent 8192a98 commit 583ec19

File tree

9 files changed

+235
-43
lines changed

9 files changed

+235
-43
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/application/src/export_worker.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,10 @@ impl<RT: Runtime> ExportWorker<RT> {
483483
content_type,
484484
file_storage_entry.sha256.clone(),
485485
)
486-
.track_storage_egress_size(file_stream.content_length as u64);
486+
.track_storage_egress_size(
487+
component_path.clone(),
488+
file_stream.content_length as u64,
489+
);
487490
zip_snapshot_upload
488491
.stream_full_file(path, file_stream.stream)
489492
.await?;
@@ -1218,7 +1221,13 @@ mod tests {
12181221

12191222
let usage = usage.gather_user_stats();
12201223
assert!(usage.database_egress_size.is_empty());
1221-
assert_eq!(usage.storage_egress_size, 3);
1224+
assert_eq!(
1225+
*usage
1226+
.storage_egress_size
1227+
.get(&ComponentPath::test_user())
1228+
.unwrap(),
1229+
3
1230+
);
12221231

12231232
Ok(())
12241233
}

crates/application/src/snapshot_import.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,7 @@ async fn import_storage_table<RT: Runtime>(
20962096
content_type,
20972097
entry.sha256,
20982098
)
2099-
.track_storage_ingress_size(file_size);
2099+
.track_storage_ingress_size(component_path.clone(), file_size);
21002100
num_files += 1;
21012101
if let Some(import_id) = import_id {
21022102
best_effort_update_progress_message(
@@ -3517,8 +3517,11 @@ a
35173517
.await?;
35183518

35193519
let stats = usage.gather_user_stats();
3520-
assert!(stats.database_ingress_size[&(component_path, table_name.to_string())] > 0);
3521-
assert_eq!(stats.storage_ingress_size, 9);
3520+
assert!(stats.database_ingress_size[&(component_path.clone(), table_name.to_string())] > 0);
3521+
assert_eq!(
3522+
*stats.storage_ingress_size.get(&component_path).unwrap(),
3523+
9u64
3524+
);
35223525

35233526
Ok(())
35243527
}

crates/events/src/usage.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ pub enum UsageEvent {
7777
/// import/export).
7878
StorageBandwidth {
7979
id: String,
80+
component_path: Option<String>,
8081
ingress: u64,
8182
egress: u64,
8283
},

crates/file_storage/src/core.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ impl<RT: Runtime> TransactionalFileStorage<RT> {
243243
let stream = storage_get_stream.stream;
244244
let content_length = ContentLength(storage_get_stream.content_length as u64);
245245

246+
let component_path = ComponentPath::TODO();
246247
let call_tracker = usage_tracker.track_storage_call(
247-
ComponentPath::TODO(),
248+
component_path.clone(),
248249
"get range",
249250
storage_id,
250251
content_type.clone(),
@@ -255,11 +256,12 @@ impl<RT: Runtime> TransactionalFileStorage<RT> {
255256
content_length,
256257
content_range,
257258
content_type,
258-
stream: Self::track_stream_usage(stream, get_file_type, call_tracker),
259+
stream: Self::track_stream_usage(component_path, stream, get_file_type, call_tracker),
259260
})
260261
}
261262

262263
fn track_stream_usage(
264+
component_path: ComponentPath,
263265
stream: BoxStream<'static, futures::io::Result<bytes::Bytes>>,
264266
get_file_type: GetFileType,
265267
storage_call_tracker: Box<dyn StorageCallTracker>,
@@ -291,7 +293,8 @@ impl<RT: Runtime> TransactionalFileStorage<RT> {
291293
if let Ok(ref bytes) = bytes {
292294
let bytes_size = bytes.len() as u64;
293295
log_get_file_chunk_size(bytes_size, get_file_type);
294-
storage_call_tracker.track_storage_egress_size(bytes_size);
296+
storage_call_tracker
297+
.track_storage_egress_size(component_path.clone(), bytes_size);
295298
}
296299
bytes
297300
}),
@@ -429,8 +432,14 @@ impl<RT: Runtime> FileStorage<RT> {
429432
.await?;
430433

431434
usage_tracker
432-
.track_storage_call(component_path, "store", storage_id, content_type, sha256)
433-
.track_storage_ingress_size(size as u64);
435+
.track_storage_call(
436+
component_path.clone(),
437+
"store",
438+
storage_id,
439+
content_type,
440+
sha256,
441+
)
442+
.track_storage_ingress_size(component_path, size as u64);
434443
Ok(virtual_id)
435444
}
436445
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,16 @@ impl<RT: Runtime> TaskExecutor<RT> {
8080
.storage_store_file_entry(self.identity.clone(), self.component_id(), entry)
8181
.await?;
8282

83+
let component_path = ComponentPath::TODO();
8384
self.usage_tracker
8485
.track_storage_call(
85-
ComponentPath::TODO(),
86+
component_path.clone(),
8687
"store",
8788
storage_id,
8889
content_type,
8990
sha256,
9091
)
91-
.track_storage_ingress_size(size as u64);
92+
.track_storage_ingress_size(component_path, size as u64);
9293

9394
Ok(storage_doc_id)
9495
}

crates/pb/protos/usage.proto

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@ package usage;
44

55
message FunctionUsageStats {
66
repeated CounterWithTag storage_calls = 1;
7+
// TODO(ENG-7342): Remove after services are pushed with by_component version
78
optional uint64 storage_ingress_size = 2;
9+
repeated CounterWithComponent storage_ingress_size_by_component = 8;
10+
// TODO(ENG-7342): Remove after services are pushed with by_component version
811
optional uint64 storage_egress_size = 3;
12+
repeated CounterWithComponent storage_egress_size_by_component = 9;
913
repeated CounterWithTag database_ingress_size = 4;
1014
repeated CounterWithTag database_egress_size = 5;
1115
repeated CounterWithTag vector_ingress_size = 6;
@@ -17,3 +21,8 @@ message CounterWithTag {
1721
optional string table_name = 1;
1822
optional uint64 count = 2;
1923
}
24+
25+
message CounterWithComponent {
26+
optional string component_path = 1;
27+
optional uint64 count = 2;
28+
}

crates/usage_tracking/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ anyhow = { workspace = true }
1313
common = { path = "../common" }
1414
events = { path = "../events" }
1515
headers = { workspace = true }
16+
maplit = { workspace = true }
1617
metrics = { path = "../metrics" }
1718
parking_lot = { workspace = true, features = ["hardware-lock-elision"] }
1819
pb = { path = "../pb" }

0 commit comments

Comments
 (0)