add support to skip event/meter generation for certain projects

gnocchi is unuseable with swift backend because for every meter we
capture we are generating an event notification which creates 1+
meters, which creates 1+ event notifications, and so on. this will
flood the message queue and it will never catch up. by default, we
will configure system to ignore requests from gnocchi project.

DocImpact
Change-Id: I175c5d59529ebe51c8e5ccb379b54b05e9affe95
This commit is contained in:
gordon chung 2015-04-23 15:09:45 -04:00
parent a086aac03c
commit 6a3c77bb30
2 changed files with 37 additions and 0 deletions

View File

@ -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 = {}

View File

@ -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))