Merge "add support to skip event/meter generation for certain projects"
This commit is contained in:
commit
157097ef90
|
@ -35,6 +35,8 @@ before "proxy-server" and add the following filter in the file:
|
|||
driver = messaging
|
||||
# set topic
|
||||
topic = notifications
|
||||
# skip metering of requests from listed project ids
|
||||
ignore_projects = <proj_uuid>, <proj_uuid2>
|
||||
"""
|
||||
import functools
|
||||
import logging
|
||||
|
@ -100,6 +102,9 @@ class Swift(object):
|
|||
|
||||
def __init__(self, app, conf):
|
||||
self._app = app
|
||||
self.ignore_projects = [
|
||||
proj.strip() for proj in
|
||||
conf.get('ignore_projects', 'gnocchi').split(',')]
|
||||
|
||||
oslo_messaging.set_transport_defaults(conf.get('control_exchange',
|
||||
'swift'))
|
||||
|
@ -156,6 +161,11 @@ class Swift(object):
|
|||
|
||||
@_log_and_ignore_error
|
||||
def emit_event(self, env, bytes_received, bytes_sent, outcome='success'):
|
||||
if (env.get('HTTP_X_SERVICE_PROJECT_ID') or
|
||||
env.get('HTTP_X_PROJECT_ID') or
|
||||
env.get('HTTP_X_TENANT_ID')) in self.ignore_projects:
|
||||
return
|
||||
|
||||
path = urlparse.quote(env['PATH_INFO'])
|
||||
method = env['REQUEST_METHOD']
|
||||
headers = {}
|
||||
|
|
|
@ -328,3 +328,30 @@ class TestSwift(tests_base.TestCase):
|
|||
self.assertEqual(1, len(notify.call_args_list))
|
||||
data = notify.call_args_list[0][0]
|
||||
self.assertEqual("account", data[2]['target']['id'])
|
||||
|
||||
def test_ignore_requests_from_project(self):
|
||||
app = swift.Swift(FakeApp(), {'ignore_projects': 'skip_proj'})
|
||||
|
||||
for proj_attr in ['HTTP_X_SERVICE_PROJECT_ID', 'HTTP_X_PROJECT_ID',
|
||||
'HTTP_X_TENANT_ID']:
|
||||
for proj, calls in [('good', 1), ('skip_proj', 0)]:
|
||||
req = FakeRequest('/1.0/CUSTOM_account/container/obj',
|
||||
environ={'REQUEST_METHOD': 'GET',
|
||||
proj_attr: proj})
|
||||
with mock.patch('oslo.messaging.Notifier.info') as notify:
|
||||
list(app(req.environ, self.start_response))
|
||||
self.assertEqual(calls, len(notify.call_args_list))
|
||||
|
||||
def test_ignore_requests_from_multiple_projects(self):
|
||||
app = swift.Swift(FakeApp(), {'ignore_projects': 'skip_proj, ignore'})
|
||||
|
||||
for proj_attr in ['HTTP_X_SERVICE_PROJECT_ID', 'HTTP_X_PROJECT_ID',
|
||||
'HTTP_X_TENANT_ID']:
|
||||
for proj, calls in [('good', 1), ('skip_proj', 0),
|
||||
('also_good', 1), ('ignore', 0)]:
|
||||
req = FakeRequest('/1.0/CUSTOM_account/container/obj',
|
||||
environ={'REQUEST_METHOD': 'GET',
|
||||
proj_attr: proj})
|
||||
with mock.patch('oslo.messaging.Notifier.info') as notify:
|
||||
list(app(req.environ, self.start_response))
|
||||
self.assertEqual(calls, len(notify.call_args_list))
|
||||
|
|
Loading…
Reference in New Issue