mirror of
https://github.com/simple-login/app.git
synced 2024-11-17 17:35:20 +01:00
Add metrics to rate limit (#2029)
This commit is contained in:
parent
05d18c23cc
commit
59d000d330
1 changed files with 5 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
import newrelic.agent
|
||||||
import redis.exceptions
|
import redis.exceptions
|
||||||
import werkzeug.exceptions
|
import werkzeug.exceptions
|
||||||
from limits.storage import RedisStorage
|
from limits.storage import RedisStorage
|
||||||
|
@ -28,6 +29,10 @@ def check_bucket_limit(
|
||||||
try:
|
try:
|
||||||
value = lock_redis.incr(bucket_lock_name, bucket_seconds)
|
value = lock_redis.incr(bucket_lock_name, bucket_seconds)
|
||||||
if value > max_hits:
|
if value > max_hits:
|
||||||
|
newrelic.agent.record_custom_event(
|
||||||
|
"BucketRateLimit",
|
||||||
|
{"lock_name": lock_name, "bucket_seconds": bucket_seconds},
|
||||||
|
)
|
||||||
raise werkzeug.exceptions.TooManyRequests()
|
raise werkzeug.exceptions.TooManyRequests()
|
||||||
except (redis.exceptions.RedisError, AttributeError):
|
except (redis.exceptions.RedisError, AttributeError):
|
||||||
log.e("Cannot connect to redis")
|
log.e("Cannot connect to redis")
|
||||||
|
|
Loading…
Reference in a new issue