Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 83 additions & 19 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,35 +215,66 @@ pub fn prometheus_metrics() -> warp::filters::log::Log<impl Fn(warp::filters::lo

// First line covers `POST /v1/beacon/blocks` only
equals("v1/beacon/blocks")
.or_else(|| starts_with("v1/validator/blocks"))
.or_else(|| starts_with("v2/validator/blocks"))
.or_else(|| starts_with("v1/validator/blinded_blocks"))
.or_else(|| starts_with("v1/validator/duties/attester"))
.or_else(|| starts_with("v1/validator/duties/proposer"))
.or_else(|| starts_with("v1/validator/duties/sync"))
.or_else(|| starts_with("v1/validator/attestation_data"))
.or_else(|| starts_with("v1/validator/aggregate_attestation"))
.or_else(|| starts_with("v2/validator/aggregate_attestation"))
.or_else(|| starts_with("v1/validator/aggregate_and_proofs"))
.or_else(|| starts_with("v2/validator/aggregate_and_proofs"))
.or_else(|| starts_with("v1/validator/sync_committee_contribution"))
.or_else(|| starts_with("v1/validator/contribution_and_proofs"))
.or_else(|| starts_with("v1/validator/beacon_committee_subscriptions"))
.or_else(|| starts_with("v1/validator/sync_committee_subscriptions"))
.or_else(|| starts_with("v1/beacon/blob_sidecars"))
.or_else(|| starts_with("v1/beacon/blocks/head/root"))
.or_else(|| starts_with("v1/beacon/blinded_blocks"))
.or_else(|| starts_with("v1/beacon/deposit_snapshot"))
.or_else(|| starts_with("v1/beacon/headers"))
.or_else(|| starts_with("v1/beacon/light_client"))
.or_else(|| starts_with("v1/beacon/pool/attestations"))
.or_else(|| starts_with("v2/beacon/pool/attestations"))
.or_else(|| starts_with("v1/beacon/pool/attester_slashings"))
.or_else(|| starts_with("v1/beacon/pool/bls_to_execution_changes"))
.or_else(|| starts_with("v1/beacon/pool/proposer_slashings"))
.or_else(|| starts_with("v1/beacon/pool/sync_committees"))
.or_else(|| starts_with("v1/beacon/blocks/head/root"))
.or_else(|| starts_with("v1/validator/prepare_beacon_proposer"))
.or_else(|| starts_with("v1/validator/register_validator"))
.or_else(|| starts_with("v1/beacon/pool/voluntary_exits"))
.or_else(|| starts_with("v1/beacon/rewards/blocks"))
.or_else(|| starts_with("v1/beacon/rewards/attestations"))
.or_else(|| starts_with("v1/beacon/rewards/sync_committee"))
.or_else(|| starts_with("v1/beacon/rewards"))
.or_else(|| starts_with("v1/beacon/states"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are still using a catch-all from all beacon/states/{state_id} endpoints. At a later time it might be worth trying to split these out into their discrete routes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they're probably all equally slow, but yeah that's a decent idea

.or_else(|| starts_with("v1/beacon/"))
.or_else(|| starts_with("v2/beacon/"))
.or_else(|| starts_with("v1/builder/states"))
.or_else(|| starts_with("v1/config/deposit_contract"))
.or_else(|| starts_with("v1/config/fork_schedule"))
.or_else(|| starts_with("v1/config/spec"))
.or_else(|| starts_with("v1/config/"))
.or_else(|| starts_with("v1/debug/"))
.or_else(|| starts_with("v2/debug/"))
.or_else(|| starts_with("v1/events"))
.or_else(|| starts_with("v1/events/"))
.or_else(|| starts_with("v1/node/"))
.or_else(|| starts_with("v1/node/health"))
.or_else(|| starts_with("v1/node/identity"))
.or_else(|| starts_with("v1/node/peers"))
.or_else(|| starts_with("v1/node/peer_count"))
.or_else(|| starts_with("v1/node/syncing"))
.or_else(|| starts_with("v1/node/version"))
.or_else(|| starts_with("v1/node"))
.or_else(|| starts_with("v1/validator/aggregate_and_proofs"))
.or_else(|| starts_with("v2/validator/aggregate_and_proofs"))
.or_else(|| starts_with("v1/validator/aggregate_attestation"))
.or_else(|| starts_with("v2/validator/aggregate_attestation"))
.or_else(|| starts_with("v1/validator/attestation_data"))
.or_else(|| starts_with("v1/validator/beacon_committee_subscriptions"))
.or_else(|| starts_with("v1/validator/blinded_blocks"))
.or_else(|| starts_with("v2/validator/blinded_blocks"))
.or_else(|| starts_with("v1/validator/blocks"))
.or_else(|| starts_with("v2/validator/blocks"))
.or_else(|| starts_with("v3/validator/blocks"))
.or_else(|| starts_with("v1/validator/contribution_and_proofs"))
.or_else(|| starts_with("v1/validator/duties/attester"))
.or_else(|| starts_with("v1/validator/duties/proposer"))
.or_else(|| starts_with("v1/validator/duties/sync"))
.or_else(|| starts_with("v1/validator/liveness"))
.or_else(|| starts_with("v1/validator/prepare_beacon_proposer"))
.or_else(|| starts_with("v1/validator/register_validator"))
.or_else(|| starts_with("v1/validator/sync_committee_contribution"))
.or_else(|| starts_with("v1/validator/sync_committee_subscriptions"))
.or_else(|| starts_with("v1/validator/"))
.or_else(|| starts_with("v2/validator/"))
.or_else(|| starts_with("v3/validator/"))
.or_else(|| starts_with("lighthouse"))
.unwrap_or("other")
};

Expand All @@ -256,6 +287,38 @@ pub fn prometheus_metrics() -> warp::filters::log::Log<impl Fn(warp::filters::lo
})
}

/// Creates a `warp` logging wrapper which we use to create `tracing` logs.
pub fn tracing_logging() -> warp::filters::log::Log<impl Fn(warp::filters::log::Info) + Clone> {
warp::log::custom(move |info| {
let status = info.status();
// Ensure elapsed time is in milliseconds.
let elapsed = info.elapsed().as_secs_f64() * 1000.0;
let path = info.path();
let method = info.method().to_string();

if status == StatusCode::OK
|| status == StatusCode::NOT_FOUND
|| status == StatusCode::PARTIAL_CONTENT
{
debug!(
elapsed_ms = %elapsed,
status = %status,
path = %path,
method = %method,
"Processed HTTP API request"
);
} else {
warn!(
elapsed_ms = %elapsed,
status = %status,
path = %path,
method = %method,
"Error processing HTTP API request"
);
}
})
}

/// Creates a server that will serve requests using information from `ctx`.
///
/// The server will shut down gracefully when the `shutdown` future resolves.
Expand Down Expand Up @@ -4884,6 +4947,7 @@ pub fn serve<T: BeaconChainTypes>(
),
)
.recover(warp_utils::reject::handle_rejection)
.with(tracing_logging())
.with(prometheus_metrics())
// Add a `Server` header.
.map(|reply| warp::reply::with_header(reply, "Server", &version_with_platform()))
Expand Down
Loading