Skip to content

Commit

Permalink
Prometheus log fixes (linera-io#1160)
Browse files Browse the repository at this point in the history
* Don't clone the whole certificate to log it.

* Log actual fuel used per block, not per user action.
  • Loading branch information
afck authored Oct 26, 2023
1 parent 09e1ce8 commit 7d8562d
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 23 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions linera-chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub static NUM_BLOCKS_EXECUTED: Lazy<IntCounterVec> = Lazy::new(|| {
)
.expect("Counter creation should not fail")
});

pub static BLOCK_EXECUTION_LATENCY: Lazy<HistogramVec> = Lazy::new(|| {
register_histogram_vec!(
"block_execution_latency",
Expand All @@ -59,6 +60,16 @@ pub static BLOCK_EXECUTION_LATENCY: Lazy<HistogramVec> = Lazy::new(|| {
.expect("Counter creation should not fail")
});

pub static WASM_FUEL_USED_PER_BLOCK: Lazy<HistogramVec> = 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<C> {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion linera-chain/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions linera-core/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 { .. } => {
Expand All @@ -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))
}
Expand Down
1 change: 0 additions & 1 deletion linera-execution/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
16 changes: 0 additions & 16 deletions linera-execution/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -32,16 +30,6 @@ use {
std::sync::Arc,
};

pub static WASM_FUEL_USED_PER_BLOCK: Lazy<HistogramVec> = 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<C> {
Expand Down Expand Up @@ -177,7 +165,6 @@ where
action: UserAction<'_>,
remaining_fuel: &mut u64,
) -> Result<Vec<ExecutionResult>, 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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7d8562d

Please sign in to comment.