From 4b0590b30eac20f0825ac750ddaf0e7c05966d3f Mon Sep 17 00:00:00 2001 From: Patrik Lundin Date: Thu, 14 Aug 2025 14:42:01 +0200 Subject: [PATCH] examples/prometheus-metrics: run upkeep task (#3430) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Mládek --- examples/prometheus-metrics/src/main.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/prometheus-metrics/src/main.rs b/examples/prometheus-metrics/src/main.rs index fe76121c..f02d7c3b 100644 --- a/examples/prometheus-metrics/src/main.rs +++ b/examples/prometheus-metrics/src/main.rs @@ -81,14 +81,24 @@ fn setup_metrics_recorder() -> PrometheusHandle { 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0, ]; - PrometheusBuilder::new() + let recorder_handle = PrometheusBuilder::new() .set_buckets_for_metric( Matcher::Full("http_requests_duration_seconds".to_string()), EXPONENTIAL_SECONDS, ) .unwrap() .install_recorder() - .unwrap() + .unwrap(); + + let upkeep_handle = recorder_handle.clone(); + tokio::spawn(async move { + loop { + tokio::time::sleep(Duration::from_secs(5)).await; + upkeep_handle.run_upkeep(); + } + }); + + recorder_handle } async fn track_metrics(req: Request, next: Next) -> impl IntoResponse {