Merge "Do not un-patch threading"

This commit is contained in:
Zuul 2025-04-05 15:26:55 +00:00 committed by Gerrit Code Review
commit c058e79baf
2 changed files with 11 additions and 16 deletions

View File

@ -20,24 +20,10 @@ import time
from oslo_config import cfg
from oslo_log import log as logging
from oslo_metrics import message_type
from oslo_utils import eventletutils
from oslo_utils import importutils
LOG = logging.getLogger(__name__)
eventlet = importutils.try_import('eventlet')
if eventlet and eventletutils.is_monkey_patched("thread"):
# Here we initialize module with the native python threading module
# if it was already monkey patched by eventlet/greenlet.
stdlib_threading = eventlet.patcher.original('threading')
else:
# Manage the case where we run this driver in a non patched environment
# and where user even so configure the driver to run heartbeat through
# a python thread, if we don't do that when the heartbeat will start
# we will facing an issue by trying to override the threading module.
stdlib_threading = threading
oslo_messaging_metrics = [
cfg.BoolOpt('metrics_enabled', default=False,
@ -114,6 +100,10 @@ class MetricsCollectorClient:
self.send_thread = threading.Thread(target=self.send_loop)
self.send_thread.start()
# TODO(tkajinam): This is needed to ensure context switch in eventlet
# case and may be removed after eventlet support is removed.
time.sleep(0)
def send_loop(self):
timeout = self.conf.metrics_thread_stop_timeout
stoptime = time.time() + timeout
@ -247,8 +237,6 @@ METRICS_COLLECTOR = None
def get_collector(conf, metrics_type, **kwargs):
global threading
threading = stdlib_threading
global METRICS_COLLECTOR
if METRICS_COLLECTOR is None:
METRICS_COLLECTOR = MetricsCollectorClient(

View File

@ -0,0 +1,7 @@
---
fixes:
- |
Fixes delayed metrics processing in services using eventlet, caused by
mixing a native thread with an eventlet-patched queue.
See `bug 2098714 <https://launchpad.net/bugs/2098714>`__
for details.