add requests in flight and error

This commit is contained in:
Victor Shyba 2021-12-13 04:40:44 -03:00
parent d359d25935
commit 273b4f6d3b

View file

@ -276,6 +276,14 @@ class KademliaProtocol(DatagramProtocol):
"request_success", "Number of successful requests", namespace="dht_node", "request_success", "Number of successful requests", namespace="dht_node",
labelnames=("method",), labelnames=("method",),
) )
request_flight_metric = Gauge(
"request_flight", "Number of ongoing requests", namespace="dht_node",
labelnames=("method",),
)
request_error_metric = Counter(
"request_error", "Number of errors returned from request to other peers", namespace="dht_node",
labelnames=("method",),
)
HISTOGRAM_BUCKETS = ( HISTOGRAM_BUCKETS = (
.005, .01, .025, .05, .075, .1, .25, .5, .75, 1.0, 2.5, 3.0, 3.5, 4.0, 4.50, 5.0, 5.50, 6.0, float('inf') .005, .01, .025, .05, .075, .1, .25, .5, .75, 1.0, 2.5, 3.0, 3.5, 4.0, 4.50, 5.0, 5.50, 6.0, float('inf')
) )
@ -606,6 +614,7 @@ class KademliaProtocol(DatagramProtocol):
response_fut = self.sent_messages[request.rpc_id][1] response_fut = self.sent_messages[request.rpc_id][1]
try: try:
self.request_sent_metric.labels(method=request.method).inc() self.request_sent_metric.labels(method=request.method).inc()
self.request_flight_metric.labels(method=request.method).inc()
start = time.perf_counter() start = time.perf_counter()
response = await asyncio.wait_for(response_fut, self.rpc_timeout) response = await asyncio.wait_for(response_fut, self.rpc_timeout)
self.response_time_metric.labels(method=request.method).observe(time.perf_counter() - start) self.response_time_metric.labels(method=request.method).observe(time.perf_counter() - start)
@ -617,10 +626,13 @@ class KademliaProtocol(DatagramProtocol):
response_fut.cancel() response_fut.cancel()
raise raise
except (asyncio.TimeoutError, RemoteException): except (asyncio.TimeoutError, RemoteException):
self.request_error_metric.labels(method=request.method).inc()
self.peer_manager.report_failure(peer.address, peer.udp_port) self.peer_manager.report_failure(peer.address, peer.udp_port)
if self.peer_manager.peer_is_good(peer) is False: if self.peer_manager.peer_is_good(peer) is False:
self.remove_peer(peer) self.remove_peer(peer)
raise raise
finally:
self.request_flight_metric.labels(method=request.method).dec()
def send_response(self, peer: 'KademliaPeer', response: ResponseDatagram): def send_response(self, peer: 'KademliaPeer', response: ResponseDatagram):
self._send(peer, response) self._send(peer, response)