Skip to content

Commit 5fe1acb

Browse files
committed
Add create network actions latency metric
1 parent 91ba951 commit 5fe1acb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

linera-core/src/chain_worker/state.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use std::{
1111
};
1212

1313
use futures::future::Either;
14+
#[cfg(with_metrics)]
15+
use linera_base::prometheus_util::MeasureLatency as _;
1416
use linera_base::{
1517
crypto::{CryptoHash, ValidatorPublicKey},
1618
data_types::{
@@ -48,6 +50,22 @@ use crate::{
4850
worker::{NetworkActions, Notification, Reason, WorkerError},
4951
};
5052

53+
#[cfg(with_metrics)]
54+
mod metrics {
55+
use std::sync::LazyLock;
56+
57+
use linera_base::prometheus_util::{exponential_bucket_latencies, register_histogram};
58+
use prometheus::Histogram;
59+
60+
pub static CREATE_NETWORK_ACTIONS_LATENCY: LazyLock<Histogram> = LazyLock::new(|| {
61+
register_histogram(
62+
"create_network_actions_latency",
63+
"Time (ms) to create network actions",
64+
exponential_bucket_latencies(10_000.0),
65+
)
66+
});
67+
}
68+
5169
/// The state of the chain worker.
5270
pub(crate) struct ChainWorkerState<StorageClient>
5371
where
@@ -419,6 +437,8 @@ where
419437
&self,
420438
old_round: Option<Round>,
421439
) -> Result<NetworkActions, WorkerError> {
440+
#[cfg(with_metrics)]
441+
let _latency = metrics::CREATE_NETWORK_ACTIONS_LATENCY.measure_latency();
422442
let mut heights_by_recipient = BTreeMap::<_, Vec<_>>::new();
423443
let mut targets = self.chain.nonempty_outbox_chain_ids();
424444
if let Some(tracked_chains) = self.tracked_chains.as_ref() {

0 commit comments

Comments
 (0)