summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgordon chung <gord@live.ca>2015-04-23 15:09:45 -0400
committergordon chung <gord@live.ca>2015-06-23 15:45:18 +0000
commit6a3c77bb309984edfd68fd45aab3db13e65728cc (patch)
tree704bf7f8427554c9858a526faa1e5f6f34aadb37
parenta086aac03cd1948887ec1151a1b650c1ed94ead5 (diff)
downloadceilometermiddleware-6a3c77bb309984edfd68fd45aab3db13e65728cc.tar.gz
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
-rw-r--r--ceilometermiddleware/swift.py10
-rw-r--r--ceilometermiddleware/tests/test_swift.py27
2 files changed, 37 insertions, 0 deletions
diff --git a/ceilometermiddleware/swift.py b/ceilometermiddleware/swift.py
index 8dfb6fb..0cd2eb3 100644
--- a/ceilometermiddleware/swift.py
+++ b/ceilometermiddleware/swift.py
@@ -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 = {}
diff --git a/ceilometermiddleware/tests/test_swift.py b/ceilometermiddleware/tests/test_swift.py
index 2bb6e33..2599a34 100644
--- a/ceilometermiddleware/tests/test_swift.py
+++ b/ceilometermiddleware/tests/test_swift.py
@@ -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))