add Trove(DBaaS) events

this patch adds support for Trove crud notifications
as events in ceilometer, and a notification plugin to
emit sample for the trove exists event.

Change-Id: I932941c88e7c8e9f059c97ec41ac098263e38803
Partially-Implements: blueprint track-dbaas-notifications
This commit is contained in:
Rohit Jaiswal 2015-07-10 21:50:56 +00:00
parent a744e1b9e7
commit 014ee79698
6 changed files with 239 additions and 0 deletions

View File

View File

@ -0,0 +1,68 @@
#
# Copyright 2015 Hewlett Packard
#
# 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 oslo_utils import timeutils
from ceilometer.agent import plugin_base
from ceilometer import sample
SERVICE = 'trove'
cfg.CONF.import_opt('trove_control_exchange',
'ceilometer.profiler.notifications')
class TroveMetricsNotificationBase(plugin_base.NotificationBase):
"""Base class for trove (dbaas) notifications."""
@staticmethod
def get_targets(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=conf.trove_control_exchange)
for topic in conf.notification_topics]
class InstanceExists(TroveMetricsNotificationBase):
"""Handles Trove instance exists notification.
Emits a sample for a measurable audit interval.
"""
event_types = ['%s.instance.exists' % SERVICE]
def process_notification(self, message):
period_start = timeutils.normalize_time(timeutils.parse_isotime(
message['payload']['audit_period_beginning']))
period_end = timeutils.normalize_time(timeutils.parse_isotime(
message['payload']['audit_period_ending']))
period_difference = timeutils.delta_seconds(period_start, period_end)
yield sample.Sample.from_notification(
name=message['event_type'],
type=sample.TYPE_CUMULATIVE,
unit='s',
volume=period_difference,
resource_id=message['payload']['instance_id'],
user_id=message['payload']['user_id'],
project_id=message['payload']['tenant_id'],
message=message)

View File

View File

@ -0,0 +1,90 @@
#
# Copyright 2015 Hewlett Packard
#
# 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.
import mock
from oslo_utils import timeutils
from oslotest import base
from ceilometer.database import notifications
from ceilometer import sample
NOW = timeutils.isotime()
TENANT_ID = u'76538754af6548f5b53cf9af2d35d582'
USER_ID = u'b70ece400e4e45c187168c40fa42ff7a'
INSTANCE_STATE = u'active'
INSTANCE_TYPE = u'm1.rd-tiny'
RESOURCE_ID = u'a8b55824-e731-40a3-a32d-de81474d74b2'
SERVICE_ID = u'2f3ff068-2bfb-4f70-9a9d-a6bb65bc084b'
NOVA_INSTANCE_ID = u'1cf6ce1b-708b-4e6a-8ecf-2b60c8ccd435'
PUBLISHER_ID = u'trove'
def _trove_notification_for(operation):
return {
u'event_type': '%s.instance.%s' % (notifications.SERVICE,
operation),
u'priority': u'INFO',
u'timestamp': NOW,
u'publisher_id': PUBLISHER_ID,
u'message_id': u'67ba0a2a-32bd-4cdf-9bfb-ef9cefcd0f63',
u'payload': {
u'state_description': INSTANCE_STATE,
u'user_id': USER_ID,
u'audit_period_beginning': u'2015-07-10T20:05:29.870091Z',
u'tenant_id': TENANT_ID,
u'created_at': u'2015-06-29T20:52:12.000000',
u'instance_type_id': u'7',
u'launched_at': u'2015-06-29T20:52:12.000000',
u'instance_id': RESOURCE_ID,
u'instance_type': INSTANCE_TYPE,
u'state': INSTANCE_STATE,
u'service_id': SERVICE_ID,
u'nova_instance_id': NOVA_INSTANCE_ID,
u'display_name': u'test',
u'instance_name': u'test',
u'region': u'LOCAL_DEV',
u'audit_period_ending': u'2015-07-10T21:05:29.870091Z'
},
}
class TestNotification(base.BaseTestCase):
def _verify_common_sample(self, actual, operation):
self.assertIsNotNone(actual)
self.assertEqual('%s.instance.%s' % (notifications.SERVICE, operation),
actual.name)
self.assertEqual(NOW, actual.timestamp)
self.assertEqual(sample.TYPE_CUMULATIVE, actual.type)
self.assertEqual(TENANT_ID, actual.project_id)
self.assertEqual(RESOURCE_ID, actual.resource_id)
self.assertEqual(USER_ID, actual.user_id)
self.assertEqual(3600, actual.volume)
self.assertEqual('s', actual.unit)
metadata = actual.resource_metadata
self.assertEqual(PUBLISHER_ID, metadata.get('host'))
def _test_operation(self, operation):
notif = _trove_notification_for(operation)
handler = notifications.InstanceExists(mock.Mock())
data = list(handler.process_notification(notif))
self.assertEqual(1, len(data))
self._verify_common_sample(data[0], operation)
def test_exists(self):
self._test_operation('exists')

View File

@ -396,3 +396,83 @@
fields: parent_domain_id
serial:
fields: payload.serial
- event_type: trove.*
traits: &trove_base_traits
state:
fields: payload.state_description
instance_type:
fields: payload.instance_type
user_id:
fields: payload.user_id
resource_id:
fields: payload.instance_id
instance_type_id:
fields: payload.instance_type_id
launched_at:
type: datetime
fields: payload.launched_at
instance_name:
fields: payload.instance_name
state:
fields: payload.state
nova_instance_id:
fields: payload.nova_instance_id
service_id:
fields: payload.service_id
created_at:
type: datetime
fields: payload.created_at
region:
fields: payload.region
- event_type: ['trove.instance.create', 'trove.instance.modify_volume', 'trove.instance.modify_flavor', 'trove.instance.delete']
traits: &trove_common_traits
name:
fields: payload.name
availability_zone:
fields: payload.availability_zone
instance_size:
type: int
fields: payload.instance_size
volume_size:
type: int
fields: payload.volume_size
nova_volume_id:
fields: payload.nova_volume_id
- event_type: trove.instance.create
traits:
<<: [*trove_base_traits, *trove_common_traits]
- event_type: trove.instance.modify_volume
traits:
<<: [*trove_base_traits, *trove_common_traits]
old_volume_size:
type: int
fields: payload.old_volume_size
modify_at:
type: datetime
fields: payload.modify_at
- event_type: trove.instance.modify_flavor
traits:
<<: [*trove_base_traits, *trove_common_traits]
old_instance_size:
type: int
fields: payload.old_instance_size
modify_at:
type: datetime
fields: payload.modify_at
- event_type: trove.instance.delete
traits:
<<: [*trove_base_traits, *trove_common_traits]
deleted_at:
type: datetime
fields: payload.deleted_at
- event_type: trove.instance.exists
traits:
<<: *trove_base_traits
display_name:
fields: payload.display_name
audit_period_beginning:
type: datetime
fields: payload.audit_period_beginning
audit_period_ending:
type: datetime
fields: payload.audit_period_ending

View File

@ -95,6 +95,7 @@ ceilometer.notification =
objectstore.request = ceilometer.objectstore.notifications:SwiftWsgiMiddleware
objectstore.request.meters = ceilometer.objectstore.notifications:SwiftWsgiMiddlewareMeters
_sample = ceilometer.telemetry.notifications:TelemetryApiPost
trove.instance.exists = ceilometer.database.notifications:InstanceExists
ceilometer.discover =
local_instances = ceilometer.compute.discovery:InstanceDiscovery