Skip to content

Commit c59b64f

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

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

common/src/indexer_service/http/indexer_service.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::{
99
use alloy::dyn_abi::Eip712Domain;
1010
use alloy::sol_types::eip712_domain;
1111
use anyhow;
12-
use autometrics::prometheus_exporter;
1312
use axum::extract::MatchedPath;
1413
use axum::extract::Request as ExtractRequest;
1514
use axum::http::{Method, Request};
@@ -22,6 +21,7 @@ use axum::{
2221
use axum::{serve, ServiceExt};
2322
use build_info::BuildInfo;
2423
use eventuals::Eventual;
24+
use prometheus::TextEncoder;
2525
use reqwest::StatusCode;
2626
use serde::{de::DeserializeOwned, Serialize};
2727
use sqlx::postgres::PgPoolOptions;
@@ -32,6 +32,7 @@ use tokio::net::TcpListener;
3232
use tokio::signal;
3333
use tower_governor::{governor::GovernorConfigBuilder, GovernorLayer};
3434
use tower_http::{cors, cors::CorsLayer, normalize_path::NormalizePath, trace::TraceLayer};
35+
use tracing::error;
3536
use tracing::{info, info_span};
3637

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

471486
serve(

0 commit comments

Comments
 (0)