@@ -62,6 +62,7 @@ const MVTX_REGISTRY_GLOBAL_PREFIX: &str = "monovtx";
6262// Prefixes for the sub-registries
6363const SINK_REGISTRY_PREFIX : & str = "sink" ;
6464const FALLBACK_SINK_REGISTRY_PREFIX : & str = "fallback_sink" ;
65+ const REDUCE_REGISTRY_PREFIX : & str = "reduce" ;
6566const ON_SUCCESS_SINK_REGISTRY_PREFIX : & str = "onsuccess_sink" ;
6667const TRANSFORMER_REGISTRY_PREFIX : & str = "transformer" ;
6768const UDF_REGISTRY_PREFIX : & str = "udf" ;
@@ -149,6 +150,14 @@ const SINK_TIME: &str = "time";
149150const FALLBACK_SINK_TIME : & str = "time" ;
150151const ON_SUCCESS_SINK_TIME : & str = "time" ;
151152
153+ // reduce specific metrics
154+ const REDUCE_ACTIVE_WINDOWS : & str = "active_windows" ;
155+ const REDUCE_CLOSED_WINDOWS : & str = "closed_windows" ;
156+ const REDUCE_WINDOW_PROCESSING_TIME : & str = "window_processing_time" ;
157+ const REDUCE_PNF_PROCESS_TIME : & str = "pnf_process_time" ;
158+ const REDUCE_WATERMARK_LAG : & str = "watermark_lag" ;
159+ const REDUCE_PBQ_WRITE_TOTAL : & str = "pbq_write" ;
160+
152161// jetstream isb processing times
153162const JETSTREAM_ISB_READ_TIME_TOTAL : & str = "read_time_total" ;
154163const JETSTREAM_ISB_WRITE_TIME_TOTAL : & str = "write_time_total" ;
@@ -307,6 +316,8 @@ pub(crate) struct PipelineMetrics {
307316 pub ( crate ) sink_forwarder : SinkForwarderMetrics ,
308317 pub ( crate ) jetstream_isb : JetStreamISBMetrics ,
309318 pub ( crate ) pending_raw : Family < Vec < ( String , String ) > , Gauge > ,
319+ // reduce specific metrics
320+ pub ( crate ) reduce : ReduceMetrics ,
310321}
311322
312323/// Family of metrics for the sink
@@ -342,6 +353,39 @@ pub(crate) struct UDFMetrics {
342353 pub ( crate ) errors_total : Family < Vec < ( String , String ) > , Counter > ,
343354}
344355
356+ /// Family of metrics for the Reduce vertex
357+ pub ( crate ) struct ReduceMetrics {
358+ // gauges
359+ pub ( crate ) active_windows : Family < Vec < ( String , String ) > , Gauge > ,
360+ pub ( crate ) closed_windows : Family < Vec < ( String , String ) > , Gauge > ,
361+ pub ( crate ) watermark_lag : Family < Vec < ( String , String ) > , Gauge < f64 , AtomicU64 > > ,
362+ // histograms
363+ pub ( crate ) window_processing_time : Family < Vec < ( String , String ) > , Histogram > ,
364+ pub ( crate ) pnf_process_time : Family < Vec < ( String , String ) > , Histogram > ,
365+ // counters
366+ pub ( crate ) pbq_write_total : Family < Vec < ( String , String ) > , Counter > ,
367+ }
368+
369+ impl ReduceMetrics {
370+ pub ( crate ) fn new ( ) -> Self {
371+ Self {
372+ active_windows : Family :: < Vec < ( String , String ) > , Gauge > :: default ( ) ,
373+ closed_windows : Family :: < Vec < ( String , String ) > , Gauge > :: default ( ) ,
374+ watermark_lag : Family :: < Vec < ( String , String ) > , Gauge < f64 , AtomicU64 > > :: default ( ) ,
375+ window_processing_time :
376+ Family :: < Vec < ( String , String ) > , Histogram > :: new_with_constructor (
377+ // 1ms to 60 minutes in microseconds
378+ || Histogram :: new ( exponential_buckets_range ( 1000.0 , 3_600_000_000.0 , 10 ) ) ,
379+ ) ,
380+ pnf_process_time : Family :: < Vec < ( String , String ) > , Histogram > :: new_with_constructor (
381+ // 1ms to 20 minutes in microseconds
382+ || Histogram :: new ( exponential_buckets_range ( 1000.0 , 1_200_000_000.0 , 10 ) ) ,
383+ ) ,
384+ pbq_write_total : Family :: < Vec < ( String , String ) > , Counter > :: default ( ) ,
385+ }
386+ }
387+ }
388+
345389/// Generic forwarder metrics
346390pub ( crate ) struct PipelineForwarderMetrics {
347391 // read counters
@@ -763,13 +807,15 @@ impl PipelineMetrics {
763807 sink_forwarder : SinkForwarderMetrics :: new ( ) ,
764808 jetstream_isb : JetStreamISBMetrics :: new ( ) ,
765809 pending_raw : Family :: < Vec < ( String , String ) > , Gauge > :: default ( ) ,
810+ reduce : ReduceMetrics :: new ( ) ,
766811 } ;
767812 let mut registry = global_registry ( ) . registry . lock ( ) ;
768813 Self :: register_forwarder_metrics ( & metrics, & mut registry) ;
769814 Self :: register_source_forwarder_metrics ( & metrics, & mut registry) ;
770815 Self :: register_sink_forwarder_metrics ( & metrics, & mut registry) ;
771816 Self :: register_jetstream_isb_metrics ( & metrics, & mut registry) ;
772817 Self :: register_vertex_metrics ( & metrics, & mut registry) ;
818+ Self :: register_reduce_metrics ( & metrics, & mut registry) ;
773819 metrics
774820 }
775821
@@ -1047,6 +1093,40 @@ impl PipelineMetrics {
10471093 metrics. pending_raw . clone ( ) ,
10481094 ) ;
10491095 }
1096+
1097+ fn register_reduce_metrics ( metrics : & Self , registry : & mut Registry ) {
1098+ let reduce_registry = registry. sub_registry_with_prefix ( REDUCE_REGISTRY_PREFIX ) ;
1099+ reduce_registry. register (
1100+ REDUCE_ACTIVE_WINDOWS ,
1101+ "Number of currently open reduce windows" ,
1102+ metrics. reduce . active_windows . clone ( ) ,
1103+ ) ;
1104+ reduce_registry. register (
1105+ REDUCE_CLOSED_WINDOWS ,
1106+ "Number of closed reduce windows awaiting GC" ,
1107+ metrics. reduce . closed_windows . clone ( ) ,
1108+ ) ;
1109+ reduce_registry. register (
1110+ REDUCE_WATERMARK_LAG ,
1111+ "Difference between current wall clock and watermark in milliseconds" ,
1112+ metrics. reduce . watermark_lag . clone ( ) ,
1113+ ) ;
1114+ reduce_registry. register (
1115+ REDUCE_WINDOW_PROCESSING_TIME ,
1116+ "Time from window open to window close in microseconds (1ms to 60 minutes)" ,
1117+ metrics. reduce . window_processing_time . clone ( ) ,
1118+ ) ;
1119+ reduce_registry. register (
1120+ REDUCE_PNF_PROCESS_TIME ,
1121+ "Time for UDF reduce function to complete per window in microseconds (1ms to 20 minutes)" ,
1122+ metrics. reduce . pnf_process_time . clone ( ) ,
1123+ ) ;
1124+ reduce_registry. register (
1125+ REDUCE_PBQ_WRITE_TOTAL ,
1126+ "Total number of messages written to PBQ" ,
1127+ metrics. reduce . pbq_write_total . clone ( ) ,
1128+ ) ;
1129+ }
10501130}
10511131
10521132/// MONOVTX_METRICS is the MonoVtxMetrics object which stores the metrics
0 commit comments