diff --git a/crates/application/src/export_worker.rs b/crates/application/src/export_worker.rs index f9c05045..b429ef5d 100644 --- a/crates/application/src/export_worker.rs +++ b/crates/application/src/export_worker.rs @@ -652,6 +652,7 @@ impl ExportWorker { ExecutionId::new(), RequestId::new(), call_type, + true, usage.gather_user_stats(), ); Ok(()) diff --git a/crates/application/src/function_log.rs b/crates/application/src/function_log.rs index 01378cdf..d7078a75 100644 --- a/crates/application/src/function_log.rs +++ b/crates/application/src/function_log.rs @@ -624,6 +624,7 @@ impl FunctionExecutionLog { } else { CallType::UncachedQuery }, + outcome.result.is_ok(), usage_stats, ); aggregated @@ -733,6 +734,7 @@ impl FunctionExecutionLog { 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(), @@ -765,6 +767,7 @@ impl FunctionExecutionLog { context.execution_id.clone(), context.request_id.clone(), CallType::Mutation { occ_info: None }, + outcome.result.is_ok(), usage_stats, ); aggregated @@ -854,6 +857,7 @@ impl FunctionExecutionLog { duration: completion.execution_time, memory_in_mb: completion.memory_in_mb, }, + outcome.result.is_ok(), usage_stats, ); aggregated @@ -993,6 +997,7 @@ impl FunctionExecutionLog { memory_in_mb: outcome.memory_in_mb(), response_sha256, }, + result.clone().is_ok_and(|code| code.0.as_u16() < 400), usage_stats, ); aggregated diff --git a/crates/application/src/snapshot_import/mod.rs b/crates/application/src/snapshot_import/mod.rs index cc4d9fc2..7686ca80 100644 --- a/crates/application/src/snapshot_import/mod.rs +++ b/crates/application/src/snapshot_import/mod.rs @@ -938,6 +938,7 @@ async fn finalize_import( ExecutionId::new(), RequestId::new(), call_type, + true, usage.gather_user_stats(), ); diff --git a/crates/database/src/tests/usage_tracking.rs b/crates/database/src/tests/usage_tracking.rs index d37fb69a..41e6124e 100644 --- a/crates/database/src/tests/usage_tracking.rs +++ b/crates/database/src/tests/usage_tracking.rs @@ -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(), ); @@ -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(), ); @@ -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(), ); @@ -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(), ); @@ -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(), ); @@ -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(), ); @@ -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(), ); @@ -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(), ); @@ -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(), ); @@ -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(), ); @@ -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(); diff --git a/crates/events/src/usage.rs b/crates/events/src/usage.rs index 29f38c2b..9e842cf8 100644 --- a/crates/events/src/usage.rs +++ b/crates/events/src/usage.rs @@ -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, @@ -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(), @@ -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", @@ -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(), @@ -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", diff --git a/crates/usage_tracking/src/lib.rs b/crates/usage_tracking/src/lib.rs index 745bb795..3b2c65f1 100644 --- a/crates/usage_tracking/src/lib.rs +++ b/crates/usage_tracking/src/lib.rs @@ -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(); @@ -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(),