feat: add payload build metrics (#2367)

This commit is contained in:
Matthias Seitz
2023-04-24 20:29:29 +02:00
committed by GitHub
parent 1912bd43cd
commit 4e95f6e7c4
5 changed files with 47 additions and 2 deletions

2
Cargo.lock generated
View File

@ -4641,6 +4641,8 @@ version = "0.1.0"
dependencies = [ dependencies = [
"futures-core", "futures-core",
"futures-util", "futures-util",
"metrics",
"reth-metrics-derive",
"reth-payload-builder", "reth-payload-builder",
"reth-primitives", "reth-primitives",
"reth-provider", "reth-provider",

View File

@ -20,6 +20,10 @@ reth-tasks = { path = "../../tasks" }
## ethereum ## ethereum
revm = { version = "3" } revm = { version = "3" }
# metrics
metrics = "0.20.1"
reth-metrics-derive = { path = "../../metrics/metrics-derive" }
## async ## async
tokio = { version = "1", features = ["sync", "time"] } tokio = { version = "1", features = ["sync", "time"] }
futures-core = "0.3" futures-core = "0.3"

View File

@ -7,6 +7,7 @@
//! reth basic payload job generator //! reth basic payload job generator
use crate::metrics::PayloadBuilderMetrics;
use futures_core::{ready, Stream}; use futures_core::{ready, Stream};
use futures_util::FutureExt; use futures_util::FutureExt;
use reth_payload_builder::{ use reth_payload_builder::{
@ -47,6 +48,8 @@ use tokio::{
}; };
use tracing::trace; use tracing::trace;
mod metrics;
/// The [PayloadJobGenerator] that creates [BasicPayloadJob]s. /// The [PayloadJobGenerator] that creates [BasicPayloadJob]s.
pub struct BasicPayloadJobGenerator<Client, Pool, Tasks> { pub struct BasicPayloadJobGenerator<Client, Pool, Tasks> {
/// The client that can interact with the chain. /// The client that can interact with the chain.
@ -143,6 +146,7 @@ where
best_payload: None, best_payload: None,
pending_block: None, pending_block: None,
payload_task_guard: self.payload_task_guard.clone(), payload_task_guard: self.payload_task_guard.clone(),
metrics: Default::default(),
}) })
} }
} }
@ -252,6 +256,8 @@ pub struct BasicPayloadJob<Client, Pool, Tasks> {
pending_block: Option<PendingPayload>, pending_block: Option<PendingPayload>,
/// Restricts how many generator tasks can be executed at once. /// Restricts how many generator tasks can be executed at once.
payload_task_guard: PayloadTaskGuard, payload_task_guard: PayloadTaskGuard,
/// metrics for this type
metrics: PayloadBuilderMetrics,
} }
impl<Client, Pool, Tasks> Stream for BasicPayloadJob<Client, Pool, Tasks> impl<Client, Pool, Tasks> Stream for BasicPayloadJob<Client, Pool, Tasks>
@ -283,6 +289,7 @@ where
let guard = this.payload_task_guard.clone(); let guard = this.payload_task_guard.clone();
let payload_config = this.config.clone(); let payload_config = this.config.clone();
let best_payload = this.best_payload.clone(); let best_payload = this.best_payload.clone();
this.metrics.inc_initiated_payload_builds();
this.executor.spawn_blocking(Box::pin(async move { this.executor.spawn_blocking(Box::pin(async move {
// acquire the permit for executing the task // acquire the permit for executing the task
let _permit = guard.0.acquire().await; let _permit = guard.0.acquire().await;
@ -311,6 +318,7 @@ where
} }
} }
Poll::Ready(Err(err)) => { Poll::Ready(Err(err)) => {
this.metrics.inc_failed_payload_builds();
this.interval.reset(); this.interval.reset();
return Poll::Ready(Some(Err(err))) return Poll::Ready(Some(Err(err)))
} }
@ -345,6 +353,7 @@ where
// Note: it is assumed that this is unlikely to happen, as the payload job is started right // Note: it is assumed that this is unlikely to happen, as the payload job is started right
// away and the first full block should have been built by the time CL is requesting the // away and the first full block should have been built by the time CL is requesting the
// payload. // payload.
self.metrics.inc_requested_empty_payload();
build_empty_payload(&self.client, self.config.clone()).map(Arc::new) build_empty_payload(&self.client, self.config.clone()).map(Arc::new)
} }
} }

View File

@ -0,0 +1,30 @@
//! Metrics for the payload builder impl
use metrics::Counter;
use reth_metrics_derive::Metrics;
/// Transaction pool metrics
#[derive(Metrics)]
#[metrics(scope = "payloads")]
pub(crate) struct PayloadBuilderMetrics {
/// Number of active jobs
pub(crate) requested_empty_payload: Counter,
/// Total number of initiated payload build attempts
pub(crate) initiated_payload_builds: Counter,
/// Total number of failed payload build attempts
pub(crate) failed_payload_builds: Counter,
}
impl PayloadBuilderMetrics {
pub(crate) fn inc_requested_empty_payload(&self) {
self.requested_empty_payload.increment(1);
}
pub(crate) fn inc_initiated_payload_builds(&self) {
self.initiated_payload_builds.increment(1);
}
pub(crate) fn inc_failed_payload_builds(&self) {
self.failed_payload_builds.increment(1);
}
}

View File

@ -1,9 +1,9 @@
//! Payloadbuild service metrics. //! Payload builder service metrics.
use metrics::{Counter, Gauge}; use metrics::{Counter, Gauge};
use reth_metrics_derive::Metrics; use reth_metrics_derive::Metrics;
/// Transaction pool metrics /// Payload builder service metrics
#[derive(Metrics)] #[derive(Metrics)]
#[metrics(scope = "payloads")] #[metrics(scope = "payloads")]
pub(crate) struct PayloadBuilderServiceMetrics { pub(crate) struct PayloadBuilderServiceMetrics {