Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinta Liem committed Dec 10, 2024
1 parent 5d7c689 commit 76c6652
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 45 deletions.
16 changes: 0 additions & 16 deletions ipa-core/src/net/http_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
28 changes: 14 additions & 14 deletions ipa-core/src/net/server/handlers/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HelperIdentity>, _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;

}
}
16 changes: 8 additions & 8 deletions ipa-core/src/net/server/handlers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod echo;
mod query;
mod metrics;
mod query;

use axum::Router;

Expand All @@ -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<HttpTransport<Shard>>) -> Router {
Expand Down
5 changes: 4 additions & 1 deletion ipa-core/src/net/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ impl<F: ConnectionFlavor> HttpTransport<F> {
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"
)
Expand Down
1 change: 0 additions & 1 deletion ipa-metrics-prometheus/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions ipa-metrics/src/partitioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,11 @@ impl PartitionedStore {
pub fn counters(&self) -> impl Iterator<Item = (&OwnedMetricName, CounterValue)> {
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]
Expand Down

0 comments on commit 76c6652

Please sign in to comment.