From c5c372e23ad93d04d8bd836073ea2ae821f2771f Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Mon, 10 Nov 2025 11:58:16 +0100 Subject: [PATCH] Change spacetime_worker_wasm_instance_errors_total metric's labels There are two purpose for introducing the changes in this commit: 1. Decrease the cardinality of the metric, as caller id and connection id combination would result in way too many combinations 2. Add a database_identity label, which is much more useful for the metric --- .../src/host/wasm_common/module_host_actor.rs | 35 ++++--------------- crates/core/src/worker_metrics/mod.rs | 4 +-- 2 files changed, 8 insertions(+), 31 deletions(-) diff --git a/crates/core/src/host/wasm_common/module_host_actor.rs b/crates/core/src/host/wasm_common/module_host_actor.rs index 30d5819a303..8b0a2b20756 100644 --- a/crates/core/src/host/wasm_common/module_host_actor.rs +++ b/crates/core/src/host/wasm_common/module_host_actor.rs @@ -575,12 +575,7 @@ impl InstanceCommon { WORKER_METRICS .wasm_instance_errors - .with_label_values( - &caller_identity, - &self.info.module_hash, - &caller_connection_id, - procedure_name, - ) + .with_label_values(&self.info.database_identity, &self.info.module_hash, procedure_name) .inc(); // TODO(procedure-energy): @@ -686,12 +681,7 @@ impl InstanceCommon { Err(ExecutionError::Recoverable(err) | ExecutionError::Trap(err)) => { inst.log_traceback("reducer", reducer_name, &err); - self.handle_outer_error( - &result.stats.energy, - &caller_identity, - &Some(caller_connection_id), - reducer_name, - ) + self.handle_outer_error(&result.stats.energy, reducer_name) } Err(ExecutionError::User(err)) => { log_reducer_error(inst.replica_ctx(), timestamp, reducer_name, &err); @@ -766,21 +756,10 @@ impl InstanceCommon { (res, trapped) } - fn handle_outer_error( - &mut self, - energy: &EnergyStats, - caller_identity: &Identity, - caller_connection_id: &Option, - reducer_name: &str, - ) -> EventStatus { + fn handle_outer_error(&mut self, energy: &EnergyStats, reducer_name: &str) -> EventStatus { WORKER_METRICS .wasm_instance_errors - .with_label_values( - caller_identity, - &self.info.module_hash, - &caller_connection_id.unwrap_or(ConnectionId::ZERO), - reducer_name, - ) + .with_label_values(&self.info.database_identity, &self.info.module_hash, reducer_name) .inc(); if energy.remaining.get() == 0 { @@ -903,14 +882,12 @@ impl InstanceCommon { let outcome = match (result.call_result, sender) { (Err(ExecutionError::Recoverable(err) | ExecutionError::Trap(err)), _) => { inst.log_traceback("view", &view_name, &err); - self.handle_outer_error(&result.stats.energy, &caller, &None, &view_name) - .into() + self.handle_outer_error(&result.stats.energy, &view_name).into() } // TODO: maybe do something else with user errors? (Err(ExecutionError::User(err)), _) => { inst.log_traceback("view", &view_name, &anyhow::anyhow!(err)); - self.handle_outer_error(&result.stats.energy, &caller, &None, &view_name) - .into() + self.handle_outer_error(&result.stats.energy, &view_name).into() } // Materialize anonymous view (Ok(bytes), None) => { diff --git a/crates/core/src/worker_metrics/mod.rs b/crates/core/src/worker_metrics/mod.rs index cf1ec661a23..0f20a12d632 100644 --- a/crates/core/src/worker_metrics/mod.rs +++ b/crates/core/src/worker_metrics/mod.rs @@ -3,7 +3,7 @@ use crate::messages::control_db::HostType; use once_cell::sync::Lazy; use prometheus::{GaugeVec, HistogramVec, IntCounterVec, IntGaugeVec}; use spacetimedb_datastore::execution_context::WorkloadType; -use spacetimedb_lib::{ConnectionId, Identity}; +use spacetimedb_lib::Identity; use spacetimedb_metrics::metrics_group; use spacetimedb_sats::memory_usage::MemoryUsage; use spacetimedb_table::page_pool::PagePool; @@ -243,7 +243,7 @@ metrics_group!( #[name = spacetime_worker_wasm_instance_errors_total] #[help = "The number of fatal WASM instance errors, such as reducer panics."] - #[labels(caller_identity: Identity, module_hash: Hash, caller_connection_id: ConnectionId, reducer_symbol: str)] + #[labels(database_identity: Identity, module_hash: Hash, reducer_symbol: str)] pub wasm_instance_errors: IntCounterVec, #[name = spacetime_worker_wasm_memory_bytes]