Skip to content

Commit 95508b7

Browse files
committed
fix: use prometheus to encode metrics
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent e41569d commit 95508b7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

common/src/indexer_service/http/indexer_service.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use axum::{
2222
use axum::{serve, ServiceExt};
2323
use build_info::BuildInfo;
2424
use eventuals::Eventual;
25+
use prometheus::TextEncoder;
2526
use reqwest::StatusCode;
2627
use serde::{de::DeserializeOwned, Serialize};
2728
use sqlx::postgres::PgPoolOptions;
@@ -32,6 +33,7 @@ use tokio::net::TcpListener;
3233
use tokio::signal;
3334
use tower_governor::{governor::GovernorConfigBuilder, GovernorLayer};
3435
use tower_http::{cors, cors::CorsLayer, normalize_path::NormalizePath, trace::TraceLayer};
36+
use tracing::error;
3537
use tracing::{info, info_span};
3638

3739
use crate::escrow_accounts::EscrowAccounts;
@@ -465,7 +467,21 @@ impl IndexerService {
465467
tokio::spawn(async move {
466468
let router = Router::new().route(
467469
"/metrics",
468-
get(|| async { prometheus_exporter::encode_http_response() }),
470+
get(|| async {
471+
let metric_families = prometheus::gather();
472+
let encoder = TextEncoder::new();
473+
474+
match encoder.encode_to_string(&metric_families) {
475+
Ok(s) => (StatusCode::OK, s),
476+
Err(e) => {
477+
error!("Error encoding metrics: {}", e);
478+
(
479+
StatusCode::INTERNAL_SERVER_ERROR,
480+
format!("Error encoding metrics: {}", e),
481+
)
482+
}
483+
}
484+
}),
469485
);
470486

471487
serve(

0 commit comments

Comments
 (0)