Skip to content

Commit 36bd80e

Browse files
committed
remove unused code.
1 parent eb8596a commit 36bd80e

File tree

2 files changed

+0
-66
lines changed

2 files changed

+0
-66
lines changed
Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
use super::common::{default_health_server_hostname, default_health_server_port};
2-
use anyhow::Error;
3-
use poem::listener::TcpListener;
4-
use poem::{get, handler, IntoResponse, Response, Route, Server};
52
use serde::{Deserialize, Serialize};
63

74
// An additional health server to be used by the indexer(or any other service).
@@ -19,21 +16,3 @@ impl Default for Config {
1916
Self { hostname: default_health_server_hostname(), port: default_health_server_port() }
2017
}
2118
}
22-
23-
impl Config {
24-
pub async fn run(self) -> Result<(), anyhow::Error> {
25-
let url = format!("{}:{}", self.hostname, self.port);
26-
run_service(url).await
27-
}
28-
}
29-
30-
pub async fn run_service(url: String) -> Result<(), Error> {
31-
let route = Route::new().at("/health", get(health));
32-
tracing::info!("Start health check access on :{url} .");
33-
Server::new(TcpListener::bind(url)).run(route).await.map_err(Into::into)
34-
}
35-
36-
#[handler]
37-
async fn health() -> Response {
38-
"{\"OK\": \"healthy\"}".into_response()
39-
}
Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use super::common::{default_metrics_server_hostname, default_metrics_server_port};
2-
use poem::http::StatusCode;
3-
use poem::{get, handler, listener::TcpListener, IntoResponse, Route, Server};
4-
use prometheus::{gather, Encoder, TextEncoder};
52
use serde::{Deserialize, Serialize};
6-
use tokio::task::JoinHandle;
73

84
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
95
pub struct MetricsConfig {
@@ -21,44 +17,3 @@ impl Default for MetricsConfig {
2117
}
2218
}
2319
}
24-
25-
impl MetricsConfig {
26-
pub async fn start_metrics_server(&self) -> Result<JoinHandle<()>, anyhow::Error> {
27-
let bind_address = format!("{}:{}", self.listen_hostname, self.listen_port);
28-
29-
let metrics_route = Route::new().at("/metrics", get(metrics_handler));
30-
31-
let server_handle = tokio::spawn(async move {
32-
let listener = TcpListener::bind(&bind_address);
33-
tracing::info!("Starting Prometheus metrics server on http://{}/metrics", bind_address);
34-
35-
if let Err(e) = Server::new(listener).run(metrics_route).await {
36-
tracing::error!("Metrics server error: {}", e);
37-
}
38-
});
39-
40-
Ok(server_handle)
41-
}
42-
}
43-
44-
#[handler]
45-
async fn metrics_handler() -> impl IntoResponse {
46-
let metrics = gather();
47-
let encoder = TextEncoder::new();
48-
let mut buffer = vec![];
49-
50-
match encoder.encode(&metrics, &mut buffer) {
51-
Ok(_) => match String::from_utf8(buffer) {
52-
Ok(metrics_text) => poem::Response::builder()
53-
.status(StatusCode::OK)
54-
.header("content-type", "text/plain")
55-
.body(metrics_text),
56-
Err(_) => poem::Response::builder()
57-
.status(StatusCode::INTERNAL_SERVER_ERROR)
58-
.body("Error encoding metrics"),
59-
},
60-
Err(_) => poem::Response::builder()
61-
.status(StatusCode::INTERNAL_SERVER_ERROR)
62-
.body("Error gathering metrics"),
63-
}
64-
}

0 commit comments

Comments
 (0)