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:
parent
33202134bd
commit
43884bfbb4
|
@ -30,4 +30,6 @@ class LogDriver(notifier._Driver):
|
||||||
def notify(self, ctxt, message, priority):
|
def notify(self, ctxt, message, priority):
|
||||||
logger = logging.getLogger('%s.%s' % (self.LOGGER_BASE,
|
logger = logging.getLogger('%s.%s' % (self.LOGGER_BASE,
|
||||||
message['event_type']))
|
message['event_type']))
|
||||||
getattr(logger, priority.lower())(jsonutils.dumps(message))
|
method = getattr(logger, priority.lower(), None)
|
||||||
|
if method:
|
||||||
|
method(jsonutils.dumps(message))
|
||||||
|
|
|
@ -243,6 +243,24 @@ class Notifier(object):
|
||||||
"""
|
"""
|
||||||
self._notify(ctxt, event_type, payload, 'CRITICAL')
|
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):
|
class _SubNotifier(Notifier):
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import fixtures
|
||||||
import testscenarios
|
import testscenarios
|
||||||
|
|
||||||
from oslo import messaging
|
from oslo import messaging
|
||||||
|
from oslo.messaging.notify import _impl_log
|
||||||
from oslo.messaging.notify import _impl_messaging
|
from oslo.messaging.notify import _impl_messaging
|
||||||
from oslo.messaging.notify import _impl_test
|
from oslo.messaging.notify import _impl_test
|
||||||
from oslo.messaging.notify import notifier as msg_notifier
|
from oslo.messaging.notify import notifier as msg_notifier
|
||||||
|
@ -104,6 +105,7 @@ class TestMessagingNotifier(test_utils.BaseTestCase):
|
||||||
('info', dict(priority='info')),
|
('info', dict(priority='info')),
|
||||||
('warn', dict(priority='warn')),
|
('warn', dict(priority='warn')),
|
||||||
('error', dict(priority='error')),
|
('error', dict(priority='error')),
|
||||||
|
('sample', dict(priority='sample')),
|
||||||
('critical', dict(priority='critical')),
|
('critical', dict(priority='critical')),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -283,3 +285,19 @@ class TestLogNotifier(test_utils.BaseTestCase):
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
|
|
||||||
notifier.info({}, 'test.notify', 'bar')
|
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")
|
||||||
|
|
Loading…
Reference in New Issue