Add metrics to rate limiter
This commit is contained in:
@@ -69,6 +69,16 @@ defmodule MusicLibraryWeb.Telemetry do
|
||||
]
|
||||
),
|
||||
|
||||
# Rate Limiter
|
||||
summary("req.rate_limiter.throttle.sleep_ms",
|
||||
unit: :millisecond,
|
||||
description: "Time spent waiting for rate limit cooldown",
|
||||
tags: [:name],
|
||||
reporter_options: [
|
||||
nav: "External APIs"
|
||||
]
|
||||
),
|
||||
|
||||
# Assets
|
||||
summary("music_library.assets.cache_size",
|
||||
unit: {:byte, :kilobyte},
|
||||
|
||||
@@ -56,6 +56,12 @@ defmodule Req.RateLimiter do
|
||||
remaining = cooldown - elapsed
|
||||
|
||||
if remaining > 0 do
|
||||
:telemetry.execute(
|
||||
[:req, :rate_limiter, :throttle],
|
||||
%{sleep_ms: remaining},
|
||||
%{name: name}
|
||||
)
|
||||
|
||||
Process.sleep(remaining)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user