examples/prometheus-metrics: run upkeep task (#3430)

Co-authored-by: David Mládek <david.mladek.cz@gmail.com>
This commit is contained in:
Patrik Lundin 2025-08-14 14:42:01 +02:00 committed by GitHub
parent a57935c039
commit 4b0590b30e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 {