Set source at publish time
We stop putting the source in the Counter, but we set it via the configuration file and use it as a source. Change-Id: I82c00ac5e55e09ab38de9364cda3194beb35e3c4 Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
365c7a849a
commit
f6868e5e48
@ -125,8 +125,9 @@ class CollectorManager(manager.Manager):
|
|||||||
"""Create a metering message for the counter and publish it."""
|
"""Create a metering message for the counter and publish it."""
|
||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
publish.publish_counter(ctxt, counter,
|
publish.publish_counter(ctxt, counter,
|
||||||
cfg.CONF.metering_topic, cfg.CONF.metering_secret,
|
cfg.CONF.metering_topic,
|
||||||
)
|
cfg.CONF.metering_secret,
|
||||||
|
cfg.CONF.counter_source)
|
||||||
|
|
||||||
def record_metering_data(self, context, data):
|
def record_metering_data(self, context, data):
|
||||||
"""This method is triggered when metering data is
|
"""This method is triggered when metering data is
|
||||||
|
@ -47,7 +47,6 @@ def get_libvirt_connection():
|
|||||||
|
|
||||||
def make_counter_from_instance(instance, name, type, volume):
|
def make_counter_from_instance(instance, name, type, volume):
|
||||||
return counter.Counter(
|
return counter.Counter(
|
||||||
source='?',
|
|
||||||
name=name,
|
name=name,
|
||||||
type=type,
|
type=type,
|
||||||
volume=volume,
|
volume=volume,
|
||||||
@ -195,7 +194,6 @@ class NetPollster(plugin.ComputePollster):
|
|||||||
resource_metadata['instance_id'] = instance.uuid
|
resource_metadata['instance_id'] = instance.uuid
|
||||||
|
|
||||||
return counter.Counter(
|
return counter.Counter(
|
||||||
source='?',
|
|
||||||
name=name,
|
name=name,
|
||||||
type=type,
|
type=type,
|
||||||
volume=volume,
|
volume=volume,
|
||||||
|
@ -67,8 +67,7 @@ class Instance(_Base):
|
|||||||
|
|
||||||
def process_notification(self, message):
|
def process_notification(self, message):
|
||||||
return [
|
return [
|
||||||
counter.Counter(source='?',
|
counter.Counter(name='instance',
|
||||||
name='instance',
|
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=1,
|
volume=1,
|
||||||
user_id=message['payload']['user_id'],
|
user_id=message['payload']['user_id'],
|
||||||
@ -85,8 +84,7 @@ class Memory(_Base):
|
|||||||
|
|
||||||
def process_notification(self, message):
|
def process_notification(self, message):
|
||||||
return [
|
return [
|
||||||
counter.Counter(source='?',
|
counter.Counter(name='memory',
|
||||||
name='memory',
|
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=message['payload']['memory_mb'],
|
volume=message['payload']['memory_mb'],
|
||||||
user_id=message['payload']['user_id'],
|
user_id=message['payload']['user_id'],
|
||||||
@ -103,8 +101,7 @@ class VCpus(_Base):
|
|||||||
|
|
||||||
def process_notification(self, message):
|
def process_notification(self, message):
|
||||||
return [
|
return [
|
||||||
counter.Counter(source='?',
|
counter.Counter(name='vcpus',
|
||||||
name='vcpus',
|
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=message['payload']['vcpus'],
|
volume=message['payload']['vcpus'],
|
||||||
user_id=message['payload']['user_id'],
|
user_id=message['payload']['user_id'],
|
||||||
@ -121,8 +118,7 @@ class RootDiskSize(_Base):
|
|||||||
|
|
||||||
def process_notification(self, message):
|
def process_notification(self, message):
|
||||||
return [
|
return [
|
||||||
counter.Counter(source='?',
|
counter.Counter(name='disk.root.size',
|
||||||
name='disk.root.size',
|
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=message['payload']['root_gb'],
|
volume=message['payload']['root_gb'],
|
||||||
user_id=message['payload']['user_id'],
|
user_id=message['payload']['user_id'],
|
||||||
@ -139,8 +135,7 @@ class EphemeralDiskSize(_Base):
|
|||||||
|
|
||||||
def process_notification(self, message):
|
def process_notification(self, message):
|
||||||
return [
|
return [
|
||||||
counter.Counter(source='?',
|
counter.Counter(name='disk.ephemeral.size',
|
||||||
name='disk.ephemeral.size',
|
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=message['payload']['ephemeral_gb'],
|
volume=message['payload']['ephemeral_gb'],
|
||||||
user_id=message['payload']['user_id'],
|
user_id=message['payload']['user_id'],
|
||||||
@ -161,7 +156,6 @@ class InstanceFlavor(_Base):
|
|||||||
if instance_type:
|
if instance_type:
|
||||||
counters.append(
|
counters.append(
|
||||||
counter.Counter(
|
counter.Counter(
|
||||||
source='?',
|
|
||||||
name='instance:%s' % instance_type,
|
name='instance:%s' % instance_type,
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=1,
|
volume=1,
|
||||||
|
@ -26,7 +26,6 @@ import collections
|
|||||||
|
|
||||||
# Fields explanation:
|
# Fields explanation:
|
||||||
#
|
#
|
||||||
# Source:
|
|
||||||
# Name: the name of the counter, must be unique
|
# Name: the name of the counter, must be unique
|
||||||
# Type: the type of the counter, must be either:
|
# Type: the type of the counter, must be either:
|
||||||
# - cumulative: the value is incremented and never reset to 0
|
# - cumulative: the value is incremented and never reset to 0
|
||||||
@ -39,17 +38,17 @@ import collections
|
|||||||
# Timestamp: when the counter has been read
|
# Timestamp: when the counter has been read
|
||||||
# Resource metadata: various metadata
|
# Resource metadata: various metadata
|
||||||
Counter = collections.namedtuple('Counter',
|
Counter = collections.namedtuple('Counter',
|
||||||
' '.join(['source',
|
' '.join([
|
||||||
'name',
|
'name',
|
||||||
'type',
|
'type',
|
||||||
'volume',
|
'volume',
|
||||||
'user_id',
|
'user_id',
|
||||||
'project_id',
|
'project_id',
|
||||||
'resource_id',
|
'resource_id',
|
||||||
'timestamp',
|
'timestamp',
|
||||||
'resource_metadata',
|
'resource_metadata',
|
||||||
])
|
]))
|
||||||
)
|
|
||||||
|
|
||||||
TYPE_GAUGE = 'gauge'
|
TYPE_GAUGE = 'gauge'
|
||||||
TYPE_DELTA = 'delta'
|
TYPE_DELTA = 'delta'
|
||||||
|
@ -86,7 +86,6 @@ class ImagePollster(_Base):
|
|||||||
def get_counters(self, manager, context):
|
def get_counters(self, manager, context):
|
||||||
for image in self.iter_images():
|
for image in self.iter_images():
|
||||||
yield counter.Counter(
|
yield counter.Counter(
|
||||||
source='?',
|
|
||||||
name='image',
|
name='image',
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=1,
|
volume=1,
|
||||||
@ -103,7 +102,6 @@ class ImageSizePollster(_Base):
|
|||||||
def get_counters(self, manager, context):
|
def get_counters(self, manager, context):
|
||||||
for image in self.iter_images():
|
for image in self.iter_images():
|
||||||
yield counter.Counter(
|
yield counter.Counter(
|
||||||
source='?',
|
|
||||||
name='image.size',
|
name='image.size',
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=image.size,
|
volume=image.size,
|
||||||
|
@ -88,7 +88,6 @@ class ImageCRUD(ImageCRUDBase):
|
|||||||
metadata = self.notification_to_metadata(message)
|
metadata = self.notification_to_metadata(message)
|
||||||
return [
|
return [
|
||||||
counter.Counter(
|
counter.Counter(
|
||||||
source='?',
|
|
||||||
name=message['event_type'],
|
name=message['event_type'],
|
||||||
type=counter.TYPE_DELTA,
|
type=counter.TYPE_DELTA,
|
||||||
volume=1,
|
volume=1,
|
||||||
@ -107,7 +106,6 @@ class Image(ImageCRUDBase):
|
|||||||
metadata = self.notification_to_metadata(message)
|
metadata = self.notification_to_metadata(message)
|
||||||
return [
|
return [
|
||||||
counter.Counter(
|
counter.Counter(
|
||||||
source='?',
|
|
||||||
name='image',
|
name='image',
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=1,
|
volume=1,
|
||||||
@ -126,7 +124,6 @@ class ImageSize(ImageCRUDBase):
|
|||||||
metadata = self.notification_to_metadata(message)
|
metadata = self.notification_to_metadata(message)
|
||||||
return [
|
return [
|
||||||
counter.Counter(
|
counter.Counter(
|
||||||
source='?',
|
|
||||||
name='image.size',
|
name='image.size',
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=message['payload']['size'],
|
volume=message['payload']['size'],
|
||||||
@ -154,7 +151,6 @@ class ImageDownload(ImageBase):
|
|||||||
metadata = self.notification_to_metadata(message)
|
metadata = self.notification_to_metadata(message)
|
||||||
return [
|
return [
|
||||||
counter.Counter(
|
counter.Counter(
|
||||||
source='?',
|
|
||||||
name='image.download',
|
name='image.download',
|
||||||
type=counter.TYPE_DELTA,
|
type=counter.TYPE_DELTA,
|
||||||
volume=message['payload']['bytes_sent'],
|
volume=message['payload']['bytes_sent'],
|
||||||
@ -183,7 +179,6 @@ class ImageServe(ImageBase):
|
|||||||
metadata = self.notification_to_metadata(message)
|
metadata = self.notification_to_metadata(message)
|
||||||
return [
|
return [
|
||||||
counter.Counter(
|
counter.Counter(
|
||||||
source='?',
|
|
||||||
name='image.serve',
|
name='image.serve',
|
||||||
type=counter.TYPE_DELTA,
|
type=counter.TYPE_DELTA,
|
||||||
volume=message['payload']['bytes_sent'],
|
volume=message['payload']['bytes_sent'],
|
||||||
|
@ -29,6 +29,10 @@ METER_OPTS = [
|
|||||||
default='change this or be hacked',
|
default='change this or be hacked',
|
||||||
help='Secret value for signing metering messages',
|
help='Secret value for signing metering messages',
|
||||||
),
|
),
|
||||||
|
cfg.StrOpt('counter_source',
|
||||||
|
default='openstack',
|
||||||
|
help='Source for counters emited on this instance',
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -75,13 +79,13 @@ def verify_signature(message, secret):
|
|||||||
return new_sig == old_sig
|
return new_sig == old_sig
|
||||||
|
|
||||||
|
|
||||||
def meter_message_from_counter(counter, secret):
|
def meter_message_from_counter(counter, secret, source):
|
||||||
"""Make a metering message ready to be published or stored.
|
"""Make a metering message ready to be published or stored.
|
||||||
|
|
||||||
Returns a dictionary containing a metering message
|
Returns a dictionary containing a metering message
|
||||||
for a notification message and a Counter instance.
|
for a notification message and a Counter instance.
|
||||||
"""
|
"""
|
||||||
msg = {'source': counter.source,
|
msg = {'source': source,
|
||||||
'counter_name': counter.name,
|
'counter_name': counter.name,
|
||||||
'counter_type': counter.type,
|
'counter_type': counter.type,
|
||||||
'counter_volume': counter.volume,
|
'counter_volume': counter.volume,
|
||||||
|
@ -38,7 +38,6 @@ class FloatingIPPollster(plugin.CentralPollster):
|
|||||||
for ip in ips:
|
for ip in ips:
|
||||||
self.LOG.info("FLOATING IP USAGE: %s" % ip.address)
|
self.LOG.info("FLOATING IP USAGE: %s" % ip.address)
|
||||||
yield counter.Counter(
|
yield counter.Counter(
|
||||||
source='?',
|
|
||||||
name='ip.floating',
|
name='ip.floating',
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=1,
|
volume=1,
|
||||||
|
@ -71,8 +71,7 @@ class NetworkNotificationBase(plugin.NotificationBase):
|
|||||||
LOG.info('network notification %r', message)
|
LOG.info('network notification %r', message)
|
||||||
message['payload'] = message['payload'][self.resource_name]
|
message['payload'] = message['payload'][self.resource_name]
|
||||||
metadata = self.notification_to_metadata(message)
|
metadata = self.notification_to_metadata(message)
|
||||||
yield counter.Counter(source='?',
|
yield counter.Counter(name=self.resource_name,
|
||||||
name=self.resource_name,
|
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=1,
|
volume=1,
|
||||||
user_id=message['_context_user_id'],
|
user_id=message['_context_user_id'],
|
||||||
@ -84,8 +83,7 @@ class NetworkNotificationBase(plugin.NotificationBase):
|
|||||||
|
|
||||||
network_counter_name = message['event_type'].rpartition('.')[0]
|
network_counter_name = message['event_type'].rpartition('.')[0]
|
||||||
if network_counter_name != self.resource_name:
|
if network_counter_name != self.resource_name:
|
||||||
yield counter.Counter(source='?',
|
yield counter.Counter(name=network_counter_name,
|
||||||
name=network_counter_name,
|
|
||||||
type=counter.TYPE_DELTA,
|
type=counter.TYPE_DELTA,
|
||||||
volume=1,
|
volume=1,
|
||||||
user_id=message['_context_user_id'],
|
user_id=message['_context_user_id'],
|
||||||
|
@ -45,16 +45,19 @@ def register_opts(config):
|
|||||||
register_opts(cfg.CONF)
|
register_opts(cfg.CONF)
|
||||||
|
|
||||||
|
|
||||||
def publish_counter(context, counter, topic, secret):
|
def publish_counter(context, counter, topic, secret, source):
|
||||||
"""Send a metering message for the data represented by the counter.
|
"""Send a metering message for the data represented by the counter.
|
||||||
|
|
||||||
:param context: Execution context from the service or RPC call
|
:param context: Execution context from the service or RPC call
|
||||||
:param counter: ceilometer.counter.Counter instance
|
:param counter: ceilometer.counter.Counter instance
|
||||||
|
:param source: counter source
|
||||||
"""
|
"""
|
||||||
msg = {
|
msg = {
|
||||||
'method': 'record_metering_data',
|
'method': 'record_metering_data',
|
||||||
'version': '1.0',
|
'version': '1.0',
|
||||||
'args': {'data': meter.meter_message_from_counter(counter, secret),
|
'args': {'data': meter.meter_message_from_counter(counter,
|
||||||
|
secret,
|
||||||
|
source),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
LOG.debug('PUBLISH: %s', str(msg))
|
LOG.debug('PUBLISH: %s', str(msg))
|
||||||
|
@ -69,8 +69,7 @@ class Volume(_Base):
|
|||||||
|
|
||||||
def process_notification(self, message):
|
def process_notification(self, message):
|
||||||
return [
|
return [
|
||||||
counter.Counter(source='?',
|
counter.Counter(name='volume',
|
||||||
name='volume',
|
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=1,
|
volume=1,
|
||||||
user_id=message['payload']['user_id'],
|
user_id=message['payload']['user_id'],
|
||||||
@ -87,8 +86,7 @@ class VolumeSize(_Base):
|
|||||||
|
|
||||||
def process_notification(self, message):
|
def process_notification(self, message):
|
||||||
return [
|
return [
|
||||||
counter.Counter(source='?',
|
counter.Counter(name='volume.size',
|
||||||
name='volume.size',
|
|
||||||
type=counter.TYPE_GAUGE,
|
type=counter.TYPE_GAUGE,
|
||||||
volume=message['payload']['size'],
|
volume=message['payload']['size'],
|
||||||
user_id=message['payload']['user_id'],
|
user_id=message['payload']['user_id'],
|
||||||
|
@ -36,6 +36,7 @@ cinder_control_exchange cinder Exchange name
|
|||||||
quantum_control_exchange quantum Exchange name for Quantum notifications
|
quantum_control_exchange quantum Exchange name for Quantum notifications
|
||||||
metering_secret change this or be hacked Secret value for signing metering messages
|
metering_secret change this or be hacked Secret value for signing metering messages
|
||||||
metering_topic metering the topic ceilometer uses for metering messages
|
metering_topic metering the topic ceilometer uses for metering messages
|
||||||
|
counter_source openstack The source name of emited counters
|
||||||
control_exchange ceilometer AMQP exchange to connect to if using RabbitMQ or Qpid
|
control_exchange ceilometer AMQP exchange to connect to if using RabbitMQ or Qpid
|
||||||
periodic_interval 600 seconds between running periodic tasks
|
periodic_interval 600 seconds between running periodic tasks
|
||||||
os-username glance Username to use for openstack service access
|
os-username glance Username to use for openstack service access
|
||||||
|
@ -35,7 +35,6 @@ class TestListEvents(tests_api.TestBase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestListEvents, self).setUp()
|
super(TestListEvents, self).setUp()
|
||||||
self.counter1 = counter.Counter(
|
self.counter1 = counter.Counter(
|
||||||
'source1',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -49,11 +48,11 @@ class TestListEvents(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg = meter.meter_message_from_counter(self.counter1,
|
msg = meter.meter_message_from_counter(self.counter1,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'source1',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg)
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
self.counter2 = counter.Counter(
|
self.counter2 = counter.Counter(
|
||||||
'source2',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -67,6 +66,7 @@ class TestListEvents(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg2 = meter.meter_message_from_counter(self.counter2,
|
msg2 = meter.meter_message_from_counter(self.counter2,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'source2',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg2)
|
self.conn.record_metering_data(msg2)
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ class TestListProjects(tests_api.TestBase):
|
|||||||
|
|
||||||
def test_projects(self):
|
def test_projects(self):
|
||||||
counter1 = counter.Counter(
|
counter1 = counter.Counter(
|
||||||
'test_list_projects',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -52,11 +51,11 @@ class TestListProjects(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg = meter.meter_message_from_counter(counter1,
|
msg = meter.meter_message_from_counter(counter1,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test_list_projects',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg)
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
counter2 = counter.Counter(
|
counter2 = counter.Counter(
|
||||||
'test_list_users',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -70,6 +69,7 @@ class TestListProjects(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg2 = meter.meter_message_from_counter(counter2,
|
msg2 = meter.meter_message_from_counter(counter2,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test_list_users',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg2)
|
self.conn.record_metering_data(msg2)
|
||||||
|
|
||||||
@ -78,7 +78,6 @@ class TestListProjects(tests_api.TestBase):
|
|||||||
|
|
||||||
def test_with_source(self):
|
def test_with_source(self):
|
||||||
counter1 = counter.Counter(
|
counter1 = counter.Counter(
|
||||||
'test_list_users',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -92,11 +91,11 @@ class TestListProjects(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg = meter.meter_message_from_counter(counter1,
|
msg = meter.meter_message_from_counter(counter1,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test_list_users',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg)
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
counter2 = counter.Counter(
|
counter2 = counter.Counter(
|
||||||
'not-test',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -110,6 +109,7 @@ class TestListProjects(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg2 = meter.meter_message_from_counter(counter2,
|
msg2 = meter.meter_message_from_counter(counter2,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'not-test',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg2)
|
self.conn.record_metering_data(msg2)
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ class TestListResources(tests_api.TestBase):
|
|||||||
|
|
||||||
def test_instances(self):
|
def test_instances(self):
|
||||||
counter1 = counter.Counter(
|
counter1 = counter.Counter(
|
||||||
'test',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -52,11 +51,11 @@ class TestListResources(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg = meter.meter_message_from_counter(counter1,
|
msg = meter.meter_message_from_counter(counter1,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg)
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
counter2 = counter.Counter(
|
counter2 = counter.Counter(
|
||||||
'test',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -70,6 +69,7 @@ class TestListResources(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg2 = meter.meter_message_from_counter(counter2,
|
msg2 = meter.meter_message_from_counter(counter2,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg2)
|
self.conn.record_metering_data(msg2)
|
||||||
|
|
||||||
@ -78,7 +78,6 @@ class TestListResources(tests_api.TestBase):
|
|||||||
|
|
||||||
def test_with_source(self):
|
def test_with_source(self):
|
||||||
counter1 = counter.Counter(
|
counter1 = counter.Counter(
|
||||||
'test_list_resources',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -92,11 +91,11 @@ class TestListResources(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg = meter.meter_message_from_counter(counter1,
|
msg = meter.meter_message_from_counter(counter1,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test_list_resources',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg)
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
counter2 = counter.Counter(
|
counter2 = counter.Counter(
|
||||||
'not-test',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -110,6 +109,7 @@ class TestListResources(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg2 = meter.meter_message_from_counter(counter2,
|
msg2 = meter.meter_message_from_counter(counter2,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'not-test',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg2)
|
self.conn.record_metering_data(msg2)
|
||||||
|
|
||||||
@ -119,7 +119,6 @@ class TestListResources(tests_api.TestBase):
|
|||||||
|
|
||||||
def test_with_user(self):
|
def test_with_user(self):
|
||||||
counter1 = counter.Counter(
|
counter1 = counter.Counter(
|
||||||
'test_list_resources',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -133,11 +132,11 @@ class TestListResources(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg = meter.meter_message_from_counter(counter1,
|
msg = meter.meter_message_from_counter(counter1,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test_list_resources',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg)
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
counter2 = counter.Counter(
|
counter2 = counter.Counter(
|
||||||
'not-test',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -151,6 +150,7 @@ class TestListResources(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg2 = meter.meter_message_from_counter(counter2,
|
msg2 = meter.meter_message_from_counter(counter2,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'not-test',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg2)
|
self.conn.record_metering_data(msg2)
|
||||||
|
|
||||||
@ -160,7 +160,6 @@ class TestListResources(tests_api.TestBase):
|
|||||||
|
|
||||||
def test_with_project(self):
|
def test_with_project(self):
|
||||||
counter1 = counter.Counter(
|
counter1 = counter.Counter(
|
||||||
'test_list_resources',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -174,11 +173,11 @@ class TestListResources(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg = meter.meter_message_from_counter(counter1,
|
msg = meter.meter_message_from_counter(counter1,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test_list_resources',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg)
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
counter2 = counter.Counter(
|
counter2 = counter.Counter(
|
||||||
'not-test',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -192,6 +191,7 @@ class TestListResources(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg2 = meter.meter_message_from_counter(counter2,
|
msg2 = meter.meter_message_from_counter(counter2,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'not-test',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg2)
|
self.conn.record_metering_data(msg2)
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ class TestListUsers(tests_api.TestBase):
|
|||||||
|
|
||||||
def test_users(self):
|
def test_users(self):
|
||||||
counter1 = counter.Counter(
|
counter1 = counter.Counter(
|
||||||
'test_list_users',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -52,11 +51,11 @@ class TestListUsers(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg = meter.meter_message_from_counter(counter1,
|
msg = meter.meter_message_from_counter(counter1,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test_list_users',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg)
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
counter2 = counter.Counter(
|
counter2 = counter.Counter(
|
||||||
'test_list_users',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -70,6 +69,7 @@ class TestListUsers(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg2 = meter.meter_message_from_counter(counter2,
|
msg2 = meter.meter_message_from_counter(counter2,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test_list_users',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg2)
|
self.conn.record_metering_data(msg2)
|
||||||
|
|
||||||
@ -78,7 +78,6 @@ class TestListUsers(tests_api.TestBase):
|
|||||||
|
|
||||||
def test_with_source(self):
|
def test_with_source(self):
|
||||||
counter1 = counter.Counter(
|
counter1 = counter.Counter(
|
||||||
'test_list_users',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -92,11 +91,11 @@ class TestListUsers(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg = meter.meter_message_from_counter(counter1,
|
msg = meter.meter_message_from_counter(counter1,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test_list_users',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg)
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
counter2 = counter.Counter(
|
counter2 = counter.Counter(
|
||||||
'not-test',
|
|
||||||
'instance',
|
'instance',
|
||||||
'cumulative',
|
'cumulative',
|
||||||
1,
|
1,
|
||||||
@ -110,6 +109,7 @@ class TestListUsers(tests_api.TestBase):
|
|||||||
)
|
)
|
||||||
msg2 = meter.meter_message_from_counter(counter2,
|
msg2 = meter.meter_message_from_counter(counter2,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'not-test',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(msg2)
|
self.conn.record_metering_data(msg2)
|
||||||
|
|
||||||
|
@ -40,7 +40,6 @@ class TestRunTasks(base.TestCase):
|
|||||||
class Pollster:
|
class Pollster:
|
||||||
counters = []
|
counters = []
|
||||||
test_data = counter.Counter(
|
test_data = counter.Counter(
|
||||||
source='test',
|
|
||||||
name='test',
|
name='test',
|
||||||
type=counter.TYPE_CUMULATIVE,
|
type=counter.TYPE_CUMULATIVE,
|
||||||
volume=1,
|
volume=1,
|
||||||
|
@ -47,7 +47,6 @@ class TestNovaNotifier(base.TestCase):
|
|||||||
class Pollster(object):
|
class Pollster(object):
|
||||||
counters = []
|
counters = []
|
||||||
test_data = counter.Counter(
|
test_data = counter.Counter(
|
||||||
source='test',
|
|
||||||
name='test',
|
name='test',
|
||||||
type=counter.TYPE_CUMULATIVE,
|
type=counter.TYPE_CUMULATIVE,
|
||||||
volume=1,
|
volume=1,
|
||||||
|
@ -71,7 +71,6 @@ class MongoDBEngineTestBase(unittest.TestCase):
|
|||||||
self.db = self.conn.conn[self.DBNAME]
|
self.db = self.conn.conn[self.DBNAME]
|
||||||
|
|
||||||
self.counter = counter.Counter(
|
self.counter = counter.Counter(
|
||||||
'test-1',
|
|
||||||
'instance',
|
'instance',
|
||||||
counter.TYPE_CUMULATIVE,
|
counter.TYPE_CUMULATIVE,
|
||||||
1,
|
1,
|
||||||
@ -84,11 +83,11 @@ class MongoDBEngineTestBase(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.msg = meter.meter_message_from_counter(self.counter,
|
self.msg = meter.meter_message_from_counter(self.counter,
|
||||||
'not-so-secret')
|
'not-so-secret',
|
||||||
|
'test-1')
|
||||||
self.conn.record_metering_data(self.msg)
|
self.conn.record_metering_data(self.msg)
|
||||||
|
|
||||||
self.counter2 = counter.Counter(
|
self.counter2 = counter.Counter(
|
||||||
'test-2',
|
|
||||||
'instance',
|
'instance',
|
||||||
counter.TYPE_CUMULATIVE,
|
counter.TYPE_CUMULATIVE,
|
||||||
1,
|
1,
|
||||||
@ -101,11 +100,11 @@ class MongoDBEngineTestBase(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.msg2 = meter.meter_message_from_counter(self.counter2,
|
self.msg2 = meter.meter_message_from_counter(self.counter2,
|
||||||
'not-so-secret')
|
'not-so-secret',
|
||||||
|
'test-2')
|
||||||
self.conn.record_metering_data(self.msg2)
|
self.conn.record_metering_data(self.msg2)
|
||||||
|
|
||||||
self.counter3 = counter.Counter(
|
self.counter3 = counter.Counter(
|
||||||
'test-3',
|
|
||||||
'instance',
|
'instance',
|
||||||
counter.TYPE_CUMULATIVE,
|
counter.TYPE_CUMULATIVE,
|
||||||
1,
|
1,
|
||||||
@ -118,12 +117,12 @@ class MongoDBEngineTestBase(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
self.msg3 = meter.meter_message_from_counter(self.counter3,
|
self.msg3 = meter.meter_message_from_counter(self.counter3,
|
||||||
'not-so-secret')
|
'not-so-secret',
|
||||||
|
'test-3')
|
||||||
self.conn.record_metering_data(self.msg3)
|
self.conn.record_metering_data(self.msg3)
|
||||||
|
|
||||||
for i in range(2, 4):
|
for i in range(2, 4):
|
||||||
c = counter.Counter(
|
c = counter.Counter(
|
||||||
'test',
|
|
||||||
'instance',
|
'instance',
|
||||||
counter.TYPE_CUMULATIVE,
|
counter.TYPE_CUMULATIVE,
|
||||||
1,
|
1,
|
||||||
@ -135,7 +134,7 @@ class MongoDBEngineTestBase(unittest.TestCase):
|
|||||||
'tag': 'counter-%s' % i,
|
'tag': 'counter-%s' % i,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
msg = meter.meter_message_from_counter(c, 'not-so-secret')
|
msg = meter.meter_message_from_counter(c, 'not-so-secret', 'test')
|
||||||
self.conn.record_metering_data(msg)
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
@ -79,7 +79,6 @@ class SQLAlchemyEngineTestBase(unittest.TestCase):
|
|||||||
migration.db_sync()
|
migration.db_sync()
|
||||||
|
|
||||||
self.counter = counter.Counter(
|
self.counter = counter.Counter(
|
||||||
'test-1',
|
|
||||||
'instance',
|
'instance',
|
||||||
counter.TYPE_CUMULATIVE,
|
counter.TYPE_CUMULATIVE,
|
||||||
volume=1,
|
volume=1,
|
||||||
@ -93,11 +92,11 @@ class SQLAlchemyEngineTestBase(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.msg1 = meter.meter_message_from_counter(self.counter,
|
self.msg1 = meter.meter_message_from_counter(self.counter,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test-1',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(self.msg1)
|
self.conn.record_metering_data(self.msg1)
|
||||||
|
|
||||||
self.counter2 = counter.Counter(
|
self.counter2 = counter.Counter(
|
||||||
'test-2',
|
|
||||||
'instance',
|
'instance',
|
||||||
counter.TYPE_CUMULATIVE,
|
counter.TYPE_CUMULATIVE,
|
||||||
volume=1,
|
volume=1,
|
||||||
@ -111,11 +110,11 @@ class SQLAlchemyEngineTestBase(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.msg2 = meter.meter_message_from_counter(self.counter2,
|
self.msg2 = meter.meter_message_from_counter(self.counter2,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test-2',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(self.msg2)
|
self.conn.record_metering_data(self.msg2)
|
||||||
|
|
||||||
self.counter3 = counter.Counter(
|
self.counter3 = counter.Counter(
|
||||||
'test-3',
|
|
||||||
'instance',
|
'instance',
|
||||||
counter.TYPE_CUMULATIVE,
|
counter.TYPE_CUMULATIVE,
|
||||||
volume=1,
|
volume=1,
|
||||||
@ -129,12 +128,12 @@ class SQLAlchemyEngineTestBase(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
self.msg3 = meter.meter_message_from_counter(self.counter3,
|
self.msg3 = meter.meter_message_from_counter(self.counter3,
|
||||||
cfg.CONF.metering_secret,
|
cfg.CONF.metering_secret,
|
||||||
|
'test-3',
|
||||||
)
|
)
|
||||||
self.conn.record_metering_data(self.msg3)
|
self.conn.record_metering_data(self.msg3)
|
||||||
|
|
||||||
for i in range(2, 4):
|
for i in range(2, 4):
|
||||||
c = counter.Counter(
|
c = counter.Counter(
|
||||||
'test',
|
|
||||||
'instance',
|
'instance',
|
||||||
counter.TYPE_CUMULATIVE,
|
counter.TYPE_CUMULATIVE,
|
||||||
1,
|
1,
|
||||||
@ -146,7 +145,8 @@ class SQLAlchemyEngineTestBase(unittest.TestCase):
|
|||||||
'tag': 'counter-%s' % i,
|
'tag': 'counter-%s' % i,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
msg = meter.meter_message_from_counter(c, cfg.CONF.metering_secret)
|
msg = meter.meter_message_from_counter(c, cfg.CONF.metering_secret,
|
||||||
|
'test')
|
||||||
self.conn.record_metering_data(msg)
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
|
|
||||||
@ -396,7 +396,6 @@ class TestGetEventInterval(SQLAlchemyEngineTestBase):
|
|||||||
def _make_events(self, *timestamps):
|
def _make_events(self, *timestamps):
|
||||||
for t in timestamps:
|
for t in timestamps:
|
||||||
c = counter.Counter(
|
c = counter.Counter(
|
||||||
'test',
|
|
||||||
'instance',
|
'instance',
|
||||||
counter.TYPE_CUMULATIVE,
|
counter.TYPE_CUMULATIVE,
|
||||||
1,
|
1,
|
||||||
@ -407,7 +406,8 @@ class TestGetEventInterval(SQLAlchemyEngineTestBase):
|
|||||||
resource_metadata={'display_name': 'test-server',
|
resource_metadata={'display_name': 'test-server',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
msg = meter.meter_message_from_counter(c, cfg.CONF.metering_secret)
|
msg = meter.meter_message_from_counter(c, cfg.CONF.metering_secret,
|
||||||
|
'test')
|
||||||
self.conn.record_metering_data(msg)
|
self.conn.record_metering_data(msg)
|
||||||
|
|
||||||
def test_before_range(self):
|
def test_before_range(self):
|
||||||
|
@ -99,8 +99,7 @@ def test_verify_signature_nested():
|
|||||||
assert meter.verify_signature(data, 'not-so-secret')
|
assert meter.verify_signature(data, 'not-so-secret')
|
||||||
|
|
||||||
|
|
||||||
TEST_COUNTER = counter.Counter(source='src',
|
TEST_COUNTER = counter.Counter(name='name',
|
||||||
name='name',
|
|
||||||
type='typ',
|
type='typ',
|
||||||
volume=1,
|
volume=1,
|
||||||
user_id='user',
|
user_id='user',
|
||||||
@ -149,14 +148,16 @@ TEST_NOTICE = {
|
|||||||
|
|
||||||
|
|
||||||
def test_meter_message_from_counter_signed():
|
def test_meter_message_from_counter_signed():
|
||||||
msg = meter.meter_message_from_counter(TEST_COUNTER, 'not-so-secret')
|
msg = meter.meter_message_from_counter(TEST_COUNTER, 'not-so-secret',
|
||||||
|
'src')
|
||||||
assert 'message_signature' in msg
|
assert 'message_signature' in msg
|
||||||
|
|
||||||
|
|
||||||
def test_meter_message_from_counter_field():
|
def test_meter_message_from_counter_field():
|
||||||
def compare(f, c, msg_f, msg):
|
def compare(f, c, msg_f, msg):
|
||||||
assert msg == c
|
assert msg == c
|
||||||
msg = meter.meter_message_from_counter(TEST_COUNTER, 'not-so-secret')
|
msg = meter.meter_message_from_counter(TEST_COUNTER, 'not-so-secret',
|
||||||
|
'src')
|
||||||
name_map = {'name': 'counter_name',
|
name_map = {'name': 'counter_name',
|
||||||
'type': 'counter_type',
|
'type': 'counter_type',
|
||||||
'volume': 'counter_volume',
|
'volume': 'counter_volume',
|
||||||
|
@ -30,7 +30,6 @@ from ceilometer import publish
|
|||||||
class TestPublish(base.TestCase):
|
class TestPublish(base.TestCase):
|
||||||
|
|
||||||
test_data = counter.Counter(
|
test_data = counter.Counter(
|
||||||
source='test',
|
|
||||||
name='test',
|
name='test',
|
||||||
type=counter.TYPE_CUMULATIVE,
|
type=counter.TYPE_CUMULATIVE,
|
||||||
volume=1,
|
volume=1,
|
||||||
@ -53,6 +52,7 @@ class TestPublish(base.TestCase):
|
|||||||
self.test_data,
|
self.test_data,
|
||||||
'metering',
|
'metering',
|
||||||
'not-so-secret',
|
'not-so-secret',
|
||||||
|
'test',
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_notify(self):
|
def test_notify(self):
|
||||||
|
@ -113,8 +113,7 @@ def main():
|
|||||||
# Generate events
|
# Generate events
|
||||||
n = 0
|
n = 0
|
||||||
while timestamp <= end:
|
while timestamp <= end:
|
||||||
c = counter.Counter(source='artificial',
|
c = counter.Counter(name=args.counter,
|
||||||
name=args.counter,
|
|
||||||
type=args.type,
|
type=args.type,
|
||||||
volume=args.volume,
|
volume=args.volume,
|
||||||
user_id=args.user,
|
user_id=args.user,
|
||||||
@ -123,7 +122,9 @@ def main():
|
|||||||
timestamp=timestamp,
|
timestamp=timestamp,
|
||||||
resource_metadata={},
|
resource_metadata={},
|
||||||
)
|
)
|
||||||
data = meter.meter_message_from_counter(c, cfg.CONF.metering_secret)
|
data = meter.meter_message_from_counter(c,
|
||||||
|
cfg.CONF.metering_secret,
|
||||||
|
'artificial')
|
||||||
conn.record_metering_data(data)
|
conn.record_metering_data(data)
|
||||||
n += 1
|
n += 1
|
||||||
timestamp = timestamp + increment
|
timestamp = timestamp + increment
|
||||||
|
Loading…
Reference in New Issue
Block a user