Skip to content

Commit

Permalink
Log sha256 on storage serving calls (#29596)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: ee27aeabe7c74874ae0dae7098f16064739993ff
  • Loading branch information
nipunn1313 authored and Convex, Inc. committed Sep 5, 2024
1 parent bc8009c commit c3c1be0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/application/src/export_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ impl<RT: Runtime> ExportWorker<RT> {
"snapshot_export",
file_storage_entry.storage_id.clone(),
content_type,
file_storage_entry.sha256.clone(),
)
.track_storage_egress_size(file_stream.content_length as u64);
zip_snapshot_upload
Expand Down
7 changes: 6 additions & 1 deletion crates/application/src/snapshot_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,12 @@ async fn import_storage_table<RT: Runtime>(
.map(|ct| ct.parse())
.transpose()?;
usage
.track_storage_call("snapshot_import", entry.storage_id, content_type)
.track_storage_call(
"snapshot_import",
entry.storage_id,
content_type,
entry.sha256,
)
.track_storage_ingress_size(file_size);
num_files += 1;
if let Some(import_id) = import_id {
Expand Down
1 change: 1 addition & 0 deletions crates/events/src/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub enum UsageEvent {
storage_id: String,
call: String,
content_type: Option<String>,
sha256: String,
},
/// Bandwidth from a storage call outside of a user function (e.g. snapshot
/// import/export).
Expand Down
7 changes: 4 additions & 3 deletions crates/file_storage/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<RT: Runtime> TransactionalFileStorage<RT> {
let FileStorageEntry {
storage_id,
storage_key,
sha256: _,
sha256,
size,
content_type,
} = file;
Expand All @@ -241,7 +241,7 @@ impl<RT: Runtime> TransactionalFileStorage<RT> {
let content_length = ContentLength(storage_get_stream.content_length as u64);

let call_tracker =
usage_tracker.track_storage_call("get range", storage_id, content_type.clone());
usage_tracker.track_storage_call("get range", storage_id, content_type.clone(), sha256);

Ok(FileRangeStream {
content_length,
Expand Down Expand Up @@ -406,6 +406,7 @@ impl<RT: Runtime> FileStorage<RT> {
.as_ref()
.map(|ct| ct.parse())
.transpose()?;
let sha256 = entry.sha256.clone();

// Start/Complete transaction after the slow upload process
// to avoid OCC risk.
Expand All @@ -419,7 +420,7 @@ impl<RT: Runtime> FileStorage<RT> {
.await?;

usage_tracker
.track_storage_call("store", storage_id, content_type)
.track_storage_call("store", storage_id, content_type, sha256)
.track_storage_ingress_size(size as u64);
Ok(virtual_id)
}
Expand Down
3 changes: 2 additions & 1 deletion crates/isolate/src/environment/action/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ impl<RT: Runtime> TaskExecutor<RT> {
.await?;
let storage_id = entry.storage_id.clone();
let size = entry.size;
let sha256 = entry.sha256.clone();
let storage_doc_id = self
.action_callbacks
.storage_store_file_entry(self.identity.clone(), self.component_id(), entry)
.await?;

self.usage_tracker
.track_storage_call("store", storage_id, content_type)
.track_storage_call("store", storage_id, content_type, sha256)
.track_storage_ingress_size(size as u64);

Ok(storage_doc_id)
Expand Down
9 changes: 8 additions & 1 deletion crates/usage_tracking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use pb::usage::{
CounterWithTag as CounterWithTagProto,
FunctionUsageStats as FunctionUsageStatsProto,
};
use value::heap_size::WithHeapSize;
use value::{
heap_size::WithHeapSize,
sha256::Sha256Digest,
};

mod metrics;

Expand Down Expand Up @@ -232,6 +235,7 @@ pub trait StorageUsageTracker: Send + Sync {
storage_api: &'static str,
storage_id: StorageUuid,
content_type: Option<ContentType>,
sha256: Sha256Digest,
) -> Box<dyn StorageCallTracker>;
}

Expand Down Expand Up @@ -280,6 +284,7 @@ impl StorageUsageTracker for UsageCounter {
storage_api: &'static str,
storage_id: StorageUuid,
content_type: Option<ContentType>,
sha256: Sha256Digest,
) -> Box<dyn StorageCallTracker> {
let execution_id = ExecutionId::new();
metrics::storage::log_storage_call();
Expand All @@ -290,6 +295,7 @@ impl StorageUsageTracker for UsageCounter {
storage_id: storage_id.to_string(),
call: storage_api.to_string(),
content_type: content_type.map(|c| c.to_string()),
sha256: sha256.as_hex(),
}]);

Box::new(IndependentStorageCallTracker::new(
Expand Down Expand Up @@ -467,6 +473,7 @@ impl StorageUsageTracker for FunctionUsageTracker {
storage_api: &'static str,
_storage_id: StorageUuid,
_content_type: Option<ContentType>,
_sha256: Sha256Digest,
) -> Box<dyn StorageCallTracker> {
let mut state = self.state.lock();
metrics::storage::log_storage_call();
Expand Down

0 comments on commit c3c1be0

Please sign in to comment.