MemcacheRing raises AttributeError when initialised with default logger

Bug #2003345 reported by Alistair Coles
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Object Storage (swift)
Confirmed
Undecided
Unassigned

Bug Description

Since https://review.opendev.org/c/openstack/swift/+/869390 the swift.common.memcached.MemcacheRing class is broken unless it is given an adapted logger instance when constructed.

If no logger is passed to the MemcacheRing constructor it defaults to using logging.getLogger() which does not support the metrics methods (e.g. timing_since) that are called by the memcached_timing_stats decorator. The metric methods are provided by swift.common.utils.LogAdpter.

To reproduce:

```
$ python
Python 3.8.10 (default, Nov 14 2022, 12:59:47)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import swift.common.memcached as m
>>> m.MemcacheRing([])
<swift.common.memcached.MemcacheRing object at 0xffff7fc93070>
>>> m.get('x')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'swift.common.memcached' has no attribute 'get'
>>> mr = m.MemcacheRing([])
>>> mr.get('x')
All memcached servers error-limited
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/vagrant/swift/swift/common/utils.py", line 2050, in _timing_stats
    cache.logger.timing_since(
AttributeError: 'RootLogger' object has no attribute 'timing_since'
```

To fix, either ensure the default logger is an instance of LogAdapter, or make the decorator calls conditional on logger being of type LogAdpater.

Revision history for this message
Tim Burke (1-tim-z) wrote :

Bah, sorry -- I had pushed up a guarded version at one point [1], but grew less concerned upon realizing the only in-tree place that we'd trip it would be probe tests. One question I've got: how much of a "public" API do we want to make this? We know we have some external tooling that want to use MemcacheRing -- what sorts of tests do we want to make sure we don't accidentally introduce another breaking change?

[1] https://review.opendev.org/c/openstack/swift/+/869390/6/swift/common/utils.py

Changed in swift:
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.