Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn Down Logging for Auth Failures #153

Merged
merged 4 commits into from
Oct 18, 2024
Merged

Turn Down Logging for Auth Failures #153

merged 4 commits into from
Oct 18, 2024

Conversation

ric-evans
Copy link
Member

Bots normally hit the index path routinely (/). This should always fail due to invalid auth. However, this bloats the logs due to the current logging scheme.

Example:

2024-10-18 13:27:18.952 [   DEBUG] skydriver-rest-7f975b4f94-z7v29 rest[1] GET [MainHandler] <handler.py:172/prepare()>
2024-10-18 13:27:18.952 [   DEBUG] skydriver-rest-7f975b4f94-z7v29 root[1] routestats: [0.0005822181701660156, 0.0006031990051269531, 0.0007824897766113281] <stats.py:63/is_overloaded()>
2024-10-18 13:27:18.952 [    INFO] skydriver-rest-7f975b4f94-z7v29 rest[1] failed auth <handler.py:165/get_current_user()>
Traceback (most recent call last):
  File "/home/app/.local/lib/python3.11/site-packages/rest_tools/server/handler.py", line 153, in get_current_user
    type, token = self.request.headers['Authorization'].split(' ', 1)
                  ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/app/.local/lib/python3.11/site-packages/tornado/httputil.py", line 216, in __getitem__
    return self._dict[_normalize_header(name)]
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'Authorization'
2024-10-18 13:27:18.952 [ WARNING] skydriver-rest-7f975b4f94-z7v29 root[1] 403 GET / (10.42.2.126) 1.41ms <server.py:27/tornado_logger()>
2024-10-18 13:27:19.080 [    INFO] skydriver-rest-7f975b4f94-z7v29 tornado.general[1] Malformed HTTP message from 10.42.2.126: Malformed HTTP version in HTTP Request-Line: 'HTTP/2.0' <http1connection.py:292/_read_message()>

This PR removes the stack trace unless the "rest" logger is enabled for "debug" (at least).

Copy link
Contributor

@dsschult dsschult left a comment

Choose a reason for hiding this comment

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

One comment, otherwise looks good.


LOGGER = logging.getLogger('rest')


def _log_auth_failed(e: Exception):
LOGGER.warning('failed auth')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should just be info level?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure thing

@ric-evans ric-evans merged commit 29aebc7 into master Oct 18, 2024
28 checks passed
@ric-evans ric-evans deleted the when-auth-fails branch October 18, 2024 20:18
@ric-evans ric-evans added the enhancement New feature or request label Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants