Skip to content

Log an error when auth rate limit is encountered#35

Merged
Michel Edkrantz (MichelEdkrantz) merged 1 commit intomasterfrom
log-rate-limiting
Apr 28, 2025
Merged

Log an error when auth rate limit is encountered#35
Michel Edkrantz (MichelEdkrantz) merged 1 commit intomasterfrom
log-rate-limiting

Conversation

@petern-annotell
Copy link
Copy Markdown
Contributor

Currently this fails in an obscure way when trying to log the response since it doesn't have the expiry. Since it's a 400-class error it isn't turned into an exception by OAuth2Client, and just kind of gets fumbled until it lands here:

  File "/usr/local/lib/python3.11/site-packages/kognic/auth/base/auth_client.py", line 12, in _log_new_token
    log.info(f"Got new token, with ttl={self.token['expires_in']} and expires {self.expires_at}")
                                        ~~~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'expires_in'

This PR adds a 'compliance hook' on the OAuth2 session that checks the response code and logs an error if the rate limit was hit.

This will not address the exception above, but provides some context in the logs. #34 will help with the bad error outcome.

Copy link
Copy Markdown

@AndersNordmark AndersNordmark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful

@MichelEdkrantz Michel Edkrantz (MichelEdkrantz) merged commit b84d97a into master Apr 28, 2025
7 checks passed
@MichelEdkrantz Michel Edkrantz (MichelEdkrantz) deleted the log-rate-limiting branch April 28, 2025 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants