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