Merge "add counter type field"

This commit is contained in:
Jenkins 2012-06-07 17:06:01 +00:00 committed by Gerrit Code Review
commit c491a93a39
12 changed files with 36 additions and 21 deletions

View File

@ -75,7 +75,7 @@ class AgentManager(manager.Manager):
} }
rpc.cast(context, cfg.CONF.metering_topic, msg) rpc.cast(context, cfg.CONF.metering_topic, msg)
rpc.cast(context, rpc.cast(context,
cfg.CONF.metering_topic + '.' + c.type, cfg.CONF.metering_topic + '.' + c.name,
msg) msg)
except Exception as err: except Exception as err:
LOG.warning('Continuing after error from %s: %s', name, err) LOG.warning('Continuing after error from %s: %s', name, err)

View File

@ -81,7 +81,7 @@ class CollectorManager(manager.Manager):
ctxt = context.get_admin_context() ctxt = context.get_admin_context()
nova_rpc.cast(ctxt, cfg.CONF.metering_topic, msg) nova_rpc.cast(ctxt, cfg.CONF.metering_topic, msg)
nova_rpc.cast(ctxt, nova_rpc.cast(ctxt,
cfg.CONF.metering_topic + '.' + counter.type, cfg.CONF.metering_topic + '.' + counter.name,
msg) msg)
def record_metering_data(self, context, data): def record_metering_data(self, context, data):

View File

@ -33,9 +33,10 @@ FLAGS = flags.FLAGS
MIB = 2 ** 20 # mebibytes MIB = 2 ** 20 # mebibytes
def make_counter_from_instance(instance, type, volume): def make_counter_from_instance(instance, name, type, volume):
return counter.Counter( return counter.Counter(
source='?', source='?',
name=name,
type=type, type=type,
volume=volume, volume=volume,
user_id=instance.user_id, user_id=instance.user_id,
@ -87,7 +88,8 @@ class DiskIOPollster(plugin.PollsterBase):
stats[2], stats[3], stats[4]) stats[2], stats[3], stats[4])
bytes += stats[1] + stats[3] # combine read and write bytes += stats[1] + stats[3] # combine read and write
yield make_counter_from_instance(instance, yield make_counter_from_instance(instance,
type='disk', name='disk',
type='cumulative',
volume=bytes / MIB, volume=bytes / MIB,
) )
@ -108,7 +110,8 @@ class CPUPollster(plugin.PollsterBase):
self.LOG.info("CPUTIME USAGE: %s %d", self.LOG.info("CPUTIME USAGE: %s %d",
instance, cpu_info['cpu_time']) instance, cpu_info['cpu_time'])
yield make_counter_from_instance(instance, yield make_counter_from_instance(instance,
type='cpu', name='cpu',
type='cumulative',
volume=cpu_info['cpu_time'], volume=cpu_info['cpu_time'],
) )
except Exception as err: except Exception as err:

View File

@ -37,12 +37,13 @@ class FloatingIPPollster(plugin.PollsterBase):
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(source='?', yield counter.Counter(source='?',
type='floating_ip', name='floating_ip',
type='delta',
volume=1, volume=1,
user_id=None, user_id=None,
project_id=ip.project_id, project_id=ip.project_id,
resource_id=ip.id, resource_id=ip.id,
datetime=None, timestamp=None,
duration=None, duration=None,
resource_metadata={ resource_metadata={
'address': ip.address, 'address': ip.address,

View File

@ -26,7 +26,8 @@ def c1(body):
"""Generate c1(instance) counters for a notice.""" """Generate c1(instance) counters for a notice."""
return counter.Counter( return counter.Counter(
source='?', source='?',
type='instance', name='instance',
type='delta',
volume=1, volume=1,
user_id=body['payload']['user_id'], user_id=body['payload']['user_id'],
project_id=body['payload']['tenant_id'], project_id=body['payload']['tenant_id'],

View File

@ -27,6 +27,7 @@ import collections
Counter = collections.namedtuple('Counter', Counter = collections.namedtuple('Counter',
' '.join(['source', ' '.join(['source',
'name',
'type', 'type',
'volume', 'volume',
'user_id', 'user_id',

View File

@ -59,6 +59,7 @@ def meter_message_from_counter(counter):
for a notification message and a Counter instance. for a notification message and a Counter instance.
""" """
msg = {'source': counter.source, msg = {'source': counter.source,
'counter_name': counter.name,
'counter_type': counter.type, 'counter_type': counter.type,
'counter_volume': counter.volume, 'counter_volume': counter.volume,
'user_id': counter.user_id, 'user_id': counter.user_id,

View File

@ -41,7 +41,8 @@ class TestRunTasks(test.TestCase):
counters = [] counters = []
test_data = counter.Counter( test_data = counter.Counter(
source='test', source='test',
type='test', name='test',
type='cumulative',
volume=1, volume=1,
user_id='test', user_id='test',
project_id='test', project_id='test',

View File

@ -73,7 +73,7 @@ def test_notify():
d.notify(TEST_NOTICE) d.notify(TEST_NOTICE)
assert len(results) == 1 assert len(results) == 1
counter = results[0] counter = results[0]
assert counter.type == 'instance' assert counter.name == 'instance'
def test_load_compute_plugins(): def test_load_compute_plugins():
@ -103,4 +103,4 @@ def test_notify_through_plugin():
d.notify(TEST_NOTICE) d.notify(TEST_NOTICE)
assert len(results) == 1 assert len(results) == 1
counter = results[0] counter = results[0]
assert counter.type == 'instance' assert counter.name == 'instance'

View File

@ -34,19 +34,23 @@ class TestFloatingIPPollster(test.TestCase):
super(TestFloatingIPPollster, self).setUp() super(TestFloatingIPPollster, self).setUp()
def test_get_counters(self): def test_get_counters(self):
self.assertEqual(list(self.pollster.get_counters(self.manager, self.context)), []) self.assertEqual(list(self.pollster.get_counters(self.manager,
self.context)),
[])
def test_get_counters_not_empty(self): def test_get_counters_not_empty(self):
db.floating_ip_create(self.context, db.floating_ip_create(self.context,
{'address': '1.1.1.1', {'address': '1.1.1.1',
'host': self.manager.host }) 'host': self.manager.host,
})
db.floating_ip_create(self.context, db.floating_ip_create(self.context,
{'address': '1.1.1.2', {'address': '1.1.1.2',
'host': self.manager.host + "randomstring" }) 'host': self.manager.host + "randomstring",
})
db.floating_ip_create(self.context, db.floating_ip_create(self.context,
{'address': '1.1.1.3', {'address': '1.1.1.3',
'host': self.manager.host + "randomstring" }) 'host': self.manager.host + "randomstring",
})
counters = list(self.pollster.get_counters(self.manager, self.context)) counters = list(self.pollster.get_counters(self.manager, self.context))
self.assertEqual(len(counters), 1) self.assertEqual(len(counters), 1)
self.assertEqual(counters[0].resource_metadata['address'], '1.1.1.1') self.assertEqual(counters[0].resource_metadata['address'], '1.1.1.1')

View File

@ -135,7 +135,8 @@ def test_c1():
info = notifications.c1(INSTANCE_CREATE_END) info = notifications.c1(INSTANCE_CREATE_END)
for name, actual, expected in [ for name, actual, expected in [
('counter_type', info.type, 'instance'), ('counter_name', info.name, 'instance'),
('counter_type', info.type, 'delta'),
('counter_volume', info.volume, 1), ('counter_volume', info.volume, 1),
('timestamp', info.timestamp, ('timestamp', info.timestamp,
INSTANCE_CREATE_END['timestamp']), INSTANCE_CREATE_END['timestamp']),
@ -155,18 +156,18 @@ def test_instance_create():
ic = notifications.InstanceNotifications() ic = notifications.InstanceNotifications()
counters = ic.process_notification(INSTANCE_CREATE_END) counters = ic.process_notification(INSTANCE_CREATE_END)
assert len(counters) == 1 assert len(counters) == 1
assert counters[0].type == 'instance' assert counters[0].name == 'instance'
def test_instance_exists(): def test_instance_exists():
ic = notifications.InstanceNotifications() ic = notifications.InstanceNotifications()
counters = ic.process_notification(INSTANCE_EXISTS) counters = ic.process_notification(INSTANCE_EXISTS)
assert len(counters) == 1 assert len(counters) == 1
assert counters[0].type == 'instance' assert counters[0].name == 'instance'
def test_instance_delete(): def test_instance_delete():
ic = notifications.InstanceNotifications() ic = notifications.InstanceNotifications()
counters = ic.process_notification(INSTANCE_DELETE_START) counters = ic.process_notification(INSTANCE_DELETE_START)
assert len(counters) == 1 assert len(counters) == 1
assert counters[0].type == 'instance' assert counters[0].name == 'instance'

View File

@ -62,6 +62,7 @@ def test_compute_signature_use_configured_secret():
TEST_COUNTER = counter.Counter(source='src', TEST_COUNTER = counter.Counter(source='src',
name='name',
type='typ', type='typ',
volume=1, volume=1,
user_id='user', user_id='user',
@ -124,7 +125,8 @@ 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) msg = meter.meter_message_from_counter(TEST_COUNTER)
name_map = {'type': 'counter_type', name_map = {'name': 'counter_name',
'type': 'counter_type',
'volume': 'counter_volume', 'volume': 'counter_volume',
'duration': 'counter_duration', 'duration': 'counter_duration',
} }