Move profiler meters to yaml

Partially-Implements: blueprint declarative-notifications

Change-Id: Ife5aabce76083b98494a64a4987b2e77718909b3
This commit is contained in:
Pradeep Kilambi 2015-08-17 15:35:41 -04:00
parent 8d5e86e188
commit e8929f3e18
11 changed files with 36 additions and 161 deletions

View File

@ -22,7 +22,7 @@ from ceilometer import sample
SERVICE = 'trove'
cfg.CONF.import_opt('trove_control_exchange',
'ceilometer.profiler.notifications')
'ceilometer.notification')
class TroveMetricsNotificationBase(plugin_base.NotificationBase):

View File

@ -38,4 +38,10 @@ EXCHANGE_OPTS = [
cfg.StrOpt('magnum_control_exchange',
default='magnum',
help="Exchange name for Magnum notifications."),
cfg.StrOpt('trove_control_exchange',
default='trove',
help="Exchange name for DBaaS notifications."),
cfg.StrOpt('zaqar_control_exchange',
default='zaqar',
help="Exchange name for Messaging service notifications."),
]

View File

@ -76,7 +76,7 @@ metric:
user_id: $.payload.user_id
project_id: $.payload.project_id
resource_id: $.payload.resource_id
multi: ['name', 'unit', 'volume']
lookup: ['name', 'unit', 'volume']
# Swift
- name: $.payload.measurements.[*].metric.[*].name
@ -87,7 +87,7 @@ metric:
resource_id: $.payload.target.id
user_id: $.payload.initiator.id
project_id: $.payload.initiator.project_id
multi: ['name', 'unit', 'volume']
lookup: ['name', 'unit', 'volume']
- name: 'memory'
event_type: 'compute.instance.*'
@ -710,3 +710,12 @@ metric:
resource_id: $.payload.target.id
user_id: $.payload.initiator.id
project_id: $.payload.initiator.project_id
- name: '$.payload.name'
event_type: 'profiler.*'
type: 'gauge'
unit: 'trace'
volume: 1
user_id: $.payload.user_id
project_id: $.payload.project_id
resource_id: '"profiler-" + $.payload.base_id'

View File

@ -65,14 +65,14 @@ class MeterDefinition(object):
if isinstance(self._event_type, six.string_types):
self._event_type = [self._event_type]
if ('type' not in self.cfg.get('multi', []) and
if ('type' not in self.cfg.get('lookup', []) and
self.cfg['type'] not in sample.TYPES):
raise MeterDefinitionException(
_LE("Invalid type %s specified") % self.cfg['type'], self.cfg)
self._field_getter = {}
for name, field in self.cfg.items():
if name in ["event_type", "multi"] or not field:
if name in ["event_type", "lookup"] or not field:
continue
elif isinstance(field, six.integer_types):
self._field_getter[name] = field
@ -216,14 +216,14 @@ class ProcessMeterNotifications(plugin_base.NotificationBase):
def _normalise_as_list(value, d, body, length):
values = d.parse_fields(value, body, True)
if not values:
if value in d.cfg.get('multi'):
if value in d.cfg.get('lookup'):
LOG.warning('Could not find %s values', value)
raise InvalidPayload
values = [d.cfg[value]]
elif value in d.cfg.get('multi') and length != len(values):
elif value in d.cfg.get('lookup') and length != len(values):
LOG.warning('Not all fetched meters contain "%s" field', value)
raise InvalidPayload
return values
return values if isinstance(values, list) else [values]
def process_notification(self, notification_body):
for d in self.definitions:
@ -232,7 +232,7 @@ class ProcessMeterNotifications(plugin_base.NotificationBase):
projectid = self.get_project_id(d, notification_body)
resourceid = d.parse_fields('resource_id', notification_body)
ts = d.parse_fields('timestamp', notification_body)
if d.cfg.get('multi'):
if d.cfg.get('lookup'):
meters = d.parse_fields('name', notification_body, True)
if not meters: # skip if no meters in payload
break
@ -247,13 +247,14 @@ class ProcessMeterNotifications(plugin_base.NotificationBase):
'type', d, notification_body, len(meters))
users = (self._normalise_as_list(
'user_id', d, notification_body, len(meters))
if 'user_id' in d.cfg['multi'] else [userid])
if 'user_id' in d.cfg['lookup'] else [userid])
projs = (self._normalise_as_list(
'project_id', d, notification_body, len(meters))
if 'project_id' in d.cfg['multi'] else [projectid])
if 'project_id' in d.cfg['lookup']
else [projectid])
times = (self._normalise_as_list(
'timestamp', d, notification_body, len(meters))
if 'timestamp' in d.cfg['multi'] else [ts])
if 'timestamp' in d.cfg['lookup'] else [ts])
except InvalidPayload:
break
for m, v, unit, t, r, p, user, ts in zip(

View File

@ -47,7 +47,6 @@ import ceilometer.nova_client
import ceilometer.objectstore.rgw
import ceilometer.objectstore.swift
import ceilometer.pipeline
import ceilometer.profiler.notifications
import ceilometer.publisher.messaging
import ceilometer.publisher.utils
import ceilometer.sample
@ -74,7 +73,6 @@ def list_opts():
ceilometer.nova_client.OPTS,
ceilometer.objectstore.swift.OPTS,
ceilometer.pipeline.OPTS,
ceilometer.profiler.notifications.OPTS,
ceilometer.sample.OPTS,
ceilometer.service.OPTS,
ceilometer.storage.OLD_OPTS,

View File

@ -1,77 +0,0 @@
# Copyright 2014: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# 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 sample
OPTS = [
cfg.StrOpt('trove_control_exchange',
default='trove',
help="Exchange name for DBaaS notifications."),
cfg.StrOpt('zaqar_control_exchange',
default='zaqar',
help="Exchange name for Messaging service notifications."),
]
cfg.CONF.register_opts(OPTS)
# TODO(boris-42): remove after adding keystone audit plugins.
cfg.CONF.import_opt('keystone_control_exchange',
'ceilometer.notification')
class ProfilerNotifications(plugin_base.NotificationBase,
plugin_base.NonMetricNotificationBase):
event_types = ["profiler.*"]
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.
"""
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,
]
for exchange in exchanges:
targets.extend(oslo_messaging.Target(topic=topic,
exchange=exchange)
for topic in conf.notification_topics)
return targets
def process_notification(self, message):
yield sample.Sample.from_notification(
name=message["payload"]["name"],
type=sample.TYPE_GAUGE,
volume=1,
unit="trace",
user_id=message["payload"].get("user_id"),
project_id=message["payload"].get("project_id"),
resource_id="profiler-%s" % message["payload"]["base_id"],
message=message)

View File

@ -225,7 +225,7 @@ class TestMeterDefinition(test.BaseTestCase):
project_id="$.payload.project_id")
handler = notifications.MeterDefinition(cfg)
self.assertTrue(handler.match_type("test.create"))
self.assertEqual(1, handler.parse_fields("volume", NOTIFICATION))
self.assertEqual(1.0, handler.parse_fields("volume", NOTIFICATION))
self.assertEqual("bea70e51c7340cb9d555b15cbfcaec23",
handler.parse_fields("resource_id", NOTIFICATION))
self.assertEqual("30be1fc9a03c4e94ab05c403a8a377f2",
@ -415,7 +415,7 @@ class TestMeterProcessing(test.BaseTestCase):
volume="$.payload.measurements.[*].result",
resource_id="$.payload.target_id",
project_id="$.payload.initiator.project_id",
multi=["name", "volume", "unit"])]})
lookup=["name", "volume", "unit"])]})
self.handler.definitions = notifications.load_definitions(
self.__setup_meter_def_file(cfg))
c = list(self.handler.process_notification(MIDDLEWARE_EVENT))
@ -440,7 +440,7 @@ class TestMeterProcessing(test.BaseTestCase):
volume="$.payload.measurements.[*].result",
resource_id="$.payload.target_id",
project_id="$.payload.initiator.project_id",
multi=["name", "unit"])]})
lookup=["name", "unit"])]})
self.handler.definitions = notifications.load_definitions(
self.__setup_meter_def_file(cfg))
c = list(self.handler.process_notification(event))
@ -461,7 +461,7 @@ class TestMeterProcessing(test.BaseTestCase):
volume="$.payload.measurements.[*].result",
resource_id="$.payload.target_id",
project_id="$.payload.initiator.project_id",
multi="name")]})
lookup="name")]})
self.handler.definitions = notifications.load_definitions(
self.__setup_meter_def_file(cfg))
c = list(self.handler.process_notification(event))
@ -477,8 +477,8 @@ class TestMeterProcessing(test.BaseTestCase):
resource_id="$.payload.[*].resource_id",
project_id="$.payload.[*].project_id",
user_id="$.payload.[*].user_id",
multi=['name', 'type', 'unit', 'volume', 'resource_id',
'project_id', 'user_id'])]})
lookup=['name', 'type', 'unit', 'volume',
'resource_id', 'project_id', 'user_id'])]})
self.handler.definitions = notifications.load_definitions(
self.__setup_meter_def_file(cfg))
c = list(self.handler.process_notification(FULL_MULTI_MSG))
@ -507,7 +507,7 @@ class TestMeterProcessing(test.BaseTestCase):
volume="$.payload.measurements.[*].result",
resource_id="$.payload.target_id",
project_id="$.payload.initiator.project_id",
multi=["name", "unit", "volume"])]})
lookup=["name", "unit", "volume"])]})
self.handler.definitions = notifications.load_definitions(
self.__setup_meter_def_file(cfg))
c = list(self.handler.process_notification(event))
@ -526,7 +526,7 @@ class TestMeterProcessing(test.BaseTestCase):
volume="$.payload.measurements.[*].result",
resource_id="$.payload.target_id",
project_id="$.payload.initiator.project_id",
multi=["name", "unit", "volume"])]})
lookup=["name", "unit", "volume"])]})
self.handler.definitions = notifications.load_definitions(
self.__setup_meter_def_file(cfg))
c = list(self.handler.process_notification(event))

View File

@ -1,61 +0,0 @@
# Copyright 2014: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslotest import base
from ceilometer.profiler import notifications
from ceilometer import sample
NOTIFICATION = {
"event_type": "profiler.compute",
"message_id": "dae6f69c-00e0-41c0-b371-41ec3b7f4451",
"publisher_id": "some_host",
"payload": {
"user_id": "1e3ce043029547f1a61c1996d1a531a2",
"project_id": "663ce04332954555a61c1996d1a53143",
"base_id": "2e3ce043029547f1a61c1996d1a531a2",
"trace_id": "3e3ce043029547f1a61c1996d1a531a2",
"parent_id": "4e3ce043029547f1a61c1996d1a531a2",
"name": "some_name",
"info": {
"foo": "bar"
}
},
"priority": "INFO",
"timestamp": "2012-05-08 20:23:48.028195"
}
class ProfilerNotificationsTestCase(base.BaseTestCase):
def test_process_notification(self):
prof = notifications.ProfilerNotifications(None)
info = next(prof.process_notification(NOTIFICATION))
self.assertEqual(NOTIFICATION["payload"]["name"], info.name)
self.assertEqual(sample.TYPE_GAUGE, info.type)
self.assertEqual("trace", info.unit)
self.assertEqual(NOTIFICATION["payload"]["user_id"], info.user_id)
self.assertEqual(NOTIFICATION["payload"]["project_id"],
info.project_id)
self.assertEqual("profiler-%s" % NOTIFICATION["payload"]["base_id"],
info.resource_id)
self.assertEqual(1, info.volume)
self.assertEqual(NOTIFICATION["timestamp"], info.timestamp)
self.assertEqual(NOTIFICATION["payload"]["info"],
info.resource_metadata["info"])
self.assertEqual(NOTIFICATION["publisher_id"],
info.resource_metadata["host"])

View File

@ -38,7 +38,6 @@ ceilometer.notification =
floatingip = ceilometer.network.notifications:FloatingIP
http.request = ceilometer.middleware:HTTPRequest
http.response = ceilometer.middleware:HTTPResponse
profiler = ceilometer.profiler.notifications:ProfilerNotifications
hardware.ipmi.temperature = ceilometer.ipmi.notifications.ironic:TemperatureSensorNotification
hardware.ipmi.voltage = ceilometer.ipmi.notifications.ironic:VoltageSensorNotification
hardware.ipmi.current = ceilometer.ipmi.notifications.ironic:CurrentSensorNotification