Browse Source
Add extra details to rate limit logs
- Include the rate limit bucket for webhooks
- Enable `stack_info` for the 429 warning.
pull/8160/head
Nadir Chowdhury
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
13 additions and
5 deletions
-
discord/http.py
-
discord/webhook/async_.py
-
discord/webhook/sync.py
|
|
@ -471,7 +471,7 @@ class HTTPClient: |
|
|
|
|
|
|
|
# sleep a bit |
|
|
|
retry_after: float = data['retry_after'] |
|
|
|
_log.warning(fmt, retry_after, bucket) |
|
|
|
_log.warning(fmt, retry_after, bucket, stack_info=True) |
|
|
|
|
|
|
|
# check if it's a global rate limit |
|
|
|
is_global = data.get('global', False) |
|
|
|
|
|
@ -187,7 +187,10 @@ class AsyncWebhookAdapter: |
|
|
|
if remaining == '0' and response.status != 429: |
|
|
|
delta = utils._parse_ratelimit_header(response) |
|
|
|
_log.debug( |
|
|
|
'Webhook ID %s has been pre-emptively rate limited, waiting %.2f seconds', webhook_id, delta |
|
|
|
'Webhook ID %s has exhausted its rate limit bucket (bucket: %s, retry: %s).', |
|
|
|
webhook_id, |
|
|
|
bucket, |
|
|
|
delta, |
|
|
|
) |
|
|
|
lock.delay_by(delta) |
|
|
|
|
|
|
@ -197,9 +200,10 @@ class AsyncWebhookAdapter: |
|
|
|
if response.status == 429: |
|
|
|
if not response.headers.get('Via'): |
|
|
|
raise HTTPException(response, data) |
|
|
|
fmt = 'Webhook ID %s is rate limited. Retrying in %.2f seconds. Handled under the bucket %s' |
|
|
|
|
|
|
|
retry_after: float = data['retry_after'] # type: ignore |
|
|
|
_log.warning('Webhook ID %s is rate limited. Retrying in %.2f seconds', webhook_id, retry_after) |
|
|
|
_log.warning(fmt, webhook_id, retry_after, bucket, stack_info=True) |
|
|
|
await asyncio.sleep(retry_after) |
|
|
|
continue |
|
|
|
|
|
|
|
|
|
@ -188,7 +188,10 @@ class WebhookAdapter: |
|
|
|
if remaining == '0' and response.status_code != 429: |
|
|
|
delta = utils._parse_ratelimit_header(response) |
|
|
|
_log.debug( |
|
|
|
'Webhook ID %s has been pre-emptively rate limited, waiting %.2f seconds', webhook_id, delta |
|
|
|
'Webhook ID %s has exhausted its rate limit bucket (bucket: %s, retry: %s).', |
|
|
|
webhook_id, |
|
|
|
bucket, |
|
|
|
delta, |
|
|
|
) |
|
|
|
lock.delay_by(delta) |
|
|
|
|
|
|
@ -198,9 +201,10 @@ class WebhookAdapter: |
|
|
|
if response.status_code == 429: |
|
|
|
if not response.headers.get('Via'): |
|
|
|
raise HTTPException(response, data) |
|
|
|
fmt = 'Webhook ID %s is rate limited. Retrying in %.2f seconds. Handled under the bucket %s' |
|
|
|
|
|
|
|
retry_after: float = data['retry_after'] # type: ignore |
|
|
|
_log.warning('Webhook ID %s is rate limited. Retrying in %.2f seconds', webhook_id, retry_after) |
|
|
|
_log.warning(fmt, webhook_id, retry_after, stack_info=True) |
|
|
|
time.sleep(retry_after) |
|
|
|
continue |
|
|
|
|
|
|
|