Skip to content

pool: Handle non-shard-aware endpoints in logging #398

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

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

tchaikov
Copy link

@tchaikov tchaikov commented Jan 3, 2025

When connecting to non-shard-aware endpoints, conn.features.shard_id is None. Previously, this would cause a TypeError when logging with %i format specifier.

  Traceback (most recent call last):
    File "/usr/lib64/python3.12/logging/__init__.py", line 1160, in emit
      msg = self.format(record)
            ^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.12/logging/__init__.py", line 999, in format
      return fmt.format(record)
             ^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3.12/site-packages/_pytest/logging.py", line 136, in format
      return super().format(record)
             ^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.12/logging/__init__.py", line 703, in format
      record.message = record.getMessage()
                       ^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.12/logging/__init__.py", line 392, in getMessage
      msg = msg % self.args
            ~~~~^~~~~~~~~~~
  TypeError: %i format: a real number is required, not NoneType
  Call stack:
    File "/usr/lib64/python3.12/threading.py", line 1032, in _bootstrap
      self._bootstrap_inner()
    File "/usr/lib64/python3.12/threading.py", line 1075, in _bootstrap_inner
      self.run()
    File "/usr/lib64/python3.12/threading.py", line 1012, in run
      self._target(*self._args, **self._kwargs)
    File "/usr/lib64/python3.12/concurrent/futures/thread.py", line 92, in _worker
      work_item.run()
    File "/usr/lib64/python3.12/concurrent/futures/thread.py", line 58, in run
      result = self.fn(*self.args, **self.kwargs)
  Message: 'Received a connection %s for shard_id=%i on host %s'
  Arguments: (140333813254336, None, <Host: 127.67.173.34:9042 dc2>)

Now prints -1 as a fallback value instead of raising an exception.

This fixes logging failures that occurred when:

  • Connecting to non-shard-aware endpoints
  • Debug logging level was enabled

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

Sorry, something went wrong.

When connecting to non-shard-aware endpoints, conn.features.shard_id is None.
Previously, this would cause a TypeError when logging with %i format specifier.

```
  Traceback (most recent call last):
    File "/usr/lib64/python3.12/logging/__init__.py", line 1160, in emit
      msg = self.format(record)
            ^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.12/logging/__init__.py", line 999, in format
      return fmt.format(record)
             ^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3.12/site-packages/_pytest/logging.py", line 136, in format
      return super().format(record)
             ^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.12/logging/__init__.py", line 703, in format
      record.message = record.getMessage()
                       ^^^^^^^^^^^^^^^^^^^
    File "/usr/lib64/python3.12/logging/__init__.py", line 392, in getMessage
      msg = msg % self.args
            ~~~~^~~~~~~~~~~
  TypeError: %i format: a real number is required, not NoneType
  Call stack:
    File "/usr/lib64/python3.12/threading.py", line 1032, in _bootstrap
      self._bootstrap_inner()
    File "/usr/lib64/python3.12/threading.py", line 1075, in _bootstrap_inner
      self.run()
    File "/usr/lib64/python3.12/threading.py", line 1012, in run
      self._target(*self._args, **self._kwargs)
    File "/usr/lib64/python3.12/concurrent/futures/thread.py", line 92, in _worker
      work_item.run()
    File "/usr/lib64/python3.12/concurrent/futures/thread.py", line 58, in run
      result = self.fn(*self.args, **self.kwargs)
  Message: 'Received a connection %s for shard_id=%i on host %s'
  Arguments: (140333813254336, None, <Host: 127.67.173.34:9042 dc2>)
```

Now prints -1 as a fallback value instead of raising an exception.

This fixes logging failures that occurred when:
- Connecting to non-shard-aware endpoints
- Debug logging level was enabled

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
@tchaikov
Copy link
Author

tchaikov commented Jan 3, 2025

see https://jenkins.scylladb.com/job/scylla-master/job/scylla-ci/14179/consoleFull for an example of the error addressed by this change.

@dkropachev dkropachev merged commit d62eb38 into scylladb:master Jan 3, 2025
19 of 21 checks passed
@tchaikov tchaikov deleted the shard-unware-conn branch January 3, 2025 12:04
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.

None yet

2 participants