Skip to content

Commit

Permalink
Switch position of expect statement for metrics. (#2861)
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuDutSik authored Nov 11, 2024
1 parent d8da3a4 commit 0b291d2
Show file tree
Hide file tree
Showing 24 changed files with 29 additions and 124 deletions.
2 changes: 0 additions & 2 deletions linera-base/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,6 @@ static BYTECODE_COMPRESSION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
1.0, 2.5, 5.0, 10.0,
]),
)
.expect("Histogram creation should not fail")
});

/// The time it takes to decompress a bytecode.
Expand All @@ -1236,7 +1235,6 @@ static BYTECODE_DECOMPRESSION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(||
1.0, 2.5, 5.0, 10.0,
]),
)
.expect("Histogram creation should not fail")
});

#[cfg(test)]
Expand Down
12 changes: 6 additions & 6 deletions linera-base/src/prometheus_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//! This module defines util functions for interacting with Prometheus (logging metrics, etc)

use prometheus::{
histogram_opts, register_histogram_vec, register_int_counter_vec, Error, HistogramVec,
IntCounterVec, Opts,
histogram_opts, register_histogram_vec, register_int_counter_vec, HistogramVec, IntCounterVec,
Opts,
};

use crate::time::Instant;
Expand All @@ -17,9 +17,9 @@ pub fn register_int_counter_vec(
name: &str,
description: &str,
label_names: &[&str],
) -> Result<IntCounterVec, Error> {
) -> IntCounterVec {
let counter_opts = Opts::new(name, description).namespace(LINERA_NAMESPACE);
register_int_counter_vec!(counter_opts, label_names)
register_int_counter_vec!(counter_opts, label_names).expect("IntCounter can be created")
}

/// Wrapper arount prometheus register_histogram_vec! macro which also sets the linera namespace
Expand All @@ -28,14 +28,14 @@ pub fn register_histogram_vec(
description: &str,
label_names: &[&str],
buckets: Option<Vec<f64>>,
) -> Result<HistogramVec, Error> {
) -> HistogramVec {
let histogram_opts = if let Some(buckets) = buckets {
histogram_opts!(name, description, buckets).namespace(LINERA_NAMESPACE)
} else {
histogram_opts!(name, description).namespace(LINERA_NAMESPACE)
};

register_histogram_vec!(histogram_opts, label_names)
register_histogram_vec!(histogram_opts, label_names).expect("Histogram can be created")
}

/// A guard for an active latency measurement.
Expand Down
9 changes: 0 additions & 9 deletions linera-chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ static NUM_BLOCKS_EXECUTED: LazyLock<IntCounterVec> = LazyLock::new(|| {
"Number of blocks executed",
&[],
)
.expect("Counter creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -80,7 +79,6 @@ static BLOCK_EXECUTION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
1.0, 2.5, 5.0, 10.0, 25.0, 50.0,
]),
)
.expect("Histogram creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -94,7 +92,6 @@ static MESSAGE_EXECUTION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
1.0, 2.5,
]),
)
.expect("Histogram creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -108,7 +105,6 @@ static OPERATION_EXECUTION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
1.0, 2.5,
]),
)
.expect("Histogram creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -122,7 +118,6 @@ static WASM_FUEL_USED_PER_BLOCK: LazyLock<HistogramVec> = LazyLock::new(|| {
100_000.0, 250_000.0, 500_000.0,
]),
)
.expect("Histogram creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -133,7 +128,6 @@ static WASM_NUM_READS_PER_BLOCK: LazyLock<HistogramVec> = LazyLock::new(|| {
&[],
Some(vec![0.5, 1.0, 2.0, 4.0, 8.0, 15.0, 30.0, 50.0, 100.0]),
)
.expect("Histogram creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -160,7 +154,6 @@ static WASM_BYTES_READ_PER_BLOCK: LazyLock<HistogramVec> = LazyLock::new(|| {
8_388_608.0,
]),
)
.expect("Histogram creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -187,7 +180,6 @@ static WASM_BYTES_WRITTEN_PER_BLOCK: LazyLock<HistogramVec> = LazyLock::new(|| {
8_388_608.0,
]),
)
.expect("Histogram creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -200,7 +192,6 @@ static STATE_HASH_COMPUTATION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(||
0.001, 0.003, 0.01, 0.03, 0.1, 0.2, 0.3, 0.4, 0.5, 0.75, 1.0, 2.0, 5.0,
]),
)
.expect("Histogram can be created")
});

/// The BCS-serialized size of an empty `ExecutedBlock`.
Expand Down
5 changes: 0 additions & 5 deletions linera-core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ mod metrics {
25.0, 50.0, 100.0, 250.0, 500.0,
]),
)
.expect("Histogram creation should not fail")
});

pub static PREPARE_CHAIN_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
Expand All @@ -115,7 +114,6 @@ mod metrics {
25.0, 50.0, 100.0, 250.0, 500.0,
]),
)
.expect("Histogram creation should not fail")
});

pub static SYNCHRONIZE_CHAIN_STATE_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
Expand All @@ -128,7 +126,6 @@ mod metrics {
25.0, 50.0, 100.0, 250.0, 500.0,
]),
)
.expect("Histogram creation should not fail")
});

pub static EXECUTE_BLOCK_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
Expand All @@ -141,7 +138,6 @@ mod metrics {
25.0, 50.0, 100.0, 250.0, 500.0,
]),
)
.expect("Histogram creation should not fail")
});

pub static FIND_RECEIVED_CERTIFICATES_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
Expand All @@ -154,7 +150,6 @@ mod metrics {
25.0, 50.0, 100.0, 250.0, 500.0,
]),
)
.expect("Histogram creation should not fail")
});
}

Expand Down
2 changes: 0 additions & 2 deletions linera-core/src/value_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ static CACHE_HIT_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| {
"Cache hits in `ValueCache`",
&["key_type", "value_type"],
)
.expect("Counter creation should not fail")
});

/// A counter metric for the number of cache misses in the [`ValueCache`].
Expand All @@ -42,7 +41,6 @@ static CACHE_MISS_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| {
"Cache misses in `ValueCache`",
&["key_type", "value_type"],
)
.expect("Counter creation should not fail")
});

/// A least-recently used cache of a value.
Expand Down
4 changes: 0 additions & 4 deletions linera-core/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ static NUM_ROUNDS_IN_CERTIFICATE: LazyLock<HistogramVec> = LazyLock::new(|| {
0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 15.0, 25.0, 50.0,
]),
)
.expect("Counter creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -77,19 +76,16 @@ static NUM_ROUNDS_IN_BLOCK_PROPOSAL: LazyLock<HistogramVec> = LazyLock::new(|| {
0.5, 1.0, 2.0, 3.0, 4.0, 6.0, 8.0, 10.0, 15.0, 25.0, 50.0,
]),
)
.expect("Counter creation should not fail")
});

#[cfg(with_metrics)]
static TRANSACTION_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| {
prometheus_util::register_int_counter_vec("transaction_count", "Transaction count", &[])
.expect("Counter creation should not fail")
});

#[cfg(with_metrics)]
static NUM_BLOCKS: LazyLock<IntCounterVec> = LazyLock::new(|| {
prometheus_util::register_int_counter_vec("num_blocks", "Number of blocks added to chains", &[])
.expect("Counter creation should not fail")
});

/// Instruct the networking layer to send cross-chain requests and/or push notifications.
Expand Down
2 changes: 0 additions & 2 deletions linera-execution/src/execution_state_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ static LOAD_CONTRACT_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
100.0, 250.0,
]),
)
.expect("Histogram creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -56,7 +55,6 @@ static LOAD_SERVICE_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
100.0, 250.0,
]),
)
.expect("Histogram creation should not fail")
});

pub(crate) type ExecutionStateSender = mpsc::UnboundedSender<ExecutionRequest>;
Expand Down
1 change: 0 additions & 1 deletion linera-execution/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ static OPEN_CHAIN_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| {
"The number of times the `OpenChain` operation was executed",
&[],
)
.expect("Counter creation should not fail")
});

/// A view accessing the execution state of the system of a chain.
Expand Down
2 changes: 0 additions & 2 deletions linera-execution/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ static CONTRACT_INSTANTIATION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(||
0.000_1, 0.000_3, 0.001, 0.002_5, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0,
]),
)
.expect("Histogram creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -66,7 +65,6 @@ static SERVICE_INSTANTIATION_LATENCY: LazyLock<HistogramVec> = LazyLock::new(||
0.000_1, 0.000_3, 0.001, 0.002_5, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0,
]),
)
.expect("Histogram creation should not fail")
});

/// A user contract in a compiled WebAssembly module.
Expand Down
5 changes: 0 additions & 5 deletions linera-rpc/src/grpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ static SERVER_REQUEST_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
&[],
Some(vec![0.5, 1.0, 2.5, 5.0, 10.0, 25.0, 50.0]),
)
.expect("Counter creation should not fail")
});

#[cfg(with_metrics)]
static SERVER_REQUEST_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| {
prometheus_util::register_int_counter_vec("server_request_count", "Server request count", &[])
.expect("Counter creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -77,7 +75,6 @@ static SERVER_REQUEST_SUCCESS: LazyLock<IntCounterVec> = LazyLock::new(|| {
"Server request success",
&["method_name"],
)
.expect("Counter creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -87,7 +84,6 @@ static SERVER_REQUEST_ERROR: LazyLock<IntCounterVec> = LazyLock::new(|| {
"Server request error",
&["method_name"],
)
.expect("Counter creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -98,7 +94,6 @@ static SERVER_REQUEST_LATENCY_PER_REQUEST_TYPE: LazyLock<HistogramVec> = LazyLoc
&["method_name"],
Some(vec![0.5, 1.0, 2.5, 5.0, 10.0, 25.0, 50.0]),
)
.expect("Counter creation should not fail")
});

#[derive(Clone)]
Expand Down
4 changes: 0 additions & 4 deletions linera-service/src/proxy/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,11 @@ static PROXY_REQUEST_LATENCY: LazyLock<HistogramVec> = LazyLock::new(|| {
50.0, 100.0, 200.0, 300.0, 400.0,
]),
)
.expect("Counter creation should not fail")
});

#[cfg(with_metrics)]
static PROXY_REQUEST_COUNT: LazyLock<IntCounterVec> = LazyLock::new(|| {
prometheus_util::register_int_counter_vec("proxy_request_count", "Proxy request count", &[])
.expect("Counter creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -88,7 +86,6 @@ static PROXY_REQUEST_SUCCESS: LazyLock<IntCounterVec> = LazyLock::new(|| {
"Proxy request success",
&["method_name"],
)
.expect("Counter creation should not fail")
});

#[cfg(with_metrics)]
Expand All @@ -98,7 +95,6 @@ static PROXY_REQUEST_ERROR: LazyLock<IntCounterVec> = LazyLock::new(|| {
"Proxy request error",
&["method_name"],
)
.expect("Counter creation should not fail")
});

#[derive(Clone)]
Expand Down
Loading

0 comments on commit 0b291d2

Please sign in to comment.