Skip to content

Commit

Permalink
[fix] hyperledger-iroha#2581: exclude /health endpoint from tracing
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Balashov <a.marcius26@gmail.com>
  • Loading branch information
0x009922 committed Mar 30, 2023
1 parent aa7d000 commit 6508920
Showing 1 changed file with 47 additions and 33 deletions.
80 changes: 47 additions & 33 deletions cli/src/torii/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,12 @@ impl Torii {
pub(crate) fn create_api_router(
&self,
) -> impl warp::Filter<Extract = impl warp::Reply> + Clone + Send {
let get_router = warp::path(uri::HEALTH)
.and_then(|| async { Ok::<_, Infallible>(handle_health()) })
.or(endpoint3(
let health_route = warp::get()
.and(warp::path(uri::HEALTH))
.and_then(|| async { Ok::<_, Infallible>(handle_health()) });

let get_router = warp::get()
.and(endpoint3(
handle_pending_transactions,
warp::path(uri::PENDING_TRANSACTIONS)
.and(add_state!(self.queue, self.sumeragi))
Expand All @@ -551,30 +554,31 @@ impl Torii {
let get_router = get_router.or(warp::path(uri::SCHEMA)
.and_then(|| async { Ok::<_, Infallible>(handle_schema().await) }));

let post_router = endpoint4(
handle_instructions,
warp::path(uri::TRANSACTION)
.and(add_state!(self.iroha_cfg, self.queue, self.sumeragi))
.and(warp::body::content_length_limit(
self.iroha_cfg.torii.max_content_len.into(),
))
.and(body::versioned()),
)
.or(endpoint4(
handle_queries,
warp::path(uri::QUERY)
.and(add_state!(self.sumeragi))
.and(paginate())
.and(sorting())
.and(body::versioned()),
))
.or(endpoint2(
handle_post_configuration,
warp::path(uri::CONFIGURATION)
.and(add_state!(self.iroha_cfg))
.and(warp::body::json()),
))
.recover(|rejection| async move { body::recover_versioned(rejection) });
let post_router = warp::post()
.and(endpoint4(
handle_instructions,
warp::path(uri::TRANSACTION)
.and(add_state!(self.iroha_cfg, self.queue, self.sumeragi))
.and(warp::body::content_length_limit(
self.iroha_cfg.torii.max_content_len.into(),
))
.and(body::versioned()),
))
.or(endpoint4(
handle_queries,
warp::path(uri::QUERY)
.and(add_state!(self.sumeragi))
.and(paginate())
.and(sorting())
.and(body::versioned()),
))
.or(endpoint2(
handle_post_configuration,
warp::path(uri::CONFIGURATION)
.and(add_state!(self.iroha_cfg))
.and(warp::body::json()),
))
.recover(|rejection| async move { body::recover_versioned(rejection) });

let events_ws_router = warp::path(uri::SUBSCRIPTION)
.and(add_state!(self.events))
Expand Down Expand Up @@ -607,12 +611,22 @@ impl Torii {
})
});

let ws_router = events_ws_router.or(blocks_ws_router);

ws_router
.or(warp::post().and(post_router))
.or(warp::get().and(get_router))
.with(warp::trace::request())
let ws_router = events_ws_router
.or(blocks_ws_router)
.with(warp::trace::request());

warp::any()
.and(
// we want to avoid logging for the "health" endpoint.
// we have to place it **first** so that warp's trace will
// not log 404 if it doesn't find "/health" which might be placed
// **after** `.with(trace)`
health_route,
)
.or(ws_router
.or(get_router)
.or(post_router)
.with(warp::trace::request()))
}

/// Start status and metrics endpoints.
Expand Down

0 comments on commit 6508920

Please sign in to comment.