From bf2d4609882b20e6fb3ab223a48d7ebfbe3950c2 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 4 Jul 2013 16:31:04 -0400 Subject: [PATCH] Remove get_counter_names from the pollster plugins Now that there is only one meter-type coming out of each plugin, we can use the plugin name instead of asking the plugin which counters it produces. blueprint one-meter-per-plugin Change-Id: I63328b1bb2a2440771d9f1f007ff69e717d3090f Signed-off-by: Doug Hellmann --- ceilometer/agent.py | 14 +++++----- ceilometer/compute/manager.py | 33 ++++++++++++------------ ceilometer/compute/pollsters/cpu.py | 8 ------ ceilometer/compute/pollsters/disk.py | 16 ------------ ceilometer/compute/pollsters/instance.py | 11 +------- ceilometer/compute/pollsters/net.py | 16 ------------ ceilometer/energy/kwapi.py | 8 ------ ceilometer/image/glance.py | 8 ------ ceilometer/network/floatingip.py | 4 --- ceilometer/objectstore/swift.py | 12 --------- ceilometer/plugin.py | 4 --- tests/agentbase.py | 4 --- tests/compute/pollsters/test_cpu.py | 6 ++--- tests/compute/pollsters/test_diskio.py | 2 +- tests/compute/pollsters/test_net.py | 2 +- tests/image/test_glance.py | 4 +-- tests/network/test_floatingip.py | 2 +- tests/objectstore/test_swift.py | 2 +- 18 files changed, 31 insertions(+), 125 deletions(-) diff --git a/ceilometer/agent.py b/ceilometer/agent.py index 5523704b0..524b6faff 100644 --- a/ceilometer/agent.py +++ b/ceilometer/agent.py @@ -73,14 +73,12 @@ class AgentManager(object): for pipeline, pollster in itertools.product( self.pipeline_manager.pipelines, self.pollster_manager.extensions): - for counter in pollster.obj.get_counter_names(): - if pipeline.support_counter(counter): - polling_task = polling_tasks.get(pipeline.interval, None) - if not polling_task: - polling_task = self.create_polling_task() - polling_tasks[pipeline.interval] = polling_task - polling_task.add(pollster, [pipeline]) - break + if pipeline.support_counter(pollster.name): + polling_task = polling_tasks.get(pipeline.interval, None) + if not polling_task: + polling_task = self.create_polling_task() + polling_tasks[pipeline.interval] = polling_task + polling_task.add(pollster, [pipeline]) return polling_tasks diff --git a/ceilometer/compute/manager.py b/ceilometer/compute/manager.py index 98c8cf03f..adf185a6a 100644 --- a/ceilometer/compute/manager.py +++ b/ceilometer/compute/manager.py @@ -34,23 +34,22 @@ class PollingTask(agent.PollingTask): def poll_and_publish_instances(self, instances): with self.publish_context as publisher: for instance in instances: - if getattr(instance, 'OS-EXT-STS:vm_state', None) != 'error': - # TODO(yjiang5) passing counters to get_counters to avoid - # polling all counters one by one - cache = {} - for pollster in self.pollsters: - try: - LOG.info("Polling pollster %s", pollster.name) - counters = list(pollster.obj.get_counters( - self.manager, - cache, - instance, - )) - publisher(counters) - except Exception as err: - LOG.warning('Continue after error from %s: %s', - pollster.name, err) - LOG.exception(err) + if getattr(instance, 'OS-EXT-STS:vm_state', None) == 'error': + continue + cache = {} + for pollster in self.pollsters: + try: + LOG.info("Polling pollster %s", pollster.name) + counters = list(pollster.obj.get_counters( + self.manager, + cache, + instance, + )) + publisher(counters) + except Exception as err: + LOG.warning('Continue after error from %s: %s', + pollster.name, err) + LOG.exception(err) def poll_and_publish(self): self.poll_and_publish_instances( diff --git a/ceilometer/compute/pollsters/cpu.py b/ceilometer/compute/pollsters/cpu.py index 446d4b75d..7bad23fd7 100644 --- a/ceilometer/compute/pollsters/cpu.py +++ b/ceilometer/compute/pollsters/cpu.py @@ -65,10 +65,6 @@ class _Base(plugin.ComputePollster): class CPUPollster(_Base): - @staticmethod - def get_counter_names(): - return ['cpu'] - @staticmethod def _get_counter(instance, instance_name, cpu_info): LOG.info("CPUTIME USAGE: %s %d", @@ -91,10 +87,6 @@ class CPUUtilPollster(_Base): utilization_map = {} - @staticmethod - def get_counter_names(): - return ['cpu_util'] - def _get_cpu_util(self, instance, cpu_info): prev_times = self.utilization_map.get(instance.id) self.utilization_map[instance.id] = (cpu_info.time, diff --git a/ceilometer/compute/pollsters/disk.py b/ceilometer/compute/pollsters/disk.py index 15b81925a..1bf1bbf25 100644 --- a/ceilometer/compute/pollsters/disk.py +++ b/ceilometer/compute/pollsters/disk.py @@ -94,10 +94,6 @@ class _Base(plugin.ComputePollster): class ReadRequestsPollster(_Base): - @staticmethod - def get_counter_names(): - return ['disk.read.requests'] - @staticmethod def _get_counter(instance, c_data): return util.make_counter_from_instance( @@ -111,10 +107,6 @@ class ReadRequestsPollster(_Base): class ReadBytesPollster(_Base): - @staticmethod - def get_counter_names(): - return ['disk.read.bytes'] - @staticmethod def _get_counter(instance, c_data): return util.make_counter_from_instance( @@ -128,10 +120,6 @@ class ReadBytesPollster(_Base): class WriteRequestsPollster(_Base): - @staticmethod - def get_counter_names(): - return ['disk.write.requests'] - @staticmethod def _get_counter(instance, c_data): return util.make_counter_from_instance( @@ -145,10 +133,6 @@ class WriteRequestsPollster(_Base): class WriteBytesPollster(_Base): - @staticmethod - def get_counter_names(): - return ['disk.write.bytes'] - @staticmethod def _get_counter(instance, c_data): return util.make_counter_from_instance( diff --git a/ceilometer/compute/pollsters/instance.py b/ceilometer/compute/pollsters/instance.py index 5b115728b..79848b21b 100644 --- a/ceilometer/compute/pollsters/instance.py +++ b/ceilometer/compute/pollsters/instance.py @@ -25,10 +25,6 @@ from ceilometer.compute.pollsters import util class InstancePollster(plugin.ComputePollster): - @staticmethod - def get_counter_names(): - return ['instance'] - @staticmethod def get_counters(manager, cache, instance): yield util.make_counter_from_instance( @@ -42,16 +38,11 @@ class InstancePollster(plugin.ComputePollster): class InstanceFlavorPollster(plugin.ComputePollster): - @staticmethod - def get_counter_names(): - # Instance type counter is specific because it includes - # variable. We don't need such format in future - return ['instance:*'] - @staticmethod def get_counters(manager, cache, instance): yield util.make_counter_from_instance( instance, + # Use the "meter name + variable" syntax name='instance:%s' % instance.flavor['name'], type=counter.TYPE_GAUGE, diff --git a/ceilometer/compute/pollsters/net.py b/ceilometer/compute/pollsters/net.py index 3954588bf..2874bc1b9 100644 --- a/ceilometer/compute/pollsters/net.py +++ b/ceilometer/compute/pollsters/net.py @@ -91,10 +91,6 @@ class _Base(plugin.ComputePollster): class IncomingBytesPollster(_Base): - @staticmethod - def get_counter_names(): - return ['network.incoming.bytes'] - def _get_counter(self, instance, vnic, info): return self.make_vnic_counter( instance, @@ -108,10 +104,6 @@ class IncomingBytesPollster(_Base): class IncomingPacketsPollster(_Base): - @staticmethod - def get_counter_names(): - return ['network.incoming.packets'] - def _get_counter(self, instance, vnic, info): return self.make_vnic_counter( instance, @@ -125,10 +117,6 @@ class IncomingPacketsPollster(_Base): class OutgoingBytesPollster(_Base): - @staticmethod - def get_counter_names(): - return ['network.outgoing.bytes'] - def _get_counter(self, instance, vnic, info): return self.make_vnic_counter( instance, @@ -142,10 +130,6 @@ class OutgoingBytesPollster(_Base): class OutgoingPacketsPollster(_Base): - @staticmethod - def get_counter_names(): - return ['network.outgoing.packets'] - def _get_counter(self, instance, vnic, info): return self.make_vnic_counter( instance, diff --git a/ceilometer/energy/kwapi.py b/ceilometer/energy/kwapi.py index 576437a5a..e664f3d11 100644 --- a/ceilometer/energy/kwapi.py +++ b/ceilometer/energy/kwapi.py @@ -81,10 +81,6 @@ class _Base(plugin.CentralPollster): class EnergyPollster(_Base): """Measures energy consumption.""" - @staticmethod - def get_counter_names(): - return ['energy'] - def get_counters(self, manager, cache): """Returns all counters.""" for probe in self._iter_probes(manager.keystone, cache): @@ -105,10 +101,6 @@ class EnergyPollster(_Base): class PowerPollster(_Base): """Measures power consumption.""" - @staticmethod - def get_counter_names(): - return ['power'] - def get_counters(self, manager, cache): """Returns all counters.""" for probe in self._iter_probes(manager.keystone, cache): diff --git a/ceilometer/image/glance.py b/ceilometer/image/glance.py index 34115b4aa..19f47ef8c 100644 --- a/ceilometer/image/glance.py +++ b/ceilometer/image/glance.py @@ -100,10 +100,6 @@ class _Base(plugin.PollsterBase): class ImagePollster(_Base): - @staticmethod - def get_counter_names(): - return ['image'] - def get_counters(self, manager, cache): for image in self._iter_images(manager.keystone, cache): yield counter.Counter( @@ -121,10 +117,6 @@ class ImagePollster(_Base): class ImageSizePollster(_Base): - @staticmethod - def get_counter_names(): - return ['image.size'] - def get_counters(self, manager, cache): for image in self._iter_images(manager.keystone, cache): yield counter.Counter( diff --git a/ceilometer/network/floatingip.py b/ceilometer/network/floatingip.py index 5e0cc0dbd..c570a27b4 100644 --- a/ceilometer/network/floatingip.py +++ b/ceilometer/network/floatingip.py @@ -31,10 +31,6 @@ class FloatingIPPollster(plugin.CentralPollster): LOG = log.getLogger(__name__ + '.floatingip') - @staticmethod - def get_counter_names(): - return ['ip.floating'] - def _get_floating_ips(self): nv = nova_client.Client() return nv.floating_ip_get_all() diff --git a/ceilometer/objectstore/swift.py b/ceilometer/objectstore/swift.py index 7849ea051..595044b39 100644 --- a/ceilometer/objectstore/swift.py +++ b/ceilometer/objectstore/swift.py @@ -89,10 +89,6 @@ class ObjectsPollster(_Base): """Iterate over all accounts, using keystone. """ - @staticmethod - def get_counter_names(): - return ['storage.objects'] - def get_counters(self, manager, cache): for tenant, account in self._iter_accounts(manager.keystone, cache): yield counter.Counter( @@ -112,10 +108,6 @@ class ObjectsSizePollster(_Base): """Iterate over all accounts, using keystone. """ - @staticmethod - def get_counter_names(): - return ['storage.objects.size'] - def get_counters(self, manager, cache): for tenant, account in self._iter_accounts(manager.keystone, cache): yield counter.Counter( @@ -135,10 +127,6 @@ class ObjectsContainersPollster(_Base): """Iterate over all accounts, using keystone. """ - @staticmethod - def get_counter_names(): - return ['storage.objects.containers'] - def get_counters(self, manager, cache): for tenant, account in self._iter_accounts(manager.keystone, cache): yield counter.Counter( diff --git a/ceilometer/plugin.py b/ceilometer/plugin.py index b06f51343..60d8db685 100644 --- a/ceilometer/plugin.py +++ b/ceilometer/plugin.py @@ -75,10 +75,6 @@ class PollsterBase(PluginBase): __metaclass__ = abc.ABCMeta - @abc.abstractmethod - def get_counter_names(self): - """Return a sequence of Counter names supported by the pollster.""" - @abc.abstractmethod def get_counters(self, manager, cache): """Return a sequence of Counter instances from polling the resources. diff --git a/tests/agentbase.py b/tests/agentbase.py index cd5aa885a..e37b20206 100644 --- a/tests/agentbase.py +++ b/tests/agentbase.py @@ -48,10 +48,6 @@ default_test_data = counter.Counter( class TestPollster: test_data = default_test_data - @classmethod - def get_counter_names(self): - return [self.test_data.name] - def get_counters(self, manager, cache, instance=None): self.counters.append((manager, instance)) return [self.test_data] diff --git a/tests/compute/pollsters/test_cpu.py b/tests/compute/pollsters/test_cpu.py index 7b0ae98f4..66160cfde 100644 --- a/tests/compute/pollsters/test_cpu.py +++ b/tests/compute/pollsters/test_cpu.py @@ -53,8 +53,7 @@ class TestCPUPollster(base.TestPollsterBase): counters = list(pollster.get_counters(mgr, cache, self.instance)) self.assertEquals(len(counters), 1) self.assertEqual(set([c.name for c in counters]), - set(pollster.get_counter_names())) - assert counters[0].name == 'cpu' + set(['cpu'])) assert counters[0].volume == expected_time assert pollster.CACHE_KEY_CPU in cache assert self.instance.name in cache[pollster.CACHE_KEY_CPU] @@ -110,8 +109,7 @@ class TestCPUUtilPollster(base.TestPollsterBase): counters = list(pollster.get_counters(mgr, cache, self.instance)) self.assertEquals(len(counters), 1) self.assertEqual(set([c.name for c in counters]), - set(pollster.get_counter_names())) - assert counters[0].name == 'cpu_util' + set(['cpu_util'])) assert (counters[0].volume == 0.0 if zero else counters[0].volume > 0.0) assert pollster.CACHE_KEY_CPU in cache diff --git a/tests/compute/pollsters/test_diskio.py b/tests/compute/pollsters/test_diskio.py index 3678fe970..415eab551 100644 --- a/tests/compute/pollsters/test_diskio.py +++ b/tests/compute/pollsters/test_diskio.py @@ -53,7 +53,7 @@ class TestDiskPollsters(base.TestPollsterBase): assert self.instance.name in cache[pollster.CACHE_KEY_DISK] self.assertEqual(set([c.name for c in counters]), - set(pollster.get_counter_names())) + set([name])) match = [c for c in counters if c.name == name] self.assertEquals(len(match), 1, 'missing counter %s' % name) diff --git a/tests/compute/pollsters/test_net.py b/tests/compute/pollsters/test_net.py index 711a71e95..c928298f1 100644 --- a/tests/compute/pollsters/test_net.py +++ b/tests/compute/pollsters/test_net.py @@ -77,7 +77,7 @@ class TestNetPollster(base.TestPollsterBase): counters = list(pollster.get_counters(mgr, {}, self.instance)) self.assertEqual(len(counters), 3) # one for each nic self.assertEqual(set([c.name for c in counters]), - set(pollster.get_counter_names())) + set([counters[0].name])) def _verify_vnic_metering(ip, expected_volume, expected_rid): match = [c for c in counters diff --git a/tests/image/test_glance.py b/tests/image/test_glance.py index dc79e0f46..05736e33b 100644 --- a/tests/image/test_glance.py +++ b/tests/image/test_glance.py @@ -166,10 +166,10 @@ class TestImagePollster(base.TestCase): def test_image_get_counter_names(self): counters = list(glance.ImagePollster().get_counters(self.manager, {})) self.assertEqual(set([c.name for c in counters]), - set(glance.ImagePollster().get_counter_names())) + set(['image'])) def test_image_size_get_counter_names(self): counters = list(glance.ImageSizePollster().get_counters(self.manager, {})) self.assertEqual(set([c.name for c in counters]), - set(glance.ImageSizePollster().get_counter_names())) + set(['image.size'])) diff --git a/tests/network/test_floatingip.py b/tests/network/test_floatingip.py index e7d3c94f0..0cb88e190 100644 --- a/tests/network/test_floatingip.py +++ b/tests/network/test_floatingip.py @@ -84,7 +84,7 @@ class TestFloatingIPPollster(base.TestCase): def test_get_counter_names(self): counters = list(self.pollster.get_counters(self.manager, {})) self.assertEqual(set([c.name for c in counters]), - set(self.pollster.get_counter_names())) + set(['ip.floating'])) def test_get_counters_cached(self): cache = {} diff --git a/tests/objectstore/test_swift.py b/tests/objectstore/test_swift.py index 8b50f875b..c8dd8c345 100644 --- a/tests/objectstore/test_swift.py +++ b/tests/objectstore/test_swift.py @@ -132,7 +132,7 @@ class TestSwiftPollster(base.TestCase): self.fake_iter_accounts) counters = list(self.pollster.get_counters(self.manager, {})) self.assertEqual(set([c.name for c in counters]), - set(self.pollster.get_counter_names())) + set([counters[0].name])) def test_endpoint_notfound(self): self.stubs.Set(self.manager.keystone.service_catalog, 'url_for',