Ignore request with swift.source in env
swift.source in env indicates request that originate in swift middleware as a side effect of another client request. These requests should not be metered, this fix adds a check for swift.source in env and avoids generating a metering event. Change-Id: I2ecbde8667cc366b192a2248abc93d0936956978 Closes-bug: 1485711
This commit is contained in:
parent
6a5642bbc2
commit
7005d98f47
|
@ -161,9 +161,10 @@ class Swift(object):
|
||||||
|
|
||||||
@_log_and_ignore_error
|
@_log_and_ignore_error
|
||||||
def emit_event(self, env, bytes_received, bytes_sent, outcome='success'):
|
def emit_event(self, env, bytes_received, bytes_sent, outcome='success'):
|
||||||
if (env.get('HTTP_X_SERVICE_PROJECT_ID') or
|
if ((env.get('HTTP_X_SERVICE_PROJECT_ID') or
|
||||||
env.get('HTTP_X_PROJECT_ID') or
|
env.get('HTTP_X_PROJECT_ID') or
|
||||||
env.get('HTTP_X_TENANT_ID')) in self.ignore_projects:
|
env.get('HTTP_X_TENANT_ID')) in self.ignore_projects or
|
||||||
|
env.get('swift.source') is not None):
|
||||||
return
|
return
|
||||||
|
|
||||||
path = urlparse.quote(env['PATH_INFO'])
|
path = urlparse.quote(env['PATH_INFO'])
|
||||||
|
|
|
@ -381,3 +381,16 @@ class TestSwift(tests_base.TestCase):
|
||||||
self.assertIsNone(metadata['container'])
|
self.assertIsNone(metadata['container'])
|
||||||
self.assertIsNone(metadata['object'])
|
self.assertIsNone(metadata['object'])
|
||||||
self.assertEqual('head', data[2]['target']['action'])
|
self.assertEqual('head', data[2]['target']['action'])
|
||||||
|
|
||||||
|
def test_put_with_swift_source(self):
|
||||||
|
app = swift.Swift(FakeApp(), {})
|
||||||
|
|
||||||
|
req = FakeRequest(
|
||||||
|
'/1.0/account/container/obj',
|
||||||
|
environ={'REQUEST_METHOD': 'PUT',
|
||||||
|
'wsgi.input':
|
||||||
|
six.moves.cStringIO('some stuff'),
|
||||||
|
'swift.source': 'RL'})
|
||||||
|
with mock.patch('oslo_messaging.Notifier.info') as notify:
|
||||||
|
list(app(req.environ, self.start_response))
|
||||||
|
self.assertEqual(False, notify.called)
|
||||||
|
|
Loading…
Reference in New Issue