Skip to content

Commit

Permalink
chore(starknet_monitoring_endpoint): revert app changes (#2504)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-starkware authored Dec 9, 2024
1 parent e72832e commit 195d4c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ impl MonitoringEndpoint {
let MonitoringEndpointConfig { ip, port, .. } = self.config;
let endpoint_addr = SocketAddr::new(ip, port);

let app = self.app(self.prometheus_handle.clone());
let app = self.app();
info!("MonitoringEndpoint running using socket: {}", endpoint_addr);

Server::bind(&endpoint_addr).serve(app.into_make_service()).await
}

fn app(&self, prometheus_handle: Option<PrometheusHandle>) -> Router {
fn app(&self) -> Router {
let version = self.version.to_string();
let prometheus_handle = self.prometheus_handle.clone();

Router::new()
.route(
Expand Down
20 changes: 10 additions & 10 deletions crates/starknet_monitoring_endpoint/src/monitoring_endpoint_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use axum::Router;
use hyper::body::to_bytes;
use hyper::Client;
use metrics::{absolute_counter, describe_counter, register_counter};
use metrics_exporter_prometheus::PrometheusBuilder;
use pretty_assertions::assert_eq;
use tokio::spawn;
use tokio::task::yield_now;
Expand All @@ -25,8 +24,9 @@ use crate::test_utils::build_request;

const TEST_VERSION: &str = "1.2.3-dev";

fn setup_monitoring_endpoint() -> MonitoringEndpoint {
create_monitoring_endpoint(MonitoringEndpointConfig::default(), TEST_VERSION)
fn setup_monitoring_endpoint(config: Option<MonitoringEndpointConfig>) -> MonitoringEndpoint {
let config = config.unwrap_or_default();
create_monitoring_endpoint(config, TEST_VERSION)
}

async fn request_app(app: Router, method: &str) -> Response {
Expand All @@ -35,7 +35,7 @@ async fn request_app(app: Router, method: &str) -> Response {

#[tokio::test]
async fn test_node_version() {
let response = request_app(setup_monitoring_endpoint().app(None), VERSION).await;
let response = request_app(setup_monitoring_endpoint(None).app(), VERSION).await;
assert_eq!(response.status(), StatusCode::OK);

let body = to_bytes(response.into_body()).await.unwrap();
Expand All @@ -44,20 +44,20 @@ async fn test_node_version() {

#[tokio::test]
async fn test_alive() {
let response = request_app(setup_monitoring_endpoint().app(None), ALIVE).await;
let response = request_app(setup_monitoring_endpoint(None).app(), ALIVE).await;
assert_eq!(response.status(), StatusCode::OK);
}

#[tokio::test]
async fn test_ready() {
let response = request_app(setup_monitoring_endpoint().app(None), READY).await;
let response = request_app(setup_monitoring_endpoint(None).app(), READY).await;
assert_eq!(response.status(), StatusCode::OK);
}

#[tokio::test]
async fn with_metrics() {
let app =
setup_monitoring_endpoint().app(Some(PrometheusBuilder::new().install_recorder().unwrap()));
let config = MonitoringEndpointConfig { collect_metrics: true, ..Default::default() };
let app = setup_monitoring_endpoint(Some(config)).app();

// Register a metric.
let metric_name = "metric_name";
Expand All @@ -80,14 +80,14 @@ async fn with_metrics() {

#[tokio::test]
async fn without_metrics() {
let app = setup_monitoring_endpoint().app(None);
let app = setup_monitoring_endpoint(None).app();
let response = request_app(app, METRICS).await;
assert_eq!(response.status(), StatusCode::METHOD_NOT_ALLOWED);
}

#[tokio::test]
async fn test_endpoint_as_server() {
spawn(async move { setup_monitoring_endpoint().run().await });
spawn(async move { setup_monitoring_endpoint(None).run().await });
yield_now().await;

let MonitoringEndpointConfig { ip, port, .. } = MonitoringEndpointConfig::default();
Expand Down

0 comments on commit 195d4c2

Please sign in to comment.