Skip to content

Commit

Permalink
chore(monitoring): format imports
Browse files Browse the repository at this point in the history
commit-id:851b43f7
  • Loading branch information
Itay-Tsabary-Starkware committed Nov 6, 2024
1 parent 2ab8bfa commit c77fb0d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
4 changes: 2 additions & 2 deletions crates/monitoring_endpoint/src/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::monitoring_endpoint::MonitoringEndpoint;
pub type MonitoringEndpointServer = WrapperServer<MonitoringEndpoint>;

pub fn create_monitoring_endpoint_server(
monitoring_endpont: MonitoringEndpoint,
monitoring_endpoint: MonitoringEndpoint,
) -> MonitoringEndpointServer {
create_empty_server(monitoring_endpont)
create_empty_server(monitoring_endpoint)
}
5 changes: 3 additions & 2 deletions crates/monitoring_endpoint/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::BTreeMap;
use std::fmt::{Display, Formatter, Result};
use std::net::IpAddr;

use papyrus_config::dumping::{ser_param, SerializeConfig};
Expand Down Expand Up @@ -37,9 +38,9 @@ impl SerializeConfig for MonitoringEndpointConfig {
}
}

impl std::fmt::Display for MonitoringEndpointConfig {
impl Display for MonitoringEndpointConfig {
#[cfg_attr(coverage_nightly, coverage_attribute)]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
write!(f, "{self:?}")
}
}
7 changes: 4 additions & 3 deletions crates/monitoring_endpoint/src/monitoring_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use std::net::SocketAddr;

use axum::http::StatusCode;
use axum::routing::get;
use axum::{async_trait, Router};
use axum::{async_trait, Router, Server};
use hyper::Error;
use starknet_sequencer_infra::component_definitions::ComponentStarter;
use starknet_sequencer_infra::errors::ComponentError;
use tracing::{info, instrument};
Expand Down Expand Up @@ -33,14 +34,14 @@ impl MonitoringEndpoint {
version = %self.version,
),
level = "debug")]
pub async fn run(&self) -> Result<(), hyper::Error> {
pub async fn run(&self) -> Result<(), Error> {
let MonitoringEndpointConfig { ip, port } = self.config;
let endpoint_addr = SocketAddr::new(ip, port);

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

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

fn app(&self) -> Router {
Expand Down
22 changes: 12 additions & 10 deletions crates/monitoring_endpoint/src/monitoring_endpoint_test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use std::net::IpAddr;

use axum::body::Bytes;
use axum::http::StatusCode;
use axum::response::Response;
use axum::Router;
use axum::{Error, Router};
use http_body::combinators::UnsyncBoxBody;
use hyper::body::to_bytes;
use hyper::Client;
use pretty_assertions::assert_eq;
use tokio::spawn;
use tokio::task::yield_now;
use tower::ServiceExt;

use super::MonitoringEndpointConfig;
Expand All @@ -20,10 +25,7 @@ fn setup_monitoring_endpoint() -> MonitoringEndpoint {
create_monitoring_endpoint(MonitoringEndpointConfig::default(), TEST_VERSION)
}

async fn request_app(
app: Router,
method: &str,
) -> Response<UnsyncBoxBody<axum::body::Bytes, axum::Error>> {
async fn request_app(app: Router, method: &str) -> Response<UnsyncBoxBody<Bytes, Error>> {
app.oneshot(build_request(&IpAddr::from([0, 0, 0, 0]), 0, method)).await.unwrap()
}

Expand All @@ -32,7 +34,7 @@ async fn test_node_version() {
let response = request_app(setup_monitoring_endpoint().app(), "nodeVersion").await;
assert_eq!(response.status(), StatusCode::OK);

let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = to_bytes(response.into_body()).await.unwrap();
assert_eq!(&body[..], TEST_VERSION.as_bytes());
}

Expand All @@ -50,16 +52,16 @@ async fn test_ready() {

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

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

let client = hyper::Client::new();
let client = Client::new();

let response = client.request(build_request(&ip, port, "nodeVersion")).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);

let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body = to_bytes(response.into_body()).await.unwrap();
assert_eq!(&body[..], TEST_VERSION.as_bytes());
}
5 changes: 3 additions & 2 deletions crates/monitoring_endpoint/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::time::Duration;
use axum::body::Body;
use axum::http::Request;
use hyper::client::HttpConnector;
use hyper::Client;
use tracing::info;

use crate::monitoring_endpoint::MONITORING_PREFIX;
Expand All @@ -13,12 +14,12 @@ use crate::monitoring_endpoint::MONITORING_PREFIX;
/// Client for querying 'alive' status of an http server.
pub struct IsAliveClient {
socket: SocketAddr,
client: hyper::Client<HttpConnector>,
client: Client<HttpConnector>,
}

impl IsAliveClient {
pub fn new(socket: SocketAddr) -> Self {
let client = hyper::Client::new();
let client = Client::new();
Self { socket, client }
}

Expand Down

0 comments on commit c77fb0d

Please sign in to comment.