From e580ff7de26c3083e92c703a5e83c8643066c35c Mon Sep 17 00:00:00 2001 From: = Date: Mon, 26 May 2025 21:09:29 -0400 Subject: [PATCH] Remove reference to WORKER_METRICS inside db_metrics --- crates/core/src/db/db_metrics/data_size.rs | 31 ------------------- crates/core/src/host/host_controller.rs | 35 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/crates/core/src/db/db_metrics/data_size.rs b/crates/core/src/db/db_metrics/data_size.rs index 68b88a3a109..9c918d3ea8b 100644 --- a/crates/core/src/db/db_metrics/data_size.rs +++ b/crates/core/src/db/db_metrics/data_size.rs @@ -3,8 +3,6 @@ use prometheus::IntGaugeVec; use spacetimedb_lib::Identity; use spacetimedb_metrics::metrics_group; -use crate::worker_metrics::WORKER_METRICS; - metrics_group!( #[non_exhaustive] pub struct DbDataSize { @@ -42,32 +40,3 @@ metrics_group!( ); pub static DATA_SIZE_METRICS: Lazy = Lazy::new(DbDataSize::new); - -// Remove all gauges associated with a database. -// This is useful if a database is being deleted. -pub fn remove_database_gauges<'a, I>(db: &Identity, table_names: I) -where - I: IntoIterator, -{ - // Remove the per-table gauges. - for table_name in table_names { - let _ = DATA_SIZE_METRICS - .data_size_table_num_rows - .remove_label_values(db, table_name); - let _ = DATA_SIZE_METRICS - .data_size_table_bytes_used_by_rows - .remove_label_values(db, table_name); - let _ = DATA_SIZE_METRICS - .data_size_table_num_rows_in_indexes - .remove_label_values(db, table_name); - let _ = DATA_SIZE_METRICS - .data_size_table_bytes_used_by_index_keys - .remove_label_values(db, table_name); - } - // Remove the per-db gauges. - let _ = DATA_SIZE_METRICS.data_size_blob_store_num_blobs.remove_label_values(db); - let _ = DATA_SIZE_METRICS - .data_size_blob_store_bytes_used_by_blobs - .remove_label_values(db); - let _ = WORKER_METRICS.wasm_memory_bytes.remove_label_values(db); -} diff --git a/crates/core/src/host/host_controller.rs b/crates/core/src/host/host_controller.rs index 2e577ad6e8a..e5b1f538f27 100644 --- a/crates/core/src/host/host_controller.rs +++ b/crates/core/src/host/host_controller.rs @@ -4,15 +4,17 @@ use super::wasmtime::WasmtimeRuntime; use super::{Scheduler, UpdateDatabaseResult}; use crate::database_logger::DatabaseLogger; use crate::db::datastore::traits::Program; +use crate::db::db_metrics::data_size::DATA_SIZE_METRICS; use crate::db::db_metrics::DB_METRICS; use crate::db::relational_db::{self, DiskSizeFn, RelationalDB, Txdata}; -use crate::db::{self, db_metrics}; +use crate::db::{self}; use crate::energy::{EnergyMonitor, EnergyQuanta, NullEnergyMonitor}; use crate::messages::control_db::{Database, HostType}; use crate::module_host_context::ModuleCreationContext; use crate::replica_context::ReplicaContext; use crate::subscription::module_subscription_actor::ModuleSubscriptions; use crate::util::{asyncify, spawn_rayon}; +use crate::worker_metrics::WORKER_METRICS; use anyhow::{anyhow, ensure, Context}; use async_trait::async_trait; use durability::{Durability, EmptyHistory}; @@ -441,7 +443,7 @@ impl HostController { let module = host.module.borrow().clone(); module.exit().await; let table_names = module.info().module_def.tables().map(|t| t.name.deref()); - db_metrics::data_size::remove_database_gauges(&module.info().database_identity, table_names); + remove_database_gauges(&module.info().database_identity, table_names); } } @@ -981,3 +983,32 @@ pub async fn extract_schema(program_bytes: Box<[u8]>, host_type: HostType) -> an Ok(module_info.module_def) } + +// Remove all gauges associated with a database. +// This is useful if a database is being deleted. +pub fn remove_database_gauges<'a, I>(db: &Identity, table_names: I) +where + I: IntoIterator, +{ + // Remove the per-table gauges. + for table_name in table_names { + let _ = DATA_SIZE_METRICS + .data_size_table_num_rows + .remove_label_values(db, table_name); + let _ = DATA_SIZE_METRICS + .data_size_table_bytes_used_by_rows + .remove_label_values(db, table_name); + let _ = DATA_SIZE_METRICS + .data_size_table_num_rows_in_indexes + .remove_label_values(db, table_name); + let _ = DATA_SIZE_METRICS + .data_size_table_bytes_used_by_index_keys + .remove_label_values(db, table_name); + } + // Remove the per-db gauges. + let _ = DATA_SIZE_METRICS.data_size_blob_store_num_blobs.remove_label_values(db); + let _ = DATA_SIZE_METRICS + .data_size_blob_store_bytes_used_by_blobs + .remove_label_values(db); + let _ = WORKER_METRICS.wasm_memory_bytes.remove_label_values(db); +}