From ffeeeeb3fbb49d39bdfd1d550b375ca73456f84f Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Thu, 10 Oct 2024 11:42:11 +0200 Subject: [PATCH] transport: add metrics Signed-off-by: Csaba Kiraly # Conflicts: # codexdht/private/eth/p2p/discoveryv5/transport.nim --- codexdht/private/eth/p2p/discoveryv5/transport.nim | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/codexdht/private/eth/p2p/discoveryv5/transport.nim b/codexdht/private/eth/p2p/discoveryv5/transport.nim index 8531918..ca39d6b 100644 --- a/codexdht/private/eth/p2p/discoveryv5/transport.nim +++ b/codexdht/private/eth/p2p/discoveryv5/transport.nim @@ -10,6 +10,7 @@ import bearssl/rand, chronos, chronicles, + metrics, libp2p/crypto/crypto, stew/shims/net, "."/[node, encoding, sessions] @@ -23,6 +24,11 @@ const logScope: topics = "discv5 transport" +declarePublicCounter discovery_transport_tx, + "Discovery transport messages sent", labels = ["state"] +declarePublicCounter discovery_transport_rx, + "Discovery transport messages received", labels = ["state"] + type Transport* [Client] = ref object client: Client @@ -56,7 +62,9 @@ proc sendToA(t: Transport, a: Address, msg: seq[byte]) = # nodes. Else the revalidation might end up clearing the routing tabl # because of ping failures due to own network connection failure. warn "Discovery send failed", msg = f.readError.msg + discovery_transport_tx.inc(labelValues = ["failed"]) ) + discovery_transport_tx.inc() proc send(t: Transport, n: Node, data: seq[byte]) = doAssert(n.address.isSome()) @@ -144,6 +152,7 @@ proc sendPending(t:Transport, toNode: Node): t.pendingRequestsByNode.del(toNode.id) proc receive*(t: Transport, a: Address, packet: openArray[byte]) = + discovery_transport_rx.inc() let decoded = t.codec.decodePacket(a, packet) if decoded.isOk: let packet = decoded[] @@ -215,6 +224,7 @@ proc receive*(t: Transport, a: Address, packet: openArray[byte]) = else: trace "address mismatch, not adding seen flag", node, address = a, nodeAddress = node.address.get() else: + discovery_transport_rx.inc(labelValues = ["failed_decode"]) trace "Packet decoding error", myport = t.bindAddress.port, error = decoded.error, address = a proc processClient[T](transp: DatagramTransport, raddr: TransportAddress):