Skip to content

Commit e6e0282

Browse files
committed
chore: add api rate limit logs
1 parent 659c953 commit e6e0282

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

apps/block_scout_web/lib/block_scout_web/views/access_helper.ex

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,36 @@ defmodule BlockScoutWeb.AccessHelper do
8383

8484
cond do
8585
check_api_key(conn) && get_api_key(conn) == static_api_key ->
86+
Logger.info("check api key")
8687
rate_limit(static_api_key, limit_by_key, time_interval_limit)
8788

8889
check_api_key(conn) && !is_nil(plan) ->
90+
Logger.info("check api key with a plan")
91+
8992
conn
9093
|> get_api_key()
9194
|> rate_limit(plan.max_req_per_second, time_interval_limit)
9295

9396
Enum.member?(whitelisted_ips(rate_limit_config), ip_string) ->
94-
rate_limit(ip_string, limit_by_whitelisted_ip, time_interval_limit)
97+
Logger.info("check whitelisted ip")
98+
Logger.info("--> ip_string: #{inspect(ip_string)} <--")
99+
r = rate_limit(ip_string, limit_by_whitelisted_ip, time_interval_limit)
100+
Logger.info("whitelist IP result: #{inspect(r)} <--")
101+
r
95102

96103
api_v2_request?(conn) && !is_nil(token) && !is_nil(user_agent) ->
104+
Logger.info("check apiv2 with token & user_agent")
97105
rate_limit(token, api_v2_ui_limit, time_interval_limit)
98106

99107
api_v2_request?(conn) && !is_nil(user_agent) ->
108+
Logger.info("check apiv2 with token")
100109
rate_limit(ip_string, limit_by_ip, time_interval_by_ip)
101110

102111
true ->
103-
rate_limit("api", global_limit, time_interval_limit)
112+
Logger.info("check default rate")
113+
r = rate_limit("api", global_limit, time_interval_limit)
114+
Logger.info("default result: #{inspect(r)} <--")
115+
r
104116
end
105117
end
106118

0 commit comments

Comments
 (0)