From 70dae0b3af6460905c553061a9c862106c45809b Mon Sep 17 00:00:00 2001 From: timglabisch Date: Fri, 8 Dec 2023 14:19:38 +0100 Subject: [PATCH] less wtf's --- openmetrics_udpserver/src/http_server.rs | 30 ++++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/openmetrics_udpserver/src/http_server.rs b/openmetrics_udpserver/src/http_server.rs index 8d1abe3..a12c53c 100644 --- a/openmetrics_udpserver/src/http_server.rs +++ b/openmetrics_udpserver/src/http_server.rs @@ -20,24 +20,24 @@ struct HttpServerState { async fn get_metrics( State(state): State>, ) -> Result, StatusCode> { - if let Ok(registry) = state.metric_registry.try_read() { + let registry = state.metric_registry.read().await; + let body = { let mut buffer = String::new(); - if encode(&mut buffer, ®istry).is_ok() { - return Response::builder() - .status(StatusCode::OK) - .header( - "Content-Type", - "application/openmetrics-text; version=1.0.0; charset=utf-8", - ) - .body(buffer) - .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR); + if !encode(&mut buffer, ®istry).is_ok() { + return Err(StatusCode::INTERNAL_SERVER_ERROR); } - } + buffer + }; - Response::builder() - .status(StatusCode::LOCKED) - .body(String::from("Unable to access metric registry")) - .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR) + return Ok(Response::builder() + .status(StatusCode::OK) + .header( + "Content-Type", + "application/openmetrics-text; version=1.0.0; charset=utf-8", + ) + .body(body) + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)? + ); } pub(crate) fn bind(