Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: non-relay protocols cross performance measurement metrics #3299

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions waku/common/rate_limit/request_limiter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@ template checkUsageLimit*(
bodyWithinLimit, bodyRejected: untyped,
) =
if t.checkUsage(proto, conn):
let requestStartTime = Moment.now()
waku_service_requests.inc(labelValues = [proto, "served"])

bodyWithinLimit

let requestDurationSec = (Moment.now() - requestStartTime).milliseconds.float / 1000
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely not needed but just in case :)?

Suggested change
let requestDurationSec = (Moment.now() - requestStartTime).milliseconds.float / 1000
let requestDurationSec: float = (Moment.now() - requestStartTime).milliseconds.float / 1000

Aside from this comment, I think it would be useful to rename the rejected case to rejected-rate-limit, or something like that

waku_service_request_handling_duration_seconds.observe(
requestDurationSec, labelValues = [proto]
)
else:
waku_service_requests.inc(labelValues = [proto, "rejected"])
bodyRejected
Expand Down
3 changes: 3 additions & 0 deletions waku/common/rate_limit/service_metrics.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 7 additions & 0 deletions waku/common/rate_limit/single_token_limiter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ template checkUsageLimit*(
bodyWithinLimit, bodyRejected: untyped,
) =
if t.checkUsage(proto):
let requestStartTime = Moment.now()
waku_service_requests.inc(labelValues = [proto, "served"])

bodyWithinLimit

let requestDurationSec = (Moment.now() - requestStartTime).milliseconds.float / 1000
waku_service_request_handling_duration_seconds.observe(
requestDurationSec, labelValues = [proto]
)
else:
waku_service_requests.inc(labelValues = [proto, "rejected"])
bodyRejected
Loading