mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-02 14:03:06 +00:00
chore: non-relay protocols cross performance measurement metrics (#3299)
* Introducing new non-relay protocol request handling time metric
This commit is contained in:
parent
fca3b034c2
commit
36ee2aa9bf
@ -22,6 +22,8 @@ import
|
||||
libp2p/stream/connection,
|
||||
libp2p/utility
|
||||
|
||||
import std/times except TimeInterval, Duration, seconds, minutes
|
||||
|
||||
import ./[single_token_limiter, service_metrics, timed_map]
|
||||
|
||||
export token_bucket, setting, service_metrics
|
||||
@ -76,8 +78,15 @@ template checkUsageLimit*(
|
||||
bodyWithinLimit, bodyRejected: untyped,
|
||||
) =
|
||||
if t.checkUsage(proto, conn):
|
||||
let requestStartTime = getTime().toUnixFloat()
|
||||
waku_service_requests.inc(labelValues = [proto, "served"])
|
||||
|
||||
bodyWithinLimit
|
||||
|
||||
let requestDurationSec = getTime().toUnixFloat() - requestStartTime
|
||||
waku_service_request_handling_duration_seconds.observe(
|
||||
requestDurationSec, labelValues = [proto]
|
||||
)
|
||||
else:
|
||||
waku_service_requests.inc(labelValues = [proto, "rejected"])
|
||||
bodyRejected
|
||||
|
||||
@ -17,3 +17,6 @@ proc setServiceLimitMetric*(service: string, limit: Option[RateLimitSetting]) =
|
||||
waku_service_requests_limit.set(
|
||||
limit.get().calculateLimitPerSecond(), labelValues = [service]
|
||||
)
|
||||
|
||||
declarePublicHistogram waku_service_request_handling_duration_seconds,
|
||||
"duration of non-relay service handling", ["service"]
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
|
||||
import std/[options], chronos/timer, libp2p/stream/connection, libp2p/utility
|
||||
|
||||
import std/times except TimeInterval, Duration
|
||||
|
||||
import ./[token_bucket, setting, service_metrics]
|
||||
export token_bucket, setting, service_metrics
|
||||
|
||||
@ -43,8 +45,15 @@ template checkUsageLimit*(
|
||||
bodyWithinLimit, bodyRejected: untyped,
|
||||
) =
|
||||
if t.checkUsage(proto):
|
||||
let requestStartTime = getTime().toUnixFloat()
|
||||
waku_service_requests.inc(labelValues = [proto, "served"])
|
||||
|
||||
bodyWithinLimit
|
||||
|
||||
let requestDurationSec = getTime().toUnixFloat() - requestStartTime
|
||||
waku_service_request_handling_duration_seconds.observe(
|
||||
requestDurationSec, labelValues = [proto]
|
||||
)
|
||||
else:
|
||||
waku_service_requests.inc(labelValues = [proto, "rejected"])
|
||||
bodyRejected
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user