@@ -34,6 +34,7 @@ struct ObservedSlotLabels {
3434pub struct Metrics {
3535 observed_slot : Family < ObservedSlotLabels , Counter > ,
3636 observed_slot_latency : Family < ObservedSlotLabels , Histogram > ,
37+ publish_to_receive_latency : Histogram ,
3738 first_observed_time_of_slot : BTreeMap < Slot , Instant > ,
3839 newest_observed_slot : HashMap < Event , Slot > ,
3940}
@@ -50,6 +51,12 @@ impl Metrics {
5051 . into_iter ( ) ,
5152 )
5253 } ) ,
54+ publish_to_receive_latency : Histogram :: new (
55+ [
56+ 0.1 , 0.2 , 0.3 , 0.4 , 0.5 , 0.7 , 1.0 , 1.3 , 1.7 , 2.0 , 3.0 , 5.0 , 10.0 , 20.0 ,
57+ ]
58+ . into_iter ( ) ,
59+ ) ,
5360 first_observed_time_of_slot : BTreeMap :: new ( ) ,
5461 newest_observed_slot : HashMap :: new ( ) ,
5562 } ;
@@ -69,11 +76,25 @@ impl Metrics {
6976 "Latency of observed slots in seconds" ,
7077 observed_slot_latency,
7178 ) ;
79+
80+ metrics_registry. register (
81+ "publish_to_receive_latency_seconds" ,
82+ "Latency from message publish_time to Hermes receive_time in seconds" ,
83+ new. publish_to_receive_latency . clone ( ) ,
84+ ) ;
7285 }
7386
7487 new
7588 }
7689
90+ pub fn observe_publish_to_receive ( & mut self , latency_secs : i64 ) {
91+ // Histogram only accepts f64. The conversion is safe (never panics), but very large values lose precision.
92+ let latency_secs = latency_secs as f64 ;
93+ if latency_secs. is_finite ( ) && latency_secs >= 0.0 {
94+ self . publish_to_receive_latency . observe ( latency_secs) ;
95+ }
96+ }
97+
7798 /// Observe a slot and event. An event at a slot should be observed only once.
7899 pub fn observe ( & mut self , slot : Slot , event : Event ) {
79100 let order = if self
0 commit comments