Fix Backup uses latest req-id for all log calls

Currently all log entries will have the request ID of the latest request
that was received in the Backup service.

So you would receive a request with ID 1 and you would start logging
that thread log calls with its ID, but as soon as you receive another
request, let's say with ID 2, you will have both request logging with ID
2 instead of each one logging with its own request ID.

The reason for this is that we are monkey patching after we have
imported OSLO logging and we should be doing the monkey patching before,
because OSLO logging imports OSLO context, which in turn imports
threading and defines the _request_store where the context is stored as
threading.local, which is not the monkey patched version and therefore
will be shared among all the greenthreads that share the same python
thread.

To fix this we just move the monkey patching earlier in the imports.

Closes-Bug: #1743461
Change-Id: I677a8e39de4292fe4fa8e70d7b6ae2fc3d5cf2ac
This commit is contained in:
Gorka Eguileor
2018-01-15 21:29:02 +01:00
parent 62561bdd4b
commit 1a569e15c3

View File

@@ -21,14 +21,18 @@ import logging as python_logging
import shlex
import sys
# NOTE(geguileo): Monkey patching must go before OSLO.log import, otherwise
# OSLO.context will not use greenthread thread local and all greenthreads will
# share the same context.
import eventlet
eventlet.monkey_patch()
from oslo_config import cfg
from oslo_log import log as logging
from oslo_privsep import priv_context
from oslo_reports import guru_meditation_report as gmr
from oslo_reports import opts as gmr_opts
eventlet.monkey_patch()
from cinder import i18n
i18n.enable_lazy()