From 5594bcb33ebf765ceb485a0bab52c386c4d7ed68 Mon Sep 17 00:00:00 2001 From: diegomrsantos Date: Tue, 30 Jan 2024 16:55:55 +0100 Subject: [PATCH] fix: more metrics issues when libp2p_expensive_metrics is enabled (#1016) --- libp2p/protocols/pubsub/gossipsub.nim | 5 ++++- libp2p/protocols/pubsub/pubsubpeer.nim | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libp2p/protocols/pubsub/gossipsub.nim b/libp2p/protocols/pubsub/gossipsub.nim index c8e756662..5740f5d8d 100644 --- a/libp2p/protocols/pubsub/gossipsub.nim +++ b/libp2p/protocols/pubsub/gossipsub.nim @@ -46,6 +46,9 @@ declareCounter(libp2p_gossipsub_saved_bytes, "bytes saved by gossipsub optimizat declareCounter(libp2p_gossipsub_duplicate, "number of duplicates received") declareCounter(libp2p_gossipsub_received, "number of messages received (deduplicated)") +when defined(libp2p_expensive_metrics): + declareCounter(libp2p_pubsub_received_messages, "number of messages received", labels = ["id", "topic"]) + proc init*(_: type[GossipSubParams]): GossipSubParams = GossipSubParams( explicit: true, @@ -428,7 +431,7 @@ method rpcHandler*(g: GossipSub, when defined(libp2p_expensive_metrics): for m in rpcMsg.messages: - for t in m.topicIDs: + for t in m.topicIds: libp2p_pubsub_received_messages.inc(labelValues = [$peer.peerId, t]) trace "decoded msg from peer", peer, msg = rpcMsg.shortLog diff --git a/libp2p/protocols/pubsub/pubsubpeer.nim b/libp2p/protocols/pubsub/pubsubpeer.nim index 0267affb6..75eec5f1c 100644 --- a/libp2p/protocols/pubsub/pubsubpeer.nim +++ b/libp2p/protocols/pubsub/pubsubpeer.nim @@ -28,7 +28,6 @@ logScope: when defined(libp2p_expensive_metrics): declareCounter(libp2p_pubsub_sent_messages, "number of messages sent", labels = ["id", "topic"]) - declareCounter(libp2p_pubsub_received_messages, "number of messages received", labels = ["id", "topic"]) declareCounter(libp2p_pubsub_skipped_received_messages, "number of received skipped messages", labels = ["id"]) declareCounter(libp2p_pubsub_skipped_sent_messages, "number of sent skipped messages", labels = ["id"]) @@ -224,7 +223,7 @@ proc hasSendConn*(p: PubSubPeer): bool = template sendMetrics(msg: RPCMsg): untyped = when defined(libp2p_expensive_metrics): for x in msg.messages: - for t in x.topicIDs: + for t in x.topicIds: # metrics libp2p_pubsub_sent_messages.inc(labelValues = [$p.peerId, t])