Skip to content

Commit fb79453

Browse files
committed
Address Prometheus upkeep review
1 parent 5ba5cce commit fb79453

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

  • quickwit/quickwit-telemetry-exporters/src

quickwit/quickwit-telemetry-exporters/src/metrics.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
use std::sync::OnceLock;
16-
#[cfg(not(test))]
1716
use std::time::Duration;
1817

1918
use anyhow::Context;
@@ -94,19 +93,11 @@ fn build_prometheus_recorder() -> anyhow::Result<PrometheusRecorder> {
9493
}
9594
let prometheus_recorder = prometheus_builder.build_recorder();
9695
let prometheus_handle = prometheus_recorder.handle();
97-
set_prometheus_handle(prometheus_handle.clone()).map_err(anyhow::Error::msg)?;
98-
Ok(prometheus_recorder)
99-
}
100-
101-
fn set_prometheus_handle(handle: PrometheusHandle) -> Result<(), String> {
102-
#[cfg(not(test))]
103-
let upkeep_handle = handle.clone();
10496
PROMETHEUS_HANDLE
105-
.set(handle)
106-
.map_err(|_| "Prometheus metrics renderer is already installed".to_string())?;
107-
#[cfg(not(test))]
108-
spawn_prometheus_upkeep(upkeep_handle)?;
109-
Ok(())
97+
.set(prometheus_handle.clone())
98+
.map_err(|_| anyhow::anyhow!("Prometheus metrics renderer is already installed"))?;
99+
spawn_prometheus_upkeep(prometheus_handle).map_err(anyhow::Error::msg)?;
100+
Ok(prometheus_recorder)
110101
}
111102

112103
pub fn metrics_text_payload() -> Result<String, String> {
@@ -116,13 +107,12 @@ pub fn metrics_text_payload() -> Result<String, String> {
116107
Ok(handle.render())
117108
}
118109

119-
#[cfg(not(test))]
120110
fn spawn_prometheus_upkeep(handle: PrometheusHandle) -> Result<(), String> {
121111
// Quickwit serves the existing `/metrics` route itself, so we build only the
122112
// Prometheus recorder instead of using the exporter's HTTP listener. That lower-level
123113
// API does not spawn the upkeep task that periodically drains histogram buffers.
124114
std::thread::Builder::new()
125-
.name("metrics-exporter-prometheus-upkeep".to_string())
115+
.name("telemetry-exporter-prometheus-upkeep".to_string())
126116
.spawn(move || {
127117
loop {
128118
std::thread::sleep(Duration::from_secs(5));
@@ -164,7 +154,9 @@ mod tests {
164154
#[test]
165155
fn metrics_text_payload_renders_prometheus_handle() {
166156
let recorder = PrometheusBuilder::new().build_recorder();
167-
set_prometheus_handle(recorder.handle()).expect("Prometheus handle should be set once");
157+
PROMETHEUS_HANDLE
158+
.set(recorder.handle())
159+
.expect("Prometheus handle should be set once");
168160

169161
with_local_recorder(&recorder, || {
170162
let info_metric = gauge!(

0 commit comments

Comments
 (0)