Add Sample priority

With the routing notifier we can now issue high-frequency notifications
and not worry about clogging up the queue. The Sample priority will
be used for this situation.

Change-Id: Ia4aa77b7aa4ca9458e97ca3ed81101d92934b691
This commit is contained in:
Sandy Walsh 2013-12-04 18:53:18 +00:00
parent 33202134bd
commit 43884bfbb4
3 changed files with 39 additions and 1 deletions

View File

@ -30,4 +30,6 @@ class LogDriver(notifier._Driver):
def notify(self, ctxt, message, priority):
logger = logging.getLogger('%s.%s' % (self.LOGGER_BASE,
message['event_type']))
getattr(logger, priority.lower())(jsonutils.dumps(message))
method = getattr(logger, priority.lower(), None)
if method:
method(jsonutils.dumps(message))

View File

@ -243,6 +243,24 @@ class Notifier(object):
"""
self._notify(ctxt, event_type, payload, 'CRITICAL')
def sample(self, ctxt, event_type, payload):
"""Send a notification at sample level.
Sample notifications are for high-frequency events
that typically contain small payloads. eg: "CPU = 70%"
Not all drivers support the sample level
(log, for example) so these could be dropped.
:param ctxt: a request context dict
:type ctxt: dict
:param event_type: describes the event, e.g. 'compute.create_instance'
:type event_type: str
:param payload: the notification payload
:type payload: dict
"""
self._notify(ctxt, event_type, payload, 'SAMPLE')
class _SubNotifier(Notifier):

View File

@ -21,6 +21,7 @@ import fixtures
import testscenarios
from oslo import messaging
from oslo.messaging.notify import _impl_log
from oslo.messaging.notify import _impl_messaging
from oslo.messaging.notify import _impl_test
from oslo.messaging.notify import notifier as msg_notifier
@ -104,6 +105,7 @@ class TestMessagingNotifier(test_utils.BaseTestCase):
('info', dict(priority='info')),
('warn', dict(priority='warn')),
('error', dict(priority='error')),
('sample', dict(priority='sample')),
('critical', dict(priority='critical')),
]
@ -283,3 +285,19 @@ class TestLogNotifier(test_utils.BaseTestCase):
self.mox.ReplayAll()
notifier.info({}, 'test.notify', 'bar')
def test_sample_priority(self):
# Ensure logger drops sample-level notifications.
driver = _impl_log.LogDriver(None, None, None)
logger = self.mox.CreateMock(
logging.getLogger('oslo.messaging.notification.foo'))
logger.sample = None
self.mox.StubOutWithMock(logging, 'getLogger')
logging.getLogger('oslo.messaging.notification.foo').\
AndReturn(logger)
self.mox.ReplayAll()
msg = {'event_type': 'foo'}
driver.notify(None, msg, "sample")