Skip to content

Commit

Permalink
Fix review findings, added limit to debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
NagyZoltanPeter committed May 9, 2024
1 parent 5ffa3fe commit 8855227
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
8 changes: 7 additions & 1 deletion waku/common/ratelimit.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ proc newTokenBucket*(setting: Option[RateLimitSetting]): Option[TokenBucket] =

proc checkUsage(
t: var Option[TokenBucket], proto: string, conn: Connection
): bool {.raises: [Defect].} =
): bool {.raises: [].} =
if t.isNone():
return true

Expand All @@ -48,3 +48,9 @@ template checkUsageLimit*(
else:
waku_service_requests_rejected.inc(labelValues = [proto])
bodyRejected

func `$`*(ob: Option[TokenBucket]): string {.inline.} =
if ob.isNone():
return "no-limit"

return $ob.get()
3 changes: 3 additions & 0 deletions waku/common/tokenbucket.nim
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ proc new*(T: type[TokenBucket], budgetCap: int, fillDuration: Duration = 1.secon
fillDuration: fillDuration,
lastTimeFull: Moment.now(),
)

func `$`*(b: TokenBucket): string {.inline.} =
return $b.budgetCap & "/" & $b.fillDuration
3 changes: 2 additions & 1 deletion waku/waku_lightpush/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ proc initProtocolHandler(wl: WakuLightPush) =

rpc = await handleRequest(wl, conn.peerId, buffer)
do:
debug "lightpush request rejected due rate limit exceeded", peerId = conn.peerId
debug "lightpush request rejected due rate limit exceeded",
peerId = conn.peerId, limit = $wl.requestRateLimiter

rpc = static(
PushRPC(
Expand Down
3 changes: 2 additions & 1 deletion waku/waku_store/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ proc initProtocolHandler(self: WakuStore) =

resBuf = await self.handleQueryRequest(conn.peerId, reqBuf)
do:
debug "store query request rejected due rate limit exceeded", peerId = conn.peerId
debug "store query request rejected due rate limit exceeded",
peerId = conn.peerId, limit = $self.requestRateLimiter
resBuf = rejectReposnseBuffer

let writeRes = catch:
Expand Down
2 changes: 1 addition & 1 deletion waku/waku_store_legacy/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ proc initProtocolHandler(ws: WakuStore) =
resBuf = await ws.handleLegacyQueryRequest(conn.peerId, reqBuf)
do:
debug "Legacy store query request rejected due rate limit exceeded",
peerId = conn.peerId
peerId = conn.peerId, limit = $ws.requestRateLimiter
resBuf = rejectResponseBuf

let writeRes = catch:
Expand Down

0 comments on commit 8855227

Please sign in to comment.