Enable request-id in cinder API logs

Using common.local:store.context doesn't work correctly with
the new oslo_log module.  This change removes the calls to
common.local and removes the file altogether which allows the
proper settings to be passed in to the logging module and give
us back our request-id in the API logs.

Change-Id: If312f419fb465c9128bcfa0a280d6c35a46cb29b
Closes-Bug: #1435588
This commit is contained in:
John Griffith 2015-03-24 03:08:15 +00:00 committed by Ivan Kolodyazhny
parent 37713115be
commit 19f2f2833a
3 changed files with 2 additions and 53 deletions

View File

@ -24,7 +24,6 @@ from oslo_log import log as logging
from oslo_utils import timeutils
from cinder.i18n import _
from cinder.openstack.common import local
from cinder import policy
@ -74,8 +73,6 @@ class RequestContext(context.RequestContext):
timestamp = timeutils.parse_strtime(timestamp)
self.timestamp = timestamp
self.quota_class = quota_class
if overwrite or not hasattr(local.store, 'context'):
self.update_store()
if service_catalog:
# Only include required parts of service_catalog
@ -109,9 +106,6 @@ class RequestContext(context.RequestContext):
read_deleted = property(_get_read_deleted, _set_read_deleted,
_del_read_deleted)
def update_store(self):
local.store.context = self
def to_dict(self):
default = super(RequestContext, self).to_dict()
extra = {'user_id': self.user_id,
@ -123,7 +117,8 @@ class RequestContext(context.RequestContext):
'remote_address': self.remote_address,
'timestamp': timeutils.strtime(self.timestamp),
'quota_class': self.quota_class,
'service_catalog': self.service_catalog}
'service_catalog': self.service_catalog,
'request_id': self.request_id}
return dict(default.items() + extra.items())
@classmethod

View File

@ -1,45 +0,0 @@
# Copyright 2011 OpenStack Foundation.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Local storage of variables using weak references"""
import threading
import weakref
class WeakLocal(threading.local):
def __getattribute__(self, attr):
rval = super(WeakLocal, self).__getattribute__(attr)
if rval:
# NOTE(mikal): this bit is confusing. What is stored is a weak
# reference, not the value itself. We therefore need to lookup
# the weak reference and return the inner value here.
rval = rval()
return rval
def __setattr__(self, attr, value):
value = weakref.ref(value)
return super(WeakLocal, self).__setattr__(attr, value)
# NOTE(mikal): the name "store" should be deprecated in the future
store = WeakLocal()
# A "weak" store uses weak references and allows an object to fall out of scope
# when it falls out of scope in the code that uses the thread local storage. A
# "strong" store will hold a reference to the object so that it never falls out
# of scope.
weak_store = WeakLocal()
strong_store = threading.local()

View File

@ -7,7 +7,6 @@ module=fileutils
module=gettextutils
module=imageutils
module=install_venv_common
module=local
module=loopingcall
module=middleware
module=periodic_task