@@ -11,7 +11,7 @@ macro_rules! define_metrics {
1111 $(
1212 $metric_type: ident $field: ident( $metric_name: literal)
1313 $( [ $( $label: literal) ,+ $( , ) ?] ) ?
14- $( buckets = [ $ ( $bucket : expr) ,+ $ ( , ) ? ] ) ?
14+ $( buckets = $buckets : expr) ?
1515 => $help: literal
1616 ) ,* $( , ) ?
1717 }
@@ -29,7 +29,7 @@ macro_rules! define_metrics {
2929 let $field = define_metrics!(
3030 @create $metric_type $metric_name $help
3131 $( [ $( $label) ,+] ) ?
32- $( buckets = [ $ ( $bucket ) ,+ ] ) ?
32+ $( buckets = $buckets ) ?
3333 ) ;
3434 registry. register( Box :: new( $field. clone( ) ) ) . expect( "metric not yet registered" ) ;
3535 ) *
@@ -86,68 +86,77 @@ macro_rules! define_metrics {
8686 ( @create histogram $name: literal $help: literal) => {
8787 Histogram :: with_opts( HistogramOpts :: new( $name, $help) ) . expect( "valid metric" )
8888 } ;
89- ( @create histogram $name: literal $help: literal buckets = [ $ ( $bucket : expr) ,+ ] ) => {
89+ ( @create histogram $name: literal $help: literal buckets = $buckets : expr) => {
9090 Histogram :: with_opts(
91- HistogramOpts :: new( $name, $help) . buckets( vec! [ $ ( $bucket ) ,+ ] )
91+ HistogramOpts :: new( $name, $help) . buckets( $buckets . to_vec ( ) )
9292 ) . expect( "valid metric" )
9393 } ;
9494 ( @create histogram $name: literal $help: literal [ $( $label: literal) ,+] ) => {
9595 HistogramVec :: new( HistogramOpts :: new( $name, $help) , & [ $( $label) ,+] ) . expect( "valid metric" )
9696 } ;
97- ( @create histogram $name: literal $help: literal [ $( $label: literal) ,+] buckets = [ $ ( $bucket : expr) ,+ ] ) => {
97+ ( @create histogram $name: literal $help: literal [ $( $label: literal) ,+] buckets = $buckets : expr) => {
9898 HistogramVec :: new(
99- HistogramOpts :: new( $name, $help) . buckets( vec! [ $ ( $bucket ) ,+ ] ) ,
99+ HistogramOpts :: new( $name, $help) . buckets( $buckets . to_vec ( ) ) ,
100100 & [ $( $label) ,+] ,
101101 ) . expect( "valid metric" )
102102 } ;
103103 ( @create histogram_vec $name: literal $help: literal [ $( $label: literal) ,+] ) => {
104104 HistogramVec :: new( HistogramOpts :: new( $name, $help) , & [ $( $label) ,+] ) . expect( "valid metric" )
105105 } ;
106- ( @create histogram_vec $name: literal $help: literal [ $( $label: literal) ,+] buckets = [ $ ( $bucket : expr) ,+ ] ) => {
106+ ( @create histogram_vec $name: literal $help: literal [ $( $label: literal) ,+] buckets = $buckets : expr) => {
107107 HistogramVec :: new(
108- HistogramOpts :: new( $name, $help) . buckets( vec! [ $ ( $bucket ) ,+ ] ) ,
108+ HistogramOpts :: new( $name, $help) . buckets( $buckets . to_vec ( ) ) ,
109109 & [ $( $label) ,+] ,
110110 ) . expect( "valid metric" )
111111 } ;
112112}
113113
114+ // Bucket sets grouped by operation latency profile.
115+
116+ /// HTTP request latency — from 5ms fast-path to 2.5s slow requests.
117+ const HTTP_BUCKETS : & [ f64 ] = & [ 0.005 , 0.01 , 0.025 , 0.05 , 0.1 , 0.25 , 0.5 , 1.0 , 2.5 ] ;
118+ /// Database-backed operations — 1ms fast-path through 1s slow queries.
119+ const DB_OP_BUCKETS : & [ f64 ] = & [ 0.001 , 0.005 , 0.01 , 0.025 , 0.05 , 0.1 , 0.25 , 0.5 , 1.0 ] ;
120+ /// Outbound HTTP webhook delivery — 50ms minimum round-trip to 10s timeout.
121+ const DELIVERY_BUCKETS : & [ f64 ] = & [ 0.05 , 0.1 , 0.25 , 0.5 , 1.0 , 2.0 , 5.0 , 10.0 ] ;
122+
114123define_metrics ! {
115124 pub struct Metrics {
116125 counter_vec http_requests_total( "http_requests_total" ) [ "method" , "path" , "status" ]
117126 => "Total HTTP requests" ,
118127 histogram_vec http_request_duration_seconds( "http_request_duration_seconds" ) [ "method" , "path" ]
119- buckets = [ 0.005 , 0.01 , 0.025 , 0.05 , 0.1 , 0.25 , 0.5 , 1.0 , 2.5 ]
128+ buckets = HTTP_BUCKETS
120129 => "HTTP request duration in seconds" ,
121130 gauge http_connections_active( "http_connections_active" )
122131 => "HTTP requests currently in flight" ,
123- counter_vec messages_sent_total( "messages_sent_total " ) [ "queue" ]
132+ counter_vec messages_sent_total( "queue_messages_sent_total " ) [ "queue" ]
124133 => "Total messages enqueued" ,
125- counter_vec messages_received_total( "messages_received_total " ) [ "queue" ]
134+ counter_vec messages_received_total( "queue_messages_received_total " ) [ "queue" ]
126135 => "Total messages delivered to consumers" ,
127- counter_vec messages_deleted_total( "messages_deleted_total " ) [ "queue" ]
136+ counter_vec messages_deleted_total( "queue_messages_deleted_total " ) [ "queue" ]
128137 => "Total messages deleted (acknowledged)" ,
129- counter_vec messages_redelivered_total( "messages_redelivered_total " ) [ "queue" ]
138+ counter_vec messages_redelivered_total( "queue_messages_redelivered_total " ) [ "queue" ]
130139 => "Total messages received with read_count > 1 (consumer did not ack before vt expiry)" ,
131- histogram_vec message_send_duration_seconds( "message_send_duration_seconds " ) [ "queue" ]
132- buckets = [ 0.001 , 0.005 , 0.01 , 0.025 , 0.05 , 0.1 , 0.25 , 0.5 , 1.0 ]
140+ histogram_vec message_send_duration_seconds( "queue_message_send_duration_seconds " ) [ "queue" ]
141+ buckets = DB_OP_BUCKETS
133142 => "Message send operation duration in seconds" ,
134- histogram_vec message_receive_duration_seconds( "message_receive_duration_seconds " ) [ "queue" ]
135- buckets = [ 0.001 , 0.005 , 0.01 , 0.025 , 0.05 , 0.1 , 0.25 , 0.5 , 1.0 ]
143+ histogram_vec message_receive_duration_seconds( "queue_message_receive_duration_seconds " ) [ "queue" ]
144+ buckets = DB_OP_BUCKETS
136145 => "Message receive operation duration in seconds" ,
137- histogram_vec message_delete_duration_seconds( "message_delete_duration_seconds " ) [ "queue" ]
138- buckets = [ 0.001 , 0.005 , 0.01 , 0.025 , 0.05 , 0.1 , 0.25 , 0.5 , 1.0 ]
146+ histogram_vec message_delete_duration_seconds( "queue_message_delete_duration_seconds " ) [ "queue" ]
147+ buckets = DB_OP_BUCKETS
139148 => "Message delete operation duration in seconds" ,
140- histogram_vec message_age_at_receive_seconds( "message_age_at_receive_seconds " ) [ "queue" ]
149+ histogram_vec message_age_at_receive_seconds( "queue_message_age_at_receive_seconds " ) [ "queue" ]
141150 buckets = [ 0.1 , 0.5 , 1.0 , 5.0 , 15.0 , 30.0 , 60.0 , 300.0 , 900.0 , 3600.0 ]
142151 => "Message age when received (time from enqueue to first delivery) in seconds" ,
143- counter_vec delivery_attempts_total( "delivery_attempts_total " ) [ "outcome" ]
152+ counter_vec delivery_attempts_total( "queue_delivery_attempts_total " ) [ "outcome" ]
144153 => "HTTP webhook delivery attempts by outcome (success|failure)" ,
145- histogram_vec delivery_attempt_duration_seconds( "delivery_attempt_duration_seconds " ) [ "outcome" ]
146- buckets = [ 0.05 , 0.1 , 0.25 , 0.5 , 1.0 , 2.0 , 5.0 , 10.0 ]
154+ histogram_vec delivery_attempt_duration_seconds( "queue_delivery_attempt_duration_seconds " ) [ "outcome" ]
155+ buckets = DELIVERY_BUCKETS
147156 => "HTTP webhook delivery attempt duration in seconds" ,
148- counter delivery_exhausted_total( "delivery_exhausted_total " )
157+ counter delivery_exhausted_total( "queue_delivery_exhausted_total " )
149158 => "Webhook deliveries permanently abandoned after exhausting max_attempts" ,
150- histogram coalescer_flush_batch_size( "coalescer_flush_batch_size " )
159+ histogram coalescer_flush_batch_size( "queue_coalescer_flush_batch_size " )
151160 buckets = [ 1.0 , 2.0 , 5.0 , 10.0 , 25.0 , 50.0 , 100.0 , 500.0 , 1000.0 ]
152161 => "Number of messages per coalescer flush batch" ,
153162 gauge_vec queue_depth( "queue_depth" ) [ "queue" ]
0 commit comments