Skip to content

Commit

Permalink
Include whether a function succeded or failed in usage events (#31735)
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 8d3f44f56d36f7cd37c846f5c88ecb8814452069
  • Loading branch information
atrakh authored and Convex, Inc. committed Nov 23, 2024
1 parent f178fff commit bb60951
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 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 @@ -652,6 +652,7 @@ impl<RT: Runtime> ExportWorker<RT> {
ExecutionId::new(),
RequestId::new(),
call_type,
true,
usage.gather_user_stats(),
);
Ok(())
Expand Down
5 changes: 5 additions & 0 deletions crates/application/src/function_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ impl<RT: Runtime> FunctionExecutionLog<RT> {
} else {
CallType::UncachedQuery
},
outcome.result.is_ok(),
usage_stats,
);
aggregated
Expand Down Expand Up @@ -733,6 +734,7 @@ impl<RT: Runtime> FunctionExecutionLog<RT> {
retry_count,
}),
},
false,
// This track call is only to keep track of OCC error metadata.
// Usage states across all retries are tracked in the `log_mutation` call.
FunctionUsageStats::default(),
Expand Down Expand Up @@ -765,6 +767,7 @@ impl<RT: Runtime> FunctionExecutionLog<RT> {
context.execution_id.clone(),
context.request_id.clone(),
CallType::Mutation { occ_info: None },
outcome.result.is_ok(),
usage_stats,
);
aggregated
Expand Down Expand Up @@ -854,6 +857,7 @@ impl<RT: Runtime> FunctionExecutionLog<RT> {
duration: completion.execution_time,
memory_in_mb: completion.memory_in_mb,
},
outcome.result.is_ok(),
usage_stats,
);
aggregated
Expand Down Expand Up @@ -993,6 +997,7 @@ impl<RT: Runtime> FunctionExecutionLog<RT> {
memory_in_mb: outcome.memory_in_mb(),
response_sha256,
},
result.clone().is_ok_and(|code| code.0.as_u16() < 400),
usage_stats,
);
aggregated
Expand Down
1 change: 1 addition & 0 deletions crates/application/src/snapshot_import/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,7 @@ async fn finalize_import<RT: Runtime>(
ExecutionId::new(),
RequestId::new(),
call_type,
true,
usage.gather_user_stats(),
);

Expand Down
11 changes: 11 additions & 0 deletions crates/database/src/tests/usage_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ async fn vector_insert_with_no_index_does_not_count_usage(rt: TestRuntime) -> an
duration: Duration::from_secs(10),
memory_in_mb: 10,
},
true,
tx_usage.gather_user_stats(),
);

Expand All @@ -109,6 +110,7 @@ async fn vector_insert_counts_usage_for_backfilling_indexes(rt: TestRuntime) ->
ExecutionId::new(),
RequestId::new(),
CallType::Mutation { occ_info: None },
true,
tx_usage.gather_user_stats(),
);

Expand Down Expand Up @@ -147,6 +149,7 @@ async fn vector_insert_counts_usage_for_enabled_indexes(rt: TestRuntime) -> anyh
duration: Duration::from_secs(10),
memory_in_mb: 10,
},
true,
tx_usage.gather_user_stats(),
);

Expand Down Expand Up @@ -181,6 +184,7 @@ async fn vectors_in_segment_count_as_usage(rt: TestRuntime) -> anyhow::Result<()
duration: Duration::from_secs(10),
memory_in_mb: 10,
},
true,
tx_usage.gather_user_stats(),
);

Expand Down Expand Up @@ -236,6 +240,7 @@ async fn vector_query_counts_bandwidth(rt: TestRuntime) -> anyhow::Result<()> {
duration: Duration::from_secs(10),
memory_in_mb: 10,
},
true,
tx_usage.gather_user_stats(),
);

Expand Down Expand Up @@ -275,6 +280,7 @@ async fn test_usage_tracking_basic_insert_and_get(rt: TestRuntime) -> anyhow::Re
ExecutionId::new(),
RequestId::new(),
CallType::Mutation { occ_info: None },
true,
tx_usage.gather_user_stats(),
);

Expand All @@ -301,6 +307,7 @@ async fn test_usage_tracking_basic_insert_and_get(rt: TestRuntime) -> anyhow::Re
ExecutionId::new(),
RequestId::new(),
CallType::Mutation { occ_info: None },
true,
tx_usage.gather_user_stats(),
);

Expand Down Expand Up @@ -344,6 +351,7 @@ async fn test_usage_tracking_insert_with_index(rt: TestRuntime) -> anyhow::Resul
ExecutionId::new(),
RequestId::new(),
CallType::Mutation { occ_info: None },
true,
tx_usage.gather_user_stats(),
);

Expand All @@ -369,6 +377,7 @@ async fn test_usage_tracking_insert_with_index(rt: TestRuntime) -> anyhow::Resul
ExecutionId::new(),
RequestId::new(),
CallType::Mutation { occ_info: None },
true,
tx_usage.gather_user_stats(),
);

Expand Down Expand Up @@ -397,6 +406,7 @@ async fn test_usage_tracking_insert_with_index(rt: TestRuntime) -> anyhow::Resul
ExecutionId::new(),
RequestId::new(),
CallType::Mutation { occ_info: None },
true,
tx_usage.gather_user_stats(),
);

Expand Down Expand Up @@ -429,6 +439,7 @@ async fn http_action_counts_compute(rt: TestRuntime) -> anyhow::Result<()> {
memory_in_mb: 100,
response_sha256: Sha256Digest::from([0; 32]),
},
true,
tx_usage.gather_user_stats(),
);
let stats = test_usage_logger.collect();
Expand Down
6 changes: 6 additions & 0 deletions crates/events/src/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub struct FunctionCallUsageFields {
pub id: String,
/// The RequestId of a particular UDF
pub request_id: String,
/// Whether the request succeeded or failed
pub status: String,
/// The path of a component. Uniquely identifies a component in a
/// project.
pub component_path: Option<String>,
Expand Down Expand Up @@ -211,6 +213,7 @@ mod tests {
fields: FunctionCallUsageFields {
id: "123".to_string(),
request_id: "request_id".to_string(),
status: "success".to_string(),
component_path: Some("component/path".to_string()),
udf_id: "udf_id".to_string(),
udf_id_type: "http".to_string(),
Expand All @@ -231,6 +234,7 @@ mod tests {
let expected_output = json!({"FunctionCall": {
"id": "123",
"request_id": "request_id",
"status": "success",
"component_path": "component/path",
"udf_id": "udf_id",
"udf_id_type": "http",
Expand All @@ -256,6 +260,7 @@ mod tests {
fields: FunctionCallUsageFields {
id: "123".to_string(),
request_id: "request_id".to_string(),
status: "success".to_string(),
component_path: Some("component/path".to_string()),
udf_id: "udf_id".to_string(),
udf_id_type: "http".to_string(),
Expand All @@ -276,6 +281,7 @@ mod tests {
let expected_output = json!({"FunctionCall": {
"id": "123",
"request_id": "request_id",
"status": "success",
"component_path": "component/path",
"udf_id": "udf_id",
"udf_id_type": "http",
Expand Down
2 changes: 2 additions & 0 deletions crates/usage_tracking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ impl UsageCounter {
execution_id: ExecutionId,
request_id: RequestId,
call_type: CallType,
success: bool,
stats: FunctionUsageStats,
) {
let mut usage_metrics = Vec::new();
Expand All @@ -221,6 +222,7 @@ impl UsageCounter {
fields: FunctionCallUsageFields {
id: execution_id.to_string(),
request_id: request_id.to_string(),
status: if success { "success" } else { "failure" }.to_string(),
component_path,
udf_id,
udf_id_type: udf_id_type.to_string(),
Expand Down

0 comments on commit bb60951

Please sign in to comment.