Skip to content

Commit 1b1fc5d

Browse files
authored
feat: add relay header metric (#161)
* add relay header metric * add header panel * fix value in logs
1 parent 5d54b6a commit 1b1fc5d

File tree

5 files changed

+172
-7
lines changed

5 files changed

+172
-7
lines changed

crates/pbs/src/metrics.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ lazy_static! {
4141
)
4242
.unwrap();
4343

44+
/// Latest slot for which relay delivered a header
45+
// Don't store slot number to avoid creating high cardinality, if needed can just aggregate for 12sec
46+
pub static ref RELAY_HEADER_VALUE: IntGaugeVec = register_int_gauge_vec_with_registry!(
47+
"relay_header_value",
48+
"Header value in gwei delivered by relay",
49+
&["relay_id"],
50+
PBS_METRICS_REGISTRY
51+
)
52+
.unwrap();
53+
54+
4455
// TO BEACON NODE
4556
/// Status code returned to beacon node by endpoint
4657
pub static ref BEACON_NODE_STATUS: IntCounterVec = register_int_counter_vec_with_registry!(

crates/pbs/src/mev_boost/get_header.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use url::Url;
2525

2626
use crate::{
2727
constants::{GET_HEADER_ENDPOINT_TAG, TIMEOUT_ERROR_CODE, TIMEOUT_ERROR_CODE_STR},
28-
metrics::{RELAY_LAST_SLOT, RELAY_LATENCY, RELAY_STATUS_CODE},
28+
metrics::{RELAY_HEADER_VALUE, RELAY_LAST_SLOT, RELAY_LATENCY, RELAY_STATUS_CODE},
2929
state::{BuilderApiState, PbsState},
3030
};
3131

@@ -76,11 +76,15 @@ pub async fn get_header<S: BuilderApiState>(
7676
let results = join_all(handles).await;
7777
let mut relay_bids = Vec::with_capacity(relays.len());
7878
for (i, res) in results.into_iter().enumerate() {
79-
let relay_id = relays[i].id.as_ref();
79+
let relay_id = relays[i].id.as_str();
8080

8181
match res {
8282
Ok(Some(res)) => {
8383
RELAY_LAST_SLOT.with_label_values(&[relay_id]).set(params.slot as i64);
84+
let value_gwei =
85+
(res.value() / U256::from(1_000_000_000)).try_into().unwrap_or_default();
86+
RELAY_HEADER_VALUE.with_label_values(&[relay_id]).set(value_gwei);
87+
8488
relay_bids.push(res)
8589
}
8690
Ok(_) => {}
@@ -276,8 +280,8 @@ async fn send_one_get_header(
276280

277281
debug!(
278282
latency = ?request_latency,
279-
block_hash = %get_header_response.block_hash(),
280283
value_eth = format_ether(get_header_response.value()),
284+
block_hash = %get_header_response.block_hash(),
281285
"received new header"
282286
);
283287

crates/pbs/src/routes/get_header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub async fn handle_get_header<S: BuilderApiState, A: BuilderApi<S>>(
3939
state.publish_event(BuilderEvent::GetHeaderResponse(Box::new(res.clone())));
4040

4141
if let Some(max_bid) = res {
42-
info!(block_hash =% max_bid.block_hash(), value_eth = format_ether(max_bid.value()), "received header");
42+
info!(value_eth = format_ether(max_bid.value()), block_hash =% max_bid.block_hash(), "received header");
4343

4444
BEACON_NODE_STATUS.with_label_values(&["200", GET_HEADER_ENDPOINT_TAG]).inc();
4545
Ok((StatusCode::OK, axum::Json(max_bid)).into_response())

grafana/dashboards/dashboard.json

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"editable": true,
4747
"fiscalYearStartMonth": 0,
4848
"graphTooltip": 0,
49-
"id": null,
49+
"id": 1,
5050
"links": [],
5151
"liveNow": true,
5252
"panels": [
@@ -127,6 +127,81 @@
127127
"title": "Last delivered slot",
128128
"type": "stat"
129129
},
130+
{
131+
"datasource": {
132+
"type": "prometheus",
133+
"uid": "cb_prometheus"
134+
},
135+
"fieldConfig": {
136+
"defaults": {
137+
"color": {
138+
"fixedColor": "text",
139+
"mode": "thresholds"
140+
},
141+
"decimals": 6,
142+
"fieldMinMax": false,
143+
"mappings": [],
144+
"thresholds": {
145+
"mode": "percentage",
146+
"steps": [
147+
{
148+
"color": "text",
149+
"value": null
150+
}
151+
]
152+
},
153+
"unit": "ETH"
154+
},
155+
"overrides": []
156+
},
157+
"gridPos": {
158+
"h": 11,
159+
"w": 6,
160+
"x": 6,
161+
"y": 0
162+
},
163+
"id": 78,
164+
"options": {
165+
"colorMode": "none",
166+
"graphMode": "area",
167+
"justifyMode": "auto",
168+
"orientation": "horizontal",
169+
"percentChangeColorMode": "standard",
170+
"reduceOptions": {
171+
"calcs": [
172+
"lastNotNull"
173+
],
174+
"fields": "",
175+
"values": false
176+
},
177+
"showPercentChange": false,
178+
"textMode": "auto",
179+
"wideLayout": true
180+
},
181+
"pluginVersion": "11.1.0",
182+
"targets": [
183+
{
184+
"datasource": {
185+
"type": "prometheus",
186+
"uid": "cb_prometheus"
187+
},
188+
"disableTextWrap": false,
189+
"editorMode": "code",
190+
"exemplar": false,
191+
"expr": "cb_pbs_relay_header_value / 1e9",
192+
"format": "time_series",
193+
"fullMetaSearch": false,
194+
"includeNullMetadata": true,
195+
"instant": false,
196+
"legendFormat": "{{relay_id}}",
197+
"range": true,
198+
"refId": "A",
199+
"useBackend": false
200+
}
201+
],
202+
"title": "Last delivered header value",
203+
"type": "stat"
204+
},
130205
{
131206
"collapsed": false,
132207
"gridPos": {
@@ -904,6 +979,6 @@
904979
"timezone": "browser",
905980
"title": "PBS Metrics",
906981
"uid": "cb_pbs_metrics",
907-
"version": 2,
982+
"version": 1,
908983
"weekStart": ""
909984
}

grafana/public_dashboard.json

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,81 @@
136136
"title": "Last delivered slot",
137137
"type": "stat"
138138
},
139+
{
140+
"datasource": {
141+
"type": "prometheus",
142+
"uid": "${DS_CB_PROMETHEUS}"
143+
},
144+
"fieldConfig": {
145+
"defaults": {
146+
"color": {
147+
"fixedColor": "text",
148+
"mode": "thresholds"
149+
},
150+
"decimals": 6,
151+
"fieldMinMax": false,
152+
"mappings": [],
153+
"thresholds": {
154+
"mode": "percentage",
155+
"steps": [
156+
{
157+
"color": "text",
158+
"value": null
159+
}
160+
]
161+
},
162+
"unit": "ETH"
163+
},
164+
"overrides": []
165+
},
166+
"gridPos": {
167+
"h": 11,
168+
"w": 6,
169+
"x": 6,
170+
"y": 0
171+
},
172+
"id": 78,
173+
"options": {
174+
"colorMode": "none",
175+
"graphMode": "area",
176+
"justifyMode": "auto",
177+
"orientation": "horizontal",
178+
"percentChangeColorMode": "standard",
179+
"reduceOptions": {
180+
"calcs": [
181+
"lastNotNull"
182+
],
183+
"fields": "",
184+
"values": false
185+
},
186+
"showPercentChange": false,
187+
"textMode": "auto",
188+
"wideLayout": true
189+
},
190+
"pluginVersion": "11.1.0",
191+
"targets": [
192+
{
193+
"datasource": {
194+
"type": "prometheus",
195+
"uid": "${DS_CB_PROMETHEUS}"
196+
},
197+
"disableTextWrap": false,
198+
"editorMode": "code",
199+
"exemplar": false,
200+
"expr": "cb_pbs_relay_header_value / 1e9",
201+
"format": "time_series",
202+
"fullMetaSearch": false,
203+
"includeNullMetadata": true,
204+
"instant": false,
205+
"legendFormat": "{{relay_id}}",
206+
"range": true,
207+
"refId": "A",
208+
"useBackend": false
209+
}
210+
],
211+
"title": "Last delivered header value",
212+
"type": "stat"
213+
},
139214
{
140215
"collapsed": false,
141216
"gridPos": {
@@ -913,6 +988,6 @@
913988
"timezone": "browser",
914989
"title": "PBS Metrics",
915990
"uid": "cb_pbs_metrics",
916-
"version": 2,
991+
"version": 1,
917992
"weekStart": ""
918993
}

0 commit comments

Comments
 (0)