Fix missing labels for Portal wire protocol metrics (#1916)

This commit is contained in:
Kim De Mey 2023-12-01 14:59:17 +01:00 committed by GitHub
parent 49d6c5728b
commit d4fc234e53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 9 deletions

View File

@ -344,7 +344,8 @@ proc handleFindNodes(p: PortalProtocol, fn: FindNodesMessage): seq[byte] =
enrOverhead = 4 # per added ENR, 4 bytes offset overhead enrOverhead = 4 # per added ENR, 4 bytes offset overhead
let enrs = truncateEnrs(nodes, maxPayloadSize, enrOverhead) let enrs = truncateEnrs(nodes, maxPayloadSize, enrOverhead)
portal_nodes_enrs_packed.observe(enrs.len().int64) portal_nodes_enrs_packed.observe(
enrs.len().int64, labelValues = [$p.protocolId])
encodeMessage(NodesMessage(total: 1, enrs: enrs)) encodeMessage(NodesMessage(total: 1, enrs: enrs))
else: else:
@ -389,7 +390,8 @@ proc handleFindContent(
closestNodes = p.routingTable.neighbours( closestNodes = p.routingTable.neighbours(
NodeId(contentId), seenOnly = true) NodeId(contentId), seenOnly = true)
enrs = truncateEnrs(closestNodes, maxPayloadSize, enrOverhead) enrs = truncateEnrs(closestNodes, maxPayloadSize, enrOverhead)
portal_content_enrs_packed.observe(enrs.len().int64) portal_content_enrs_packed.observe(
enrs.len().int64, labelValues = [$p.protocolId])
encodeMessage(ContentMessage(contentMessageType: enrsType, enrs: enrs)) encodeMessage(ContentMessage(contentMessageType: enrsType, enrs: enrs))
@ -787,7 +789,8 @@ proc offer(p: PortalProtocol, o: OfferRequest):
debug "Offering content" debug "Offering content"
portal_content_keys_offered.observe(contentKeys.len().int64) portal_content_keys_offered.observe(
contentKeys.len().int64, labelValues = [$p.protocolId])
let acceptMessageResponse = await p.offerImpl(o.dst, contentKeys) let acceptMessageResponse = await p.offerImpl(o.dst, contentKeys)
@ -808,7 +811,8 @@ proc offer(p: PortalProtocol, o: OfferRequest):
return err("Accepted content key bitlist has invalid size") return err("Accepted content key bitlist has invalid size")
let acceptedKeysAmount = m.contentKeys.countOnes() let acceptedKeysAmount = m.contentKeys.countOnes()
portal_content_keys_accepted.observe(acceptedKeysAmount.int64) portal_content_keys_accepted.observe(
acceptedKeysAmount.int64, labelValues = [$p.protocolId])
if acceptedKeysAmount == 0: if acceptedKeysAmount == 0:
debug "No content accepted" debug "No content accepted"
# Don't open an uTP stream if no content was requested # Don't open an uTP stream if no content was requested
@ -980,7 +984,8 @@ proc lookup*(p: PortalProtocol, target: NodeId): Future[seq[Node]] {.async.} =
if closestNodes.len > BUCKET_SIZE: if closestNodes.len > BUCKET_SIZE:
closestNodes.del(closestNodes.high()) closestNodes.del(closestNodes.high())
portal_lookup_node_requests.observe(requestAmount) portal_lookup_node_requests.observe(
requestAmount, labelValues = [$p.protocolId])
p.lastLookup = now(chronos.Moment) p.lastLookup = now(chronos.Moment)
return closestNodes return closestNodes
@ -1094,7 +1099,8 @@ proc contentLookup*(p: PortalProtocol, target: ByteList, targetId: UInt256):
# cancel any pending queries as the content has been found # cancel any pending queries as the content has been found
for f in pendingQueries: for f in pendingQueries:
f.cancelSoon() f.cancelSoon()
portal_lookup_content_requests.observe(requestAmount) portal_lookup_content_requests.observe(
requestAmount, labelValues = [$p.protocolId])
return Opt.some(ContentLookupResult.init( return Opt.some(ContentLookupResult.init(
content.content, content.utpTransfer, nodesWithoutContent)) content.content, content.utpTransfer, nodesWithoutContent))
else: else:
@ -1102,7 +1108,7 @@ proc contentLookup*(p: PortalProtocol, target: ByteList, targetId: UInt256):
# query? # query?
discard discard
portal_lookup_content_failures.inc() portal_lookup_content_failures.inc(labelValues = [$p.protocolId])
return Opt.none(ContentLookupResult) return Opt.none(ContentLookupResult)
proc traceContentLookup*(p: PortalProtocol, target: ByteList, targetId: UInt256): proc traceContentLookup*(p: PortalProtocol, target: ByteList, targetId: UInt256):
@ -1238,7 +1244,8 @@ proc traceContentLookup*(p: PortalProtocol, target: ByteList, targetId: UInt256)
# cancel any pending queries as the content has been found # cancel any pending queries as the content has been found
for f in pendingQueries: for f in pendingQueries:
f.cancelSoon() f.cancelSoon()
portal_lookup_content_requests.observe(requestAmount) portal_lookup_content_requests.observe(
requestAmount, labelValues = [$p.protocolId])
let distance = p.distance(content.src.id, targetId) let distance = p.distance(content.src.id, targetId)
@ -1279,7 +1286,7 @@ proc traceContentLookup*(p: PortalProtocol, target: ByteList, targetId: UInt256)
# query? # query?
discard discard
portal_lookup_content_failures.inc() portal_lookup_content_failures.inc(labelValues = [$p.protocolId])
return TraceContentLookupResult( return TraceContentLookupResult(
content: Opt.none(seq[byte]), content: Opt.none(seq[byte]),
utpTransfer: false, utpTransfer: false,