From 7d8562d3030faae999beda24ec1acae0d6853953 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Thu, 26 Oct 2023 18:43:54 +0200 Subject: [PATCH] Prometheus log fixes (#1160) * Don't clone the whole certificate to log it. * Log actual fuel used per block, not per user action. --- Cargo.lock | 1 - examples/Cargo.lock | 1 - linera-chain/src/chain.rs | 14 ++++++++++++++ linera-chain/src/data_types.rs | 2 +- linera-core/src/worker.rs | 7 ++++--- linera-execution/Cargo.toml | 1 - linera-execution/src/execution.rs | 16 ---------------- 7 files changed, 19 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d19fee2e1a7..02dc8ee7275 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2835,7 +2835,6 @@ dependencies = [ "linera-wit-bindgen-host-wasmtime-rust", "lru", "once_cell", - "prometheus", "serde", "serde_bytes", "serde_json", diff --git a/examples/Cargo.lock b/examples/Cargo.lock index bdaf88091bd..a7b6e604c13 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -1700,7 +1700,6 @@ dependencies = [ "linera-wit-bindgen-host-wasmer-rust", "lru", "once_cell", - "prometheus", "serde", "serde_bytes", "serde_json", diff --git a/linera-chain/src/chain.rs b/linera-chain/src/chain.rs index ae50e8aaf37..26721966491 100644 --- a/linera-chain/src/chain.rs +++ b/linera-chain/src/chain.rs @@ -49,6 +49,7 @@ pub static NUM_BLOCKS_EXECUTED: Lazy = Lazy::new(|| { ) .expect("Counter creation should not fail") }); + pub static BLOCK_EXECUTION_LATENCY: Lazy = Lazy::new(|| { register_histogram_vec!( "block_execution_latency", @@ -59,6 +60,16 @@ pub static BLOCK_EXECUTION_LATENCY: Lazy = Lazy::new(|| { .expect("Counter creation should not fail") }); +pub static WASM_FUEL_USED_PER_BLOCK: Lazy = Lazy::new(|| { + register_histogram_vec!( + "wasm_fuel_used_per_block", + "Wasm fuel used per block", + // Can add labels here + &[] + ) + .expect("Counter can be created") +}); + /// A view accessing the state of a chain. #[derive(Debug, RootView, GraphQLView)] pub struct ChainStateView { @@ -563,6 +574,9 @@ where BLOCK_EXECUTION_LATENCY .with_label_values(&[]) .observe(start_time.elapsed().as_secs_f64()); + WASM_FUEL_USED_PER_BLOCK + .with_label_values(&[]) + .observe(used_fuel as f64); Ok(BlockExecutionOutcome { messages, message_counts, diff --git a/linera-chain/src/data_types.rs b/linera-chain/src/data_types.rs index 8292ab361ac..d8f522fa89f 100644 --- a/linera-chain/src/data_types.rs +++ b/linera-chain/src/data_types.rs @@ -561,7 +561,7 @@ impl CertificateValue { .map(|executed_block| &executed_block.block) } - pub fn to_log_str(&self) -> &str { + pub fn to_log_str(&self) -> &'static str { match self { CertificateValue::ConfirmedBlock { .. } => "confirmed_block", CertificateValue::ValidatedBlock { .. } => "validated_block", diff --git a/linera-core/src/worker.rs b/linera-core/src/worker.rs index 78ba7140127..723d06aa583 100644 --- a/linera-core/src/worker.rs +++ b/linera-core/src/worker.rs @@ -1091,7 +1091,8 @@ where } ); - let certificate_for_logging = certificate.clone(); + let round = certificate.round; + let log_str = certificate.value().to_log_str(); let mut duplicated = false; let (info, actions) = match certificate.value() { CertificateValue::ValidatedBlock { .. } => { @@ -1117,8 +1118,8 @@ where if !duplicated { NUM_ROUNDS_IN_CERTIFICATE - .with_label_values(&[certificate_for_logging.value().to_log_str()]) - .observe(certificate_for_logging.round.0 as f64); + .with_label_values(&[log_str]) + .observe(round.0 as f64); } Ok((info, actions)) } diff --git a/linera-execution/Cargo.toml b/linera-execution/Cargo.toml index 988f2b4f2c3..eeec5029b2b 100644 --- a/linera-execution/Cargo.toml +++ b/linera-execution/Cargo.toml @@ -35,7 +35,6 @@ linera-views = { workspace = true, features = ["metrics"] } linera-views-derive = { workspace = true } lru = { workspace = true } once_cell = { workspace = true } -prometheus = { workspace = true } serde = { workspace = true } serde_bytes = { workspace = true } serde_json = { workspace = true } diff --git a/linera-execution/src/execution.rs b/linera-execution/src/execution.rs index 28cbe7365a3..0dec138615d 100644 --- a/linera-execution/src/execution.rs +++ b/linera-execution/src/execution.rs @@ -20,8 +20,6 @@ use linera_views::{ views::{View, ViewError}, }; use linera_views_derive::CryptoHashView; -use once_cell::sync::Lazy; -use prometheus::{register_histogram_vec, HistogramVec}; #[cfg(any(test, feature = "test"))] use { @@ -32,16 +30,6 @@ use { std::sync::Arc, }; -pub static WASM_FUEL_USED_PER_BLOCK: Lazy = Lazy::new(|| { - register_histogram_vec!( - "wasm_fuel_used_per_block", - "Wasm fuel used per block", - // Can add labels here - &[] - ) - .expect("Counter can be created") -}); - /// A view accessing the execution state of a chain. #[derive(Debug, CryptoHashView)] pub struct ExecutionStateView { @@ -177,7 +165,6 @@ where action: UserAction<'_>, remaining_fuel: &mut u64, ) -> Result, ExecutionError> { - let initial_remaining_fuel = *remaining_fuel; // Try to load the application. This may fail if the corresponding // bytecode-publishing certificate doesn't exist yet on this validator. let description = self @@ -233,9 +220,6 @@ where // Set the authenticated signer to be used in outgoing messages. result.authenticated_signer = signer; *remaining_fuel = runtime.remaining_fuel(); - WASM_FUEL_USED_PER_BLOCK - .with_label_values(&[]) - .observe((initial_remaining_fuel - *remaining_fuel) as f64); // Check that applications were correctly stacked and unstacked. assert_eq!(applications.len(), 1);