Skip to content
Snippets Groups Projects
Unverified Commit 0449b214 authored by tmpolaczyk's avatar tmpolaczyk Committed by GitHub
Browse files

Fix metrics not shutting down if there are open connections (#6220)

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:

https://github.com/paritytech/polkadot-sdk/pull/1637
parent 293d4a59
No related merge requests found
Pipeline #506152 waiting for manual action with stages
in 1 hour, 16 minutes, and 38 seconds
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
......@@ -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 }
......
......@@ -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 {
......@@ -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 {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment