From a603ab51445f91362e9516729eb3d1b7081fa86f Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Tue, 21 Jul 2020 11:07:46 +0200 Subject: [PATCH] Add sync_legacy_requests_received metric --- client/network/src/protocol.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index 626cb04389236..d606a1be989c4 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -142,6 +142,7 @@ struct Metrics { finality_proofs: GaugeVec, justifications: GaugeVec, propagated_transactions: Counter, + legacy_requests_received: Counter, } impl Metrics { @@ -187,6 +188,10 @@ impl Metrics { "sync_propagated_transactions", "Number of transactions propagated to at least one peer", )?, r)?, + legacy_requests_received: register(Counter::new( + "sync_legacy_requests_received", + "Number of block/finality/light-client requests received on the legacy substream", + )?, r)?, }) } } @@ -715,6 +720,10 @@ impl Protocol { } fn on_block_request(&mut self, peer: PeerId, request: message::BlockRequest) { + if let Some(metrics) = &self.metrics { + metrics.legacy_requests_received.inc(); + } + trace!(target: "sync", "BlockRequest {} from {}: from {:?} to {:?} max {:?} for {:?}", request.id, peer, @@ -1399,6 +1408,11 @@ impl Protocol { request.method, request.block ); + + if let Some(metrics) = &self.metrics { + metrics.legacy_requests_received.inc(); + } + let proof = match self.context_data.chain.execution_proof( &BlockId::Hash(request.block), &request.method, @@ -1519,6 +1533,10 @@ impl Protocol { who: PeerId, request: message::RemoteReadRequest, ) { + if let Some(metrics) = &self.metrics { + metrics.legacy_requests_received.inc(); + } + if request.keys.is_empty() { debug!(target: "sync", "Invalid remote read request sent by {}", who); self.behaviour.disconnect_peer(&who); @@ -1568,6 +1586,10 @@ impl Protocol { who: PeerId, request: message::RemoteReadChildRequest, ) { + if let Some(metrics) = &self.metrics { + metrics.legacy_requests_received.inc(); + } + if request.keys.is_empty() { debug!(target: "sync", "Invalid remote child read request sent by {}", who); self.behaviour.disconnect_peer(&who); @@ -1624,6 +1646,10 @@ impl Protocol { who: PeerId, request: message::RemoteHeaderRequest>, ) { + if let Some(metrics) = &self.metrics { + metrics.legacy_requests_received.inc(); + } + trace!(target: "sync", "Remote header proof request {} from {} ({})", request.id, who, request.block); let (header, proof) = match self.context_data.chain.header_proof(&BlockId::Number(request.block)) { @@ -1654,6 +1680,10 @@ impl Protocol { who: PeerId, request: message::RemoteChangesRequest, ) { + if let Some(metrics) = &self.metrics { + metrics.legacy_requests_received.inc(); + } + trace!(target: "sync", "Remote changes proof request {} from {} for key {} ({}..{})", request.id, who, @@ -1717,6 +1747,10 @@ impl Protocol { who: PeerId, request: message::FinalityProofRequest, ) { + if let Some(metrics) = &self.metrics { + metrics.legacy_requests_received.inc(); + } + trace!(target: "sync", "Finality proof request from {} for {}", who, request.block); let finality_proof = self.finality_proof_provider.as_ref() .ok_or_else(|| String::from("Finality provider is not configured"))