Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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