From 06fec41e5ccb1ce164596481dcd7f39b0f7878b3 Mon Sep 17 00:00:00 2001 From: Chris Manghane Date: Thu, 20 Mar 2025 21:39:29 -0600 Subject: [PATCH] feat(metrics): add metric for builder proxy being up Adds a metric, "rpc.builder_up" that indicates whether the builder proxy is responding to requests. If the builder proxy returns 500 Internal Server Error, the builder proxy is reported as down. Otherwise, the builder proxy is reported as up. This is a valuable feature for chain operators running rollup boost who need to track the status of the remote builder. --- src/metrics.rs | 11 ++++++++++- src/proxy.rs | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/metrics.rs b/src/metrics.rs index a10ce2d..f5976c8 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use metrics::{Counter, Histogram, counter, histogram}; +use metrics::{Counter, Gauge, Histogram, counter, gauge, histogram}; use metrics_derive::Metrics; use crate::server::PayloadSource; @@ -26,6 +26,10 @@ pub struct ServerMetrics { #[allow(dead_code)] pub builder_rpc_response_count: Counter, + #[metric(describe = "Whether the builder client is up")] + #[allow(dead_code)] + pub builder_up: Gauge, + // L2 proxy metrics #[metric(describe = "Latency for l2 client forwarded rpc calls (excluding the engine api)", labels = ["method"])] #[allow(dead_code)] @@ -73,6 +77,11 @@ impl ServerMetrics { histogram!("rpc.builder_forwarded_call", "method" => method).record(latency.as_secs_f64()); } + pub fn record_builder_up(&self, up: bool) { + let val = if up { 1 } else { 0 }; + gauge!("rpc.builder_up").set(val); + } + pub fn increment_builder_rpc_response_count( &self, http_status_code: String, diff --git a/src/proxy.rs b/src/proxy.rs index 52a902e..57c4814 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -339,6 +339,9 @@ async fn record_metrics( if let Some(metrics) = &metrics { match source { PayloadSource::Builder => { + metrics.record_builder_up( + http_status_code == StatusCode::INTERNAL_SERVER_ERROR.to_string(), + ); metrics.record_builder_forwarded_call(duration, method.to_string()); metrics.increment_builder_rpc_response_count( http_status_code,