Skip to content

Commit 7a7c48b

Browse files
committed
fix(kms-connector): add prometheus content-type header
1 parent 266cdc8 commit 7a7c48b

File tree

1 file changed

+10
-3
lines changed
  • kms-connector/crates/utils/src/monitoring

1 file changed

+10
-3
lines changed

kms-connector/crates/utils/src/monitoring/otlp.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use actix_web::{HttpResponse, http::StatusCode};
1+
use actix_web::{HttpResponse, HttpResponseBuilder, body::BoxBody, http::StatusCode};
22
use anyhow::anyhow;
33
use opentelemetry::{
44
global,
@@ -51,13 +51,20 @@ pub fn init_otlp_setup(service_name: String) -> anyhow::Result<()> {
5151
Ok(())
5252
}
5353

54+
/// The content type header for Prometheus text-based metrics format.
55+
///
56+
/// For more details, check https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format
57+
const PROMETHEUS_TEXT_FORMAT_HEADER: (&str, &str) = ("Content-Type", "text/plain; version=0.0.4");
58+
5459
/// Responder used to collect metrics of the service.
5560
pub async fn metrics_responder() -> impl actix_web::Responder {
5661
let encoder = prometheus::TextEncoder::new();
5762
let metric_families = prometheus::gather();
5863
match encoder.encode_to_string(&metric_families) {
59-
Ok(encoded_metrics) => HttpResponse::with_body(StatusCode::OK, encoded_metrics),
60-
Err(e) => HttpResponse::with_body(StatusCode::INTERNAL_SERVER_ERROR, e.to_string()),
64+
Ok(encoded_metrics) => HttpResponse::Ok()
65+
.insert_header(PROMETHEUS_TEXT_FORMAT_HEADER)
66+
.body(encoded_metrics),
67+
Err(e) => HttpResponse::InternalServerError().body(e.to_string()),
6168
}
6269
}
6370

0 commit comments

Comments
 (0)