Merge "change dns and trove notifications to declarative"
This commit is contained in:
commit
dd2c6509c8
|
@ -1,67 +0,0 @@
|
|||
#
|
||||
# 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.notification')
|
||||
|
||||
|
||||
class TroveMetricsNotificationBase(plugin_base.NotificationBase):
|
||||
"""Base class for trove (dbaas) notifications."""
|
||||
|
||||
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=conf.trove_control_exchange)
|
||||
for topic in self.get_notification_topics(conf)]
|
||||
|
||||
|
||||
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)
|
|
@ -1,73 +0,0 @@
|
|||
#
|
||||
# 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
|
||||
|
||||
OPTS = [
|
||||
cfg.StrOpt('dns_control_exchange',
|
||||
default='central',
|
||||
help="Exchange name for DNS notifications."),
|
||||
|
||||
]
|
||||
|
||||
cfg.CONF.register_opts(OPTS)
|
||||
SERVICE = 'dns'
|
||||
|
||||
|
||||
class DnsMetricsNotificationBase(plugin_base.NotificationBase):
|
||||
"""Base class for DNSaaS(Designate) notifications."""
|
||||
|
||||
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=conf.dns_control_exchange)
|
||||
for topic in self.get_notification_topics(conf)]
|
||||
|
||||
|
||||
class DomainExists(DnsMetricsNotificationBase):
|
||||
"""Handles DNS domain exists notification.
|
||||
|
||||
Emits a sample for a measurable audit interval.
|
||||
"""
|
||||
|
||||
event_types = ['%s.domain.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']['id'],
|
||||
user_id=message['_context_user'],
|
||||
project_id=message['payload']['tenant_id'],
|
||||
message=message)
|
|
@ -44,4 +44,7 @@ EXCHANGE_OPTS = [
|
|||
cfg.StrOpt('zaqar_control_exchange',
|
||||
default='zaqar',
|
||||
help="Exchange name for Messaging service notifications."),
|
||||
cfg.StrOpt('dns_control_exchange',
|
||||
default='central',
|
||||
help="Exchange name for DNS service notifications."),
|
||||
]
|
||||
|
|
|
@ -263,6 +263,40 @@ metric:
|
|||
host: $.publisher_id
|
||||
source: $.payload.metrics[?(@.name='cpu.percent')].source
|
||||
|
||||
# DNS
|
||||
- name: 'dns.domain.exists'
|
||||
event_type: 'dns.domain.exists'
|
||||
type: 'cumulative'
|
||||
unit: 's'
|
||||
volume:
|
||||
fields: [$.payload.audit_period_beginning, $.payload.audit_period_ending]
|
||||
plugin: 'timedelta'
|
||||
project_id: $.payload.tenant_id
|
||||
resource_id: $.payload.id
|
||||
user_id: $._context_user
|
||||
metadata:
|
||||
status: $.payload.status
|
||||
pool_id: $.payload.pool_id
|
||||
host: $.publisher_id
|
||||
|
||||
# Trove
|
||||
- name: 'trove.instance.exists'
|
||||
event_type: 'trove.instance.exists'
|
||||
type: 'cumulative'
|
||||
unit: 's'
|
||||
volume:
|
||||
fields: [$.payload.audit_period_beginning, $.payload.audit_period_ending]
|
||||
plugin: 'timedelta'
|
||||
project_id: $.payload.tenant_id
|
||||
resource_id: $.payload.instance_id
|
||||
user_id: $.payload.user_id
|
||||
metadata:
|
||||
nova_instance_id: $.payload.nova_instance_id
|
||||
state: $.payload.state
|
||||
service_id: $.payload.service_id
|
||||
instance_type: $.payload.instance_type
|
||||
instance_type_id: $.payload.instance_type_id
|
||||
|
||||
|
||||
# NOTE: non-metric meters are generally events/existence meters
|
||||
# These are DEPRECATED in current release and expected to be
|
||||
|
|
|
@ -223,6 +223,7 @@ class ProcessMeterNotifications(plugin_base.NotificationBase):
|
|||
conf.magnetodb_control_exchange,
|
||||
conf.ceilometer_control_exchange,
|
||||
conf.magnum_control_exchange,
|
||||
conf.dns_control_exchange,
|
||||
]
|
||||
|
||||
for exchange in exchanges:
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
#
|
||||
# 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.utcnow().isoformat()
|
||||
|
||||
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')
|
|
@ -1,102 +0,0 @@
|
|||
#
|
||||
# Copyright (c) 2015 Hewlett Packard Inc.
|
||||
#
|
||||
# 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.dns import notifications
|
||||
from ceilometer import sample
|
||||
|
||||
NOW = timeutils.utcnow().isoformat()
|
||||
|
||||
TENANT_ID = u'76538754af6548f5b53cf9af2d35d582'
|
||||
USER_ID = u'b70ece400e4e45c187168c40fa42ff7a'
|
||||
DOMAIN_STATUS = u'ACTIVE'
|
||||
RESOURCE_ID = u'a8b55824-e731-40a3-a32d-de81474d74b2'
|
||||
PUBLISHER_ID = u'central.ubuntu'
|
||||
POOL_ID = u'794ccc2c-d751-44fe-b57f-8894c9f5c842'
|
||||
|
||||
|
||||
def _dns_notification_for(operation):
|
||||
|
||||
return {
|
||||
u'event_type': '%s.domain.%s' % (notifications.SERVICE,
|
||||
operation),
|
||||
u'_context_roles': [u'admin'],
|
||||
u'timestamp': NOW,
|
||||
u'_context_tenant': TENANT_ID,
|
||||
u'payload': {
|
||||
u'status': DOMAIN_STATUS,
|
||||
u'retry': 600,
|
||||
u'description': None,
|
||||
u'expire': 86400,
|
||||
u'deleted': u'0',
|
||||
u'tenant_id': TENANT_ID,
|
||||
u'created_at': u'2015-07-10T20:05:29.870091Z',
|
||||
u'updated_at': None,
|
||||
u'refresh': 3600,
|
||||
u'pool_id': POOL_ID,
|
||||
u'email': u'admin@hpcloud.com',
|
||||
u'minimum': 3600,
|
||||
u'parent_domain_id': None,
|
||||
u'version': 1,
|
||||
u'ttl': 3600,
|
||||
u'action': operation.upper(),
|
||||
u'serial': 1426295326,
|
||||
u'deleted_at': None,
|
||||
u'id': RESOURCE_ID,
|
||||
u'name': u'paas.hpcloud.com.',
|
||||
u'audit_period_beginning': u'2015-07-10T20:05:29.870091Z',
|
||||
u'audit_period_ending': u'2015-07-10T21:05:29.870091Z'
|
||||
},
|
||||
u'_context_user': USER_ID,
|
||||
u'_context_auth_token': u'b95d4fc3bb2e4a5487cad06af65ffcfc',
|
||||
u'_context_tenant': TENANT_ID,
|
||||
u'priority': u'INFO',
|
||||
u'_context_is_admin': False,
|
||||
u'publisher_id': PUBLISHER_ID,
|
||||
u'message_id': u'67ba0a2a-32bd-4cdf-9bfb-ef9cefcd0f63',
|
||||
}
|
||||
|
||||
|
||||
class TestNotification(base.BaseTestCase):
|
||||
def _verify_common_sample(self, actual, operation):
|
||||
self.assertIsNotNone(actual)
|
||||
self.assertEqual('%s.domain.%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)
|
||||
metadata = actual.resource_metadata
|
||||
self.assertEqual(PUBLISHER_ID, metadata.get('host'))
|
||||
self.assertEqual(operation.upper(), metadata.get('action'))
|
||||
self.assertEqual(DOMAIN_STATUS, metadata.get('status'))
|
||||
|
||||
self.assertEqual(3600, actual.volume)
|
||||
self.assertEqual('s', actual.unit)
|
||||
|
||||
def _test_operation(self, operation):
|
||||
notif = _dns_notification_for(operation)
|
||||
handler = notifications.DomainExists(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')
|
Loading…
Reference in New Issue