Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions engine/src/invocation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ impl InvocationHandler {
acc.invocations_total.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
acc.invocations_success.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
acc.increment_function(&function_id);
if !crate::workers::telemetry::is_iii_standard_function_id(&function_id) {
let _ = acc.first_user_success_fn.set(function_id.clone());
}

let _ = invocation.sender.send(Ok(result));
}
Expand Down Expand Up @@ -190,6 +193,9 @@ impl InvocationHandler {
acc.invocations_total.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
acc.invocations_error.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
acc.increment_function(&function_id);
if !crate::workers::telemetry::is_iii_standard_function_id(&function_id) {
let _ = acc.first_user_failure_fn.set(function_id.clone());
}

let _ = invocation.sender.send(Err(error));
}
Expand Down
48 changes: 48 additions & 0 deletions engine/src/workers/observability/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ pub struct MetricsAccumulator {
pub invocations_by_function: dashmap::DashMap<String, u64>,
pub workers_spawns: std::sync::atomic::AtomicU64,
pub workers_deaths: std::sync::atomic::AtomicU64,
/// Set once on the first successful invocation of a user-defined function.
pub first_user_success_fn: std::sync::OnceLock<String>,
/// Set once on the first failed invocation of a user-defined function.
pub first_user_failure_fn: std::sync::OnceLock<String>,
}

impl Default for MetricsAccumulator {
Expand All @@ -366,6 +370,8 @@ impl Default for MetricsAccumulator {
invocations_by_function: dashmap::DashMap::new(),
workers_spawns: std::sync::atomic::AtomicU64::new(0),
workers_deaths: std::sync::atomic::AtomicU64::new(0),
first_user_success_fn: std::sync::OnceLock::new(),
first_user_failure_fn: std::sync::OnceLock::new(),
}
}
}
Expand Down Expand Up @@ -3449,6 +3455,48 @@ mod tests {
assert_eq!(counts.get("func_y"), Some(&1));
}

#[test]
fn test_first_user_success_fn_set_once() {
let acc = MetricsAccumulator::default();
assert!(acc.first_user_success_fn.get().is_none());

let _ = acc.first_user_success_fn.set("math::add".to_string());
assert_eq!(acc.first_user_success_fn.get(), Some(&"math::add".to_string()));

let _ = acc.first_user_success_fn.set("math::multiply".to_string());
assert_eq!(
acc.first_user_success_fn.get(),
Some(&"math::add".to_string()),
"OnceLock should retain the first value"
);
}

#[test]
fn test_first_user_failure_fn_set_once() {
let acc = MetricsAccumulator::default();
assert!(acc.first_user_failure_fn.get().is_none());

let _ = acc.first_user_failure_fn.set("math::add".to_string());
assert_eq!(acc.first_user_failure_fn.get(), Some(&"math::add".to_string()));

let _ = acc.first_user_failure_fn.set("other::fn".to_string());
assert_eq!(
acc.first_user_failure_fn.get(),
Some(&"math::add".to_string()),
"OnceLock should retain the first value"
);
}

#[test]
fn test_first_user_fns_independent() {
let acc = MetricsAccumulator::default();
let _ = acc.first_user_success_fn.set("math::add".to_string());
let _ = acc.first_user_failure_fn.set("math::divide".to_string());

assert_eq!(acc.first_user_success_fn.get(), Some(&"math::add".to_string()));
assert_eq!(acc.first_user_failure_fn.get(), Some(&"math::divide".to_string()));
}

// =========================================================================
// TimeIndexedMetricStorage len / is_empty
// =========================================================================
Expand Down
Loading
Loading