Skip to content

Commit

Permalink
Fix metrics not shutting down if there are open connections (#6220)
Browse files Browse the repository at this point in the history
Fix prometheus metrics not shutting down if there are open connections.
I fixed the same issue in the past but it broke again after a dependecy
upgrade.

See also:

#1637
  • Loading branch information
tmpolaczyk authored Nov 19, 2024
1 parent 293d4a5 commit 0449b21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions prdoc/pr_6220.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: Fix metrics not shutting down if there are open connections

doc:
- audience: Runtime Dev
description: |
Fix prometheus metrics not shutting down if there are open connections

crates:
- name: substrate-prometheus-endpoint
bump: patch
2 changes: 1 addition & 1 deletion substrate/utils/prometheus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
http-body-util = { workspace = true }
hyper = { features = ["http1", "server"], workspace = true }
hyper-util = { features = ["server-auto", "tokio"], workspace = true }
hyper-util = { features = ["server-auto", "server-graceful", "tokio"], workspace = true }
log = { workspace = true, default-features = true }
prometheus = { workspace = true }
thiserror = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions substrate/utils/prometheus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ async fn init_prometheus_with_listener(
log::info!(target: "prometheus", "〽️ Prometheus exporter started at {}", listener.local_addr()?);

let server = hyper_util::server::conn::auto::Builder::new(hyper_util::rt::TokioExecutor::new());
let graceful = hyper_util::server::graceful::GracefulShutdown::new();

loop {
let io = match listener.accept().await {
Expand All @@ -120,6 +121,7 @@ async fn init_prometheus_with_listener(
hyper::service::service_fn(move |req| request_metrics(req, registry.clone())),
)
.into_owned();
let conn = graceful.watch(conn);

tokio::spawn(async move {
if let Err(err) = conn.await {
Expand Down

0 comments on commit 0449b21

Please sign in to comment.