Support extended declaring exchanges

Allow users add metrics into meters.yaml themselves. Reusing
http_control_exchanges makes it available to extend addtional
exchanges.

Closes-Bug: #1656873
Change-Id: I196f8fb0e2aee8498309bb0cb1b3ec2b2e21e211
This commit is contained in:
Hanxi Liu 2017-01-19 14:07:04 +08:00
parent b01c33f78b
commit fed5795d35
7 changed files with 82 additions and 78 deletions

View File

@ -16,41 +16,67 @@ from oslo_config import cfg
EXCHANGE_OPTS = [
cfg.StrOpt('nova_control_exchange',
default='nova',
help="Exchange name for Nova notifications."),
help="Exchange name for Nova notifications.",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
cfg.StrOpt('neutron_control_exchange',
default='neutron',
help="Exchange name for Neutron notifications."),
help="Exchange name for Neutron notifications.",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
cfg.StrOpt('heat_control_exchange',
default='heat',
help="Exchange name for Heat notifications"),
help="Exchange name for Heat notifications",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
cfg.StrOpt('glance_control_exchange',
default='glance',
help="Exchange name for Glance notifications."),
help="Exchange name for Glance notifications.",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
cfg.StrOpt('keystone_control_exchange',
default='keystone',
help="Exchange name for Keystone notifications."),
help="Exchange name for Keystone notifications.",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
cfg.StrOpt('cinder_control_exchange',
default='cinder',
help="Exchange name for Cinder notifications."),
help="Exchange name for Cinder notifications.",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
cfg.StrOpt('sahara_control_exchange',
default='sahara',
help="Exchange name for Data Processing notifications."),
help="Exchange name for Data Processing notifications.",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
cfg.StrOpt('swift_control_exchange',
default='swift',
help="Exchange name for Swift notifications."),
help="Exchange name for Swift notifications.",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
cfg.StrOpt('magnum_control_exchange',
default='magnum',
help="Exchange name for Magnum notifications."),
help="Exchange name for Magnum notifications.",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
cfg.StrOpt('trove_control_exchange',
default='trove',
help="Exchange name for DBaaS notifications."),
help="Exchange name for DBaaS notifications.",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
cfg.StrOpt('zaqar_control_exchange',
default='zaqar',
help="Exchange name for Messaging service notifications."),
help="Exchange name for Messaging service notifications.",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
cfg.StrOpt('dns_control_exchange',
default='central',
help="Exchange name for DNS service notifications."),
help="Exchange name for DNS service notifications.",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
cfg.StrOpt('ceilometer_control_exchange',
default='ceilometer',
help="Exchange name for ceilometer notifications."),
help="Exchange name for ceilometer notifications.",
deprecated_for_removal=True,
deprecated_reason="Use notification_control_exchanges instead"),
]

View File

@ -17,12 +17,11 @@ import six
from oslo_config import cfg
from oslo_log import log
import oslo_messaging
from oslo_utils import fnmatch
from stevedore import extension
from ceilometer.agent import plugin_base
from ceilometer import declarative
from ceilometer import notification
from ceilometer.i18n import _LE, _LW
from ceilometer import sample as sample_util
@ -166,7 +165,7 @@ class MeterDefinition(object):
yield sample
class ProcessMeterNotifications(plugin_base.NotificationBase):
class ProcessMeterNotifications(notification.NotificationProcessBase):
event_types = []
@ -199,37 +198,6 @@ class ProcessMeterNotifications(plugin_base.NotificationBase):
definitions[meter_cfg['name']] = md
return definitions.values()
def get_targets(self, conf):
"""Return a sequence of oslo_messaging.Target
It is defining the exchange and topics to be connected for this plugin.
:param conf: Configuration.
#TODO(prad): This should be defined in the notification agent
"""
targets = []
exchanges = [
conf.nova_control_exchange,
conf.cinder_control_exchange,
conf.glance_control_exchange,
conf.neutron_control_exchange,
conf.heat_control_exchange,
conf.keystone_control_exchange,
conf.sahara_control_exchange,
conf.trove_control_exchange,
conf.zaqar_control_exchange,
conf.swift_control_exchange,
conf.ceilometer_control_exchange,
conf.magnum_control_exchange,
conf.dns_control_exchange,
]
for exchange in exchanges:
targets.extend(oslo_messaging.Target(topic=topic,
exchange=exchange)
for topic in
self.get_notification_topics(conf))
return targets
def process_notification(self, notification_body):
for d in self.definitions:
if d.match_type(notification_body['event_type']):

View File

@ -13,39 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
import oslo_messaging
from ceilometer.agent import plugin_base
from ceilometer import notification
from ceilometer import sample
# NOTE(sileht): reading config values at loadtime won't works
# we should use set_defaults at runtime to set http_control_exchanges to
# [cfg.CONF.nova_control_exchange,
# cfg.CONF.glance_control_exchange,
# cfg.CONF.neutron_control_exchange,
# cfg.CONF.cinder_control_exchange],
OPTS = [
cfg.MultiStrOpt('http_control_exchanges',
default=['nova', 'glance', 'neutron', 'cinder'],
help="Exchanges name to listen for notifications."),
]
class HTTPRequest(plugin_base.NotificationBase):
class HTTPRequest(notification.NotificationProcessBase):
event_types = ['http.request']
def get_targets(self, conf):
"""Return a sequence of oslo_messaging.Target
This sequence is defining the exchange and topics to be connected for
this plugin.
"""
return [oslo_messaging.Target(topic=topic, exchange=exchange)
for topic in self.get_notification_topics(conf)
for exchange in conf.http_control_exchanges]
def process_notification(self, message):
yield sample.Sample.from_notification(
name=message['event_type'],

View File

@ -12,9 +12,11 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import itertools
import threading
from ceilometer.agent import plugin_base
from concurrent import futures
from futurist import periodics
from oslo_config import cfg
@ -80,6 +82,17 @@ OPTS = [
]
EXCHANGES_OPTS = [
cfg.MultiStrOpt('notification_control_exchanges',
default=['nova', 'glance', 'neutron', 'cinder', 'heat',
'keystone', 'sahara', 'trove', 'zaqar', 'swift',
'ceilometer', 'magnum', 'dns'],
deprecated_group='DEFAULT',
deprecated_name="http_control_exchanges",
help="Exchanges name to listen for notifications."),
]
class NotificationService(service_base.PipelineBasedService):
"""Notification service.
@ -334,3 +347,17 @@ class NotificationService(service_base.PipelineBasedService):
# is enabled.
if self.conf.notification.workload_partitioning:
self._configure_pipeline_listener()
class NotificationProcessBase(plugin_base.NotificationBase):
def get_targets(self, conf):
"""Return a sequence of oslo_messaging.Target
This sequence is defining the exchange and topics to be connected for
this plugin.
"""
return [oslo_messaging.Target(topic=topic, exchange=exchange)
for topic in self.get_notification_topics(conf)
for exchange in
conf.notification.notification_control_exchanges]

View File

@ -81,7 +81,6 @@ def list_opts():
ceilometer.compute.virt.libvirt.utils.OPTS,
ceilometer.dispatcher.OPTS,
ceilometer.ipmi.notifications.ironic.OPTS,
ceilometer.middleware.OPTS,
ceilometer.nova_client.OPTS,
ceilometer.objectstore.swift.OPTS,
ceilometer.pipeline.OPTS,
@ -107,7 +106,9 @@ def list_opts():
itertools.chain(ceilometer.ipmi.platform.intel_node_manager.OPTS,
ceilometer.ipmi.pollsters.OPTS)),
('meter', ceilometer.meter.notifications.OPTS),
('notification', ceilometer.notification.OPTS),
('notification',
itertools.chain(ceilometer.notification.OPTS,
ceilometer.notification.EXCHANGES_OPTS)),
('polling', ceilometer.agent.manager.POLLING_OPTS),
('publisher', ceilometer.publisher.utils.OPTS),
('publisher_notifier', ceilometer.publisher.messaging.NOTIFIER_OPTS),

View File

@ -97,4 +97,4 @@ class TestNotifications(base.BaseTestCase):
def test_targets(self):
targets = middleware.HTTPRequest(mock.Mock()).get_targets(self.CONF)
self.assertEqual(4, len(targets))
self.assertEqual(13, len(targets))

View File

@ -0,0 +1,8 @@
---
deprecations:
- |
Allow users to add additional exchanges in ceilometer.conf instead of
hardcoding exchanges. Now original http_control_exchanges is being deprecated
and renamed notification_control_exchanges. Besides, the new option is integrated
with other exchanges in default EXCHANGE_OPTS to make it available to extend
addtional exchanges.