Add more message related metrics

This commit is contained in:
kdeme 2021-01-13 21:44:17 +01:00
parent aa7442c9ff
commit 181bbadcbc
No known key found for this signature in database
GPG Key ID: 4E8DD21420AF43F5
1 changed files with 16 additions and 6 deletions

View File

@ -85,8 +85,12 @@ export options
{.push raises: [Defect].} {.push raises: [Defect].}
declarePublicGauge discovery_message_requests, declarePublicGauge discovery_message_requests_outgoing,
"Discovery protocol message requests", labels = ["response"] "Discovery protocol outgoing message requests", labels = ["response"]
declarePublicGauge discovery_message_requests_incoming,
"Discovery protocol incoming message requests", labels = ["response"]
declarePublicGauge discovery_unsolicited_messages,
"Discovery protocol unsolicited or timed-out messages"
logScope: logScope:
topics = "discv5" topics = "discv5"
@ -311,12 +315,17 @@ proc handleMessage(d: Protocol, srcId: NodeId, fromAddr: Address,
message: Message) {.raises:[Exception].} = message: Message) {.raises:[Exception].} =
case message.kind case message.kind
of ping: of ping:
discovery_message_requests_incoming.inc()
d.handlePing(srcId, fromAddr, message.ping, message.reqId) d.handlePing(srcId, fromAddr, message.ping, message.reqId)
of findNode: of findNode:
discovery_message_requests_incoming.inc()
d.handleFindNode(srcId, fromAddr, message.findNode, message.reqId) d.handleFindNode(srcId, fromAddr, message.findNode, message.reqId)
of talkreq: of talkreq:
discovery_message_requests_incoming.inc()
d.handleTalkReq(srcId, fromAddr, message.talkreq, message.reqId) d.handleTalkReq(srcId, fromAddr, message.talkreq, message.reqId)
of regtopic, topicquery: of regtopic, topicquery:
discovery_message_requests_incoming.inc()
discovery_message_requests_incoming.inc(labelValues = ["no_response"])
trace "Received unimplemented message kind", kind = message.kind, trace "Received unimplemented message kind", kind = message.kind,
origin = fromAddr origin = fromAddr
else: else:
@ -324,6 +333,7 @@ proc handleMessage(d: Protocol, srcId: NodeId, fromAddr: Address,
if d.awaitedMessages.take((srcId, message.reqId), waiter): if d.awaitedMessages.take((srcId, message.reqId), waiter):
waiter.complete(some(message)) # TODO: raises: [Exception] waiter.complete(some(message)) # TODO: raises: [Exception]
else: else:
discovery_unsolicited_messages.inc()
trace "Timed out or unrequested message", kind = message.kind, trace "Timed out or unrequested message", kind = message.kind,
origin = fromAddr origin = fromAddr
@ -584,7 +594,7 @@ proc sendMessage*[T: SomeMessage](d: Protocol, toNode: Node, m: T):
d.registerRequest(toNode, message, nonce) d.registerRequest(toNode, message, nonce)
trace "Send message packet", dstId = toNode.id, address, kind = messageKind(T) trace "Send message packet", dstId = toNode.id, address, kind = messageKind(T)
d.send(toNode, data) d.send(toNode, data)
discovery_message_requests.inc() discovery_message_requests_outgoing.inc()
return reqId return reqId
proc ping*(d: Protocol, toNode: Node): proc ping*(d: Protocol, toNode: Node):
@ -601,7 +611,7 @@ proc ping*(d: Protocol, toNode: Node):
return ok(resp.get().pong) return ok(resp.get().pong)
else: else:
d.replaceNode(toNode) d.replaceNode(toNode)
discovery_message_requests.inc(labelValues = ["timed_out"]) discovery_message_requests_outgoing.inc(labelValues = ["no_response"])
return err("Pong message not received in time") return err("Pong message not received in time")
proc findNode*(d: Protocol, toNode: Node, distances: seq[uint32]): proc findNode*(d: Protocol, toNode: Node, distances: seq[uint32]):
@ -619,7 +629,7 @@ proc findNode*(d: Protocol, toNode: Node, distances: seq[uint32]):
return ok(res) return ok(res)
else: else:
d.replaceNode(toNode) d.replaceNode(toNode)
discovery_message_requests.inc(labelValues = ["timed_out"]) discovery_message_requests_outgoing.inc(labelValues = ["no_response"])
return err(nodes.error) return err(nodes.error)
proc talkreq*(d: Protocol, toNode: Node, protocol, request: seq[byte]): proc talkreq*(d: Protocol, toNode: Node, protocol, request: seq[byte]):
@ -636,7 +646,7 @@ proc talkreq*(d: Protocol, toNode: Node, protocol, request: seq[byte]):
return ok(resp.get().talkresp) return ok(resp.get().talkresp)
else: else:
d.replaceNode(toNode) d.replaceNode(toNode)
discovery_message_requests.inc(labelValues = ["timed_out"]) discovery_message_requests_outgoing.inc(labelValues = ["no_response"])
return err("Talk response message not received in time") return err("Talk response message not received in time")
proc lookupDistances(target, dest: NodeId): seq[uint32] {.raises: [Defect].} = proc lookupDistances(target, dest: NodeId): seq[uint32] {.raises: [Defect].} =