Skip to content

Commit

Permalink
Introduce new gauge to help dasboard effectively show current rate li…
Browse files Browse the repository at this point in the history
…mit applied for protocol
  • Loading branch information
NagyZoltanPeter committed Sep 13, 2024
1 parent a25c0d4 commit fa46148
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 2 deletions.
12 changes: 11 additions & 1 deletion waku/common/rate_limit/service_metrics.nim
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
{.push raises: [].}

import metrics
import std/options
import metrics, setting

declarePublicGauge waku_service_requests_limit,
"Applied rate limit of non-relay service", ["service"]

declarePublicCounter waku_service_requests,
"number of non-relay service requests received", ["service", "state"]

declarePublicCounter waku_service_network_bytes,
"total incoming traffic of specific waku services", labels = ["service", "direction"]

proc setServiceLimitMetric*(service: string, limit: Option[RateLimitSetting]) =
if limit.isSome() and not limit.get().isUnlimited():
waku_service_requests_limit.set(
limit.get().calculateLimitPerSecond(), labelValues = [service]
)
5 changes: 5 additions & 0 deletions waku/common/rate_limit/setting.nim
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,8 @@ proc getSetting*(
): RateLimitSetting =
let default = t.getOrDefault(GLOBAL, UnlimitedRateLimit)
return t.getOrDefault(protocol, default)

proc calculateLimitPerSecond*(setting: RateLimitSetting): float64 =
if setting.isUnlimited():
return 0.float64
return (setting.volume.float64 / setting.period.milliseconds.float64) * 1000.float64
1 change: 1 addition & 0 deletions waku/waku_filter_v2/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ proc new*(
)

wf.initProtocolHandler()
setServiceLimitMetric(WakuFilterSubscribeCodec, rateLimitSetting)
return wf

const MaintainSubscriptionsInterval* = 1.minutes
Expand Down
1 change: 1 addition & 0 deletions waku/waku_lightpush/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@ proc new*(
requestRateLimiter: newRequestRateLimiter(rateLimitSetting),
)
wl.initProtocolHandler()
setServiceLimitMetric(WakuLightpushCodec, rateLimitSetting)
return wl
1 change: 1 addition & 0 deletions waku/waku_peer_exchange/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,6 @@ proc new*(
requestRateLimiter: newRequestRateLimiter(rateLimitSetting),
)
wpx.initProtocolHandler()
setServiceLimitMetric(WakuPeerExchangeCodec, rateLimitSetting)
asyncSpawn wpx.updatePxEnrCache()
return wpx
2 changes: 1 addition & 1 deletion waku/waku_store/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,5 @@ proc new*(
)

store.initProtocolHandler()

setServiceLimitMetric(WakuStoreCodec, rateLimitSetting)
return store
1 change: 1 addition & 0 deletions waku/waku_store_legacy/protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,5 @@ proc new*(
requestRateLimiter: newRequestRateLimiter(rateLimitSetting),
)
ws.initProtocolHandler()
setServiceLimitMetric(WakuLegacyStoreCodec, rateLimitSetting)
ws

0 comments on commit fa46148

Please sign in to comment.