diff --git a/ipa-core/src/net/http_serde.rs b/ipa-core/src/net/http_serde.rs index d93112520..6d99498e0 100644 --- a/ipa-core/src/net/http_serde.rs +++ b/ipa-core/src/net/http_serde.rs @@ -70,27 +70,11 @@ pub mod echo { pub mod metrics { - use axum::{body::Body, http::uri}; use serde::{Deserialize, Serialize}; #[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Request {} - impl Request { - pub fn try_into_http_request( - self, - scheme: uri::Scheme, - authority: uri::Authority, - ) -> crate::net::http_serde::OutgoingRequest { - let uri = uri::Builder::new() - .scheme(scheme) - .authority(authority) - .path_and_query(String::from(AXUM_PATH)) - .build()?; - Ok(hyper::Request::get(uri).body(Body::empty())?) - } - } - pub const AXUM_PATH: &str = "/metrics"; } diff --git a/ipa-core/src/net/server/handlers/metrics.rs b/ipa-core/src/net/server/handlers/metrics.rs index 832350105..1c7d859b6 100644 --- a/ipa-core/src/net/server/handlers/metrics.rs +++ b/ipa-core/src/net/server/handlers/metrics.rs @@ -29,34 +29,34 @@ pub fn router(transport: MpcHttpTransport) -> Router { #[cfg(all(test, unit_test))] mod tests { - use axum::{body::Body, http::uri::{Authority, Scheme}}; - use bytes::Buf; - use http_body_util::BodyExt; - use hyper::{Request, StatusCode}; - use serde_json::{json, Value}; - use tower::ServiceExt; - - use crate::{helpers::{make_owned_handler, routing::Addr, HelperIdentity, HelperResponse}, net::server::handlers::query::test_helpers::assert_success_with}; + use axum::{ + body::Body, + http::uri::{self, Authority, Scheme}, + }; use super::*; + use crate::{ + helpers::{make_owned_handler, routing::Addr, HelperIdentity, HelperResponse}, + net::server::handlers::query::test_helpers::assert_success_with, + }; #[tokio::test] async fn happy_case() { let handler = make_owned_handler( move |addr: Addr, _data: BodyStream| async move { - println!("{:?}", addr.route); let RouteId::Metrics = addr.route else { panic!("unexpected call"); }; Ok(HelperResponse::from(Vec::new())) }, ); - let req = http_serde::metrics::Request { }; - let req = req - .try_into_http_request(Scheme::HTTP, Authority::from_static("localhost")) + let uri = uri::Builder::new() + .scheme(Scheme::HTTP) + .authority(Authority::from_static("localhost")) + .path_and_query(String::from("/metrics")) + .build() .unwrap(); - + let req = hyper::Request::get(uri).body(Body::empty()).unwrap(); assert_success_with(req, handler).await; - } } diff --git a/ipa-core/src/net/server/handlers/mod.rs b/ipa-core/src/net/server/handlers/mod.rs index a375b759b..2571a2be0 100644 --- a/ipa-core/src/net/server/handlers/mod.rs +++ b/ipa-core/src/net/server/handlers/mod.rs @@ -1,6 +1,6 @@ mod echo; -mod query; mod metrics; +mod query; use axum::Router; @@ -11,13 +11,13 @@ use crate::{ pub fn mpc_router(transport: MpcHttpTransport) -> Router { echo::router() - .merge(metrics::router(transport.clone())) - .nest( - http_serde::query::BASE_AXUM_PATH, - Router::new() - .merge(query::query_router(transport.clone())) - .merge(query::h2h_router(transport.inner_transport)), - ) + .merge(metrics::router(transport.clone())) + .nest( + http_serde::query::BASE_AXUM_PATH, + Router::new() + .merge(query::query_router(transport.clone())) + .merge(query::h2h_router(transport.inner_transport)), + ) } pub fn shard_router(transport: Arc>) -> Router { diff --git a/ipa-core/src/net/transport.rs b/ipa-core/src/net/transport.rs index bc0c4c41e..fda51ce70 100644 --- a/ipa-core/src/net/transport.rs +++ b/ipa-core/src/net/transport.rs @@ -115,7 +115,10 @@ impl HttpTransport { let req = serde_json::from_str(route.extra().borrow())?; self.clients[client_ix].status_match(req).await } - evt @ (RouteId::QueryInput | RouteId::ReceiveQuery | RouteId::KillQuery | RouteId::Metrics) => { + evt @ (RouteId::QueryInput + | RouteId::ReceiveQuery + | RouteId::KillQuery + | RouteId::Metrics) => { unimplemented!( "attempting to send client-specific request {evt:?} to another helper" ) diff --git a/ipa-metrics-prometheus/src/exporter.rs b/ipa-metrics-prometheus/src/exporter.rs index fee9026e8..8ba17f905 100644 --- a/ipa-metrics-prometheus/src/exporter.rs +++ b/ipa-metrics-prometheus/src/exporter.rs @@ -70,7 +70,6 @@ mod test { let mut buff = Vec::new(); store.export(&mut buff); - let expected_result = "# TYPE bar_total counter bar_total{otel_scope_name=\"ipa-helper\"} 1 # TYPE baz_total counter diff --git a/ipa-metrics/src/partitioned.rs b/ipa-metrics/src/partitioned.rs index 70fd4df0e..3b2419fae 100644 --- a/ipa-metrics/src/partitioned.rs +++ b/ipa-metrics/src/partitioned.rs @@ -124,12 +124,11 @@ impl PartitionedStore { pub fn counters(&self) -> impl Iterator { if let Some(partition) = CurrentThreadContext::get() { return match self.inner.get(&partition) { - Some(store) => store.counters(), - None => self.default_store.counters() - } - } else { - self.default_store.counters() + Some(store) => store.counters(), + None => self.default_store.counters(), + }; } + self.default_store.counters() } #[must_use]