From beb8583436ccf33c56d1a31bd261cb9e5bf93ccf Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Thu, 16 Dec 2021 16:50:14 -0300 Subject: [PATCH] change colliding bits metric to gauge --- lbry/dht/protocol/routing_table.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lbry/dht/protocol/routing_table.py b/lbry/dht/protocol/routing_table.py index c0e1f77b9..344158a95 100644 --- a/lbry/dht/protocol/routing_table.py +++ b/lbry/dht/protocol/routing_table.py @@ -4,7 +4,7 @@ import logging import typing import itertools -from prometheus_client import Gauge, Counter +from prometheus_client import Gauge from lbry.dht import constants from lbry.dht.protocol.distance import Distance @@ -22,7 +22,7 @@ class KBucket: "peers_in_routing_table", "Number of peers on routing table", namespace="dht_node", labelnames=("scope",) ) - peer_with_x_bit_colliding_metric = Counter( + peer_with_x_bit_colliding_metric = Gauge( "peer_x_bit_colliding", "Number of peers with at least X bits colliding with this node id", namespace="dht_node", labelnames=("amount",) ) @@ -140,6 +140,9 @@ class KBucket: def remove_peer(self, peer: 'KademliaPeer') -> None: self.peers.remove(peer) self.peer_in_routing_table_metric.labels("global").dec() + if peer.node_id[0] == self._node_id[0]: + bits_colliding = 8 - (peer.node_id[1] ^ self._node_id[1]).bit_length() + self.peer_with_x_bit_colliding_metric.labels(amount=(bits_colliding + 8)).dec() def key_in_range(self, key: bytes) -> bool: """ Tests whether the specified key (i.e. node ID) is in the range