From 6d58afa1981832408e063dac07f809e4f224f981 Mon Sep 17 00:00:00 2001 From: Bianca Pelegrini Date: Sat, 23 Dec 2023 00:56:40 -0300 Subject: [PATCH 1/3] add health endpoint to http listener --- metrics-exporter-prometheus/src/builder.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/metrics-exporter-prometheus/src/builder.rs b/metrics-exporter-prometheus/src/builder.rs index 70f5f762..5c3736f5 100644 --- a/metrics-exporter-prometheus/src/builder.rs +++ b/metrics-exporter-prometheus/src/builder.rs @@ -435,13 +435,16 @@ impl PrometheusBuilder { let handle = handle.clone(); async move { - Ok::<_, hyper::Error>(service_fn(move |_| { + Ok::<_, hyper::Error>(service_fn(move |req| { let handle = handle.clone(); async move { if is_allowed { let output = handle.render(); - Ok::<_, hyper::Error>(Response::new(Body::from(output))) + Ok::<_, hyper::Error>(match req.uri().path() { + "/health" => Response::new(Body::from("Ok")), + _ => Response::new(Body::from(output)), + }) } else { Ok::<_, hyper::Error>( Response::builder() From ffef4002bbbd2ab29f52f268d132b03d7920b480 Mon Sep 17 00:00:00 2001 From: Toby Lawrence Date: Sun, 14 Jan 2024 09:39:33 -0500 Subject: [PATCH 2/3] change output string for healthcheck endpoint --- metrics-exporter-prometheus/src/builder.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics-exporter-prometheus/src/builder.rs b/metrics-exporter-prometheus/src/builder.rs index 764c2184..01f0d1bc 100644 --- a/metrics-exporter-prometheus/src/builder.rs +++ b/metrics-exporter-prometheus/src/builder.rs @@ -442,7 +442,7 @@ impl PrometheusBuilder { if is_allowed { let output = handle.render(); Ok::<_, hyper::Error>(match req.uri().path() { - "/health" => Response::new(Body::from("Ok")), + "/health" => Response::new(Body::from("OK")), _ => Response::new(Body::from(output)), }) } else { From b0e6ac677ad86ed8498c2d2a053730d8bfdff42f Mon Sep 17 00:00:00 2001 From: Toby Lawrence Date: Sun, 14 Jan 2024 09:40:31 -0500 Subject: [PATCH 3/3] don't generate rendered output if healthcheck endpoint --- metrics-exporter-prometheus/src/builder.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/metrics-exporter-prometheus/src/builder.rs b/metrics-exporter-prometheus/src/builder.rs index 01f0d1bc..6d02bb4a 100644 --- a/metrics-exporter-prometheus/src/builder.rs +++ b/metrics-exporter-prometheus/src/builder.rs @@ -440,10 +440,9 @@ impl PrometheusBuilder { async move { if is_allowed { - let output = handle.render(); Ok::<_, hyper::Error>(match req.uri().path() { "/health" => Response::new(Body::from("OK")), - _ => Response::new(Body::from(output)), + _ => Response::new(Body::from(handle.render())), }) } else { Ok::<_, hyper::Error>(