@@ -250,7 +250,8 @@ impl PrometheusMetrics {
250
250
endpoint : Option < & str > ,
251
251
replacements : Vec < ( Regex , String ) > ,
252
252
) -> Result < Self , Box < dyn std:: error:: Error > > {
253
- let ( http_requests_total, http_requests_duration_seconds) = Self :: register_metrics ( & registry, namespace) ?;
253
+ let ( http_requests_total, http_requests_duration_seconds) =
254
+ Self :: register_metrics ( & registry, namespace) ?;
254
255
Ok ( PrometheusMetrics {
255
256
http_requests_total,
256
257
http_requests_duration_seconds,
@@ -273,7 +274,8 @@ impl PrometheusMetrics {
273
274
namespace : & str ,
274
275
endpoint : Option < & str > ,
275
276
) -> Result < Self , Box < std:: error:: Error > > {
276
- let ( http_requests_total, http_requests_duration_seconds) = Self :: register_metrics ( & registry, namespace) ?;
277
+ let ( http_requests_total, http_requests_duration_seconds) =
278
+ Self :: register_metrics ( & registry, namespace) ?;
277
279
Ok ( PrometheusMetrics {
278
280
http_requests_total,
279
281
http_requests_duration_seconds,
@@ -287,14 +289,15 @@ impl PrometheusMetrics {
287
289
} )
288
290
}
289
291
290
- fn register_metrics ( registry : & Registry , namespace : & str ) -> prometheus:: Result < ( IntCounterVec , HistogramVec ) > {
291
- let http_requests_total_opts = opts ! (
292
- "http_requests_total" , "Total number of HTTP requests"
293
- ) . namespace ( namespace) ;
294
- let http_requests_total = IntCounterVec :: new (
295
- http_requests_total_opts,
296
- & [ "endpoint" , "method" , "status" ] ,
297
- ) . unwrap ( ) ;
292
+ fn register_metrics (
293
+ registry : & Registry ,
294
+ namespace : & str ,
295
+ ) -> prometheus:: Result < ( IntCounterVec , HistogramVec ) > {
296
+ let http_requests_total_opts =
297
+ opts ! ( "http_requests_total" , "Total number of HTTP requests" ) . namespace ( namespace) ;
298
+ let http_requests_total =
299
+ IntCounterVec :: new ( http_requests_total_opts, & [ "endpoint" , "method" , "status" ] )
300
+ . unwrap ( ) ;
298
301
299
302
registry. register ( Box :: new ( http_requests_total. clone ( ) ) ) ?;
300
303
@@ -306,7 +309,8 @@ impl PrometheusMetrics {
306
309
let http_requests_duration_seconds = HistogramVec :: new (
307
310
http_requests_duration_seconds_opts. into ( ) ,
308
311
& [ "endpoint" , "method" , "status" ] ,
309
- ) . unwrap ( ) ;
312
+ )
313
+ . unwrap ( ) ;
310
314
311
315
registry. register ( Box :: new ( http_requests_duration_seconds. clone ( ) ) ) ?;
312
316
@@ -345,7 +349,13 @@ impl PrometheusMetrics {
345
349
self . update_metrics_inner ( path, method, status, clock)
346
350
}
347
351
348
- fn update_metrics_inner ( & self , path : & str , method : & Method , status : StatusCode , clock : SystemTime ) {
352
+ fn update_metrics_inner (
353
+ & self ,
354
+ path : & str ,
355
+ method : & Method ,
356
+ status : StatusCode ,
357
+ clock : SystemTime ,
358
+ ) {
349
359
let method = method. to_string ( ) ;
350
360
let status = status. as_u16 ( ) . to_string ( ) ;
351
361
0 commit comments