Skip to content

Commit

Permalink
Merge "Rename get_counters to get_samples"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Aug 5, 2013
2 parents 27eab58 + a34bcb7 commit 082427d
Show file tree
Hide file tree
Showing 24 changed files with 150 additions and 151 deletions.
6 changes: 3 additions & 3 deletions ceilometer/central/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ class PollingTask(agent.PollingTask):
def poll_and_publish(self):
"""Tasks to be run at a periodic interval."""
with self.publish_context as publisher:
# TODO(yjiang5) passing counters into get_counters to avoid
# TODO(yjiang5) passing samples into get_samples 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(
samples = list(pollster.obj.get_samples(
self.manager,
cache,
))
publisher(counters)
publisher(samples)
except Exception as err:
LOG.warning('Continue after error from %s: %s',
pollster.name, err)
Expand Down
4 changes: 2 additions & 2 deletions ceilometer/compute/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def poll_and_publish_instances(self, instances):
for pollster in self.pollsters:
try:
LOG.info("Polling pollster %s", pollster.name)
counters = list(pollster.obj.get_counters(
samples = list(pollster.obj.get_samples(
self.manager,
cache,
instance,
))
publisher(counters)
publisher(samples)
except Exception as err:
LOG.warning('Continue after error from %s: %s',
pollster.name, err)
Expand Down
15 changes: 7 additions & 8 deletions ceilometer/compute/nova_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,20 @@ def __init__(self, extensions):
self.mgr = extensions
self.inspector = inspector.get_hypervisor_inspector()

def _get_counters_from_plugin(self, ext, cache, instance, *args, **kwds):
def _get_samples_from_plugin(self, ext, cache, instance, *args, **kwds):
"""Used with the extenaion manager map() method."""
return ext.obj.get_counters(self, cache, instance)
return ext.obj.get_samples(self, cache, instance)

def __call__(self, instance):
cache = {}
counters = self.mgr.map(self._get_counters_from_plugin,
cache=cache,
instance=instance,
)
samples = self.mgr.map(self._get_samples_from_plugin,
cache=cache,
instance=instance)
# counters is a list of lists, so flatten it before returning
# the results
results = []
for clist in counters:
results.extend(clist)
for slist in samples:
results.extend(slist)
return results


Expand Down
2 changes: 1 addition & 1 deletion ceilometer/compute/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ComputePollster(plugin.PollsterBase):
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def get_counters(self, manager, cache, instance):
def get_samples(self, manager, cache, instance):
"""Return a sequence of Counter instances from polling the resources.
:param manager: The service manager invoking the plugin
Expand Down
2 changes: 1 addition & 1 deletion ceilometer/compute/pollsters/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class CPUPollster(plugin.ComputePollster):

def get_counters(self, manager, cache, instance):
def get_samples(self, manager, cache, instance):
LOG.info('checking instance %s', instance.id)
instance_name = util.instance_name(instance)
try:
Expand Down
2 changes: 1 addition & 1 deletion ceilometer/compute/pollsters/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _populate_cache(self, inspector, cache, instance, instance_name):
def _get_counter(instance, c_data):
"""Return one Counter."""

def get_counters(self, manager, cache, instance):
def get_samples(self, manager, cache, instance):
instance_name = util.instance_name(instance)
c_data = self._populate_cache(
manager.inspector,
Expand Down
4 changes: 2 additions & 2 deletions ceilometer/compute/pollsters/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class InstancePollster(plugin.ComputePollster):

@staticmethod
def get_counters(manager, cache, instance):
def get_samples(manager, cache, instance):
yield util.make_counter_from_instance(
instance,
name='instance',
Expand All @@ -39,7 +39,7 @@ def get_counters(manager, cache, instance):
class InstanceFlavorPollster(plugin.ComputePollster):

@staticmethod
def get_counters(manager, cache, instance):
def get_samples(manager, cache, instance):
yield util.make_counter_from_instance(
instance,
# Use the "meter name + variable" syntax
Expand Down
2 changes: 1 addition & 1 deletion ceilometer/compute/pollsters/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def _get_vnics_for_instance(self, cache, inspector, instance_name):
)
return i_cache[instance_name]

def get_counters(self, manager, cache, instance):
def get_samples(self, manager, cache, instance):
instance_name = util.instance_name(instance)
LOG.info('checking instance %s', instance.id)
try:
Expand Down
4 changes: 2 additions & 2 deletions ceilometer/energy/kwapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _get_probes(self, ksclient):
class EnergyPollster(_Base):
"""Measures energy consumption."""

def get_counters(self, manager, cache):
def get_samples(self, manager, cache):
"""Returns all counters."""
for probe in self._iter_probes(manager.keystone, cache):
yield sample.Sample(
Expand All @@ -102,7 +102,7 @@ def get_counters(self, manager, cache):
class PowerPollster(_Base):
"""Measures power consumption."""

def get_counters(self, manager, cache):
def get_samples(self, manager, cache):
"""Returns all counters."""
for probe in self._iter_probes(manager.keystone, cache):
yield sample.Sample(
Expand Down
4 changes: 2 additions & 2 deletions ceilometer/image/glance.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def extract_image_metadata(image):

class ImagePollster(_Base):

def get_counters(self, manager, cache):
def get_samples(self, manager, cache):
for image in self._iter_images(manager.keystone, cache):
yield sample.Sample(
name='image',
Expand All @@ -118,7 +118,7 @@ def get_counters(self, manager, cache):

class ImageSizePollster(_Base):

def get_counters(self, manager, cache):
def get_samples(self, manager, cache):
for image in self._iter_images(manager.keystone, cache):
yield sample.Sample(
name='image.size',
Expand Down
2 changes: 1 addition & 1 deletion ceilometer/network/floatingip.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _iter_floating_ips(self, cache):
cache['floating_ips'] = list(self._get_floating_ips())
return iter(cache['floating_ips'])

def get_counters(self, manager, cache):
def get_samples(self, manager, cache):
for ip in self._iter_floating_ips(cache):
self.LOG.info("FLOATING IP USAGE: %s" % ip.ip)
# FIXME (flwang) Now Nova API /os-floating-ips can't provide those
Expand Down
6 changes: 3 additions & 3 deletions ceilometer/objectstore/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ObjectsPollster(_Base):
"""Iterate over all accounts, using keystone.
"""

def get_counters(self, manager, cache):
def get_samples(self, manager, cache):
for tenant, account in self._iter_accounts(manager.keystone, cache):
yield sample.Sample(
name='storage.objects',
Expand All @@ -101,7 +101,7 @@ class ObjectsSizePollster(_Base):
"""Iterate over all accounts, using keystone.
"""

def get_counters(self, manager, cache):
def get_samples(self, manager, cache):
for tenant, account in self._iter_accounts(manager.keystone, cache):
yield sample.Sample(
name='storage.objects.size',
Expand All @@ -120,7 +120,7 @@ class ObjectsContainersPollster(_Base):
"""Iterate over all accounts, using keystone.
"""

def get_counters(self, manager, cache):
def get_samples(self, manager, cache):
for tenant, account in self._iter_accounts(manager.keystone, cache):
yield sample.Sample(
name='storage.objects.containers',
Expand Down
2 changes: 1 addition & 1 deletion ceilometer/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class PollsterBase(PluginBase):
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def get_counters(self, manager, cache):
def get_samples(self, manager, cache):
"""Return a sequence of Counter instances from polling the resources.
:param manager: The service manager class invoking the plugin.
Expand Down
8 changes: 4 additions & 4 deletions doc/source/contributing/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ information follows.
The compute agent is implemented in ``ceilometer/compute/manager.py``. As
you will see in the manager, the computeagent loads all plugins defined in
the namespace ``ceilometer.poll.compute``, then periodically calls their
:func:`get_counters` method.
:func:`get_samples` method.

The central agent polls other types of resources from a management server.
The central agent is defined in ``ceilometer/central/manager.py``. It loads
plugins from the ``ceilometer.poll.central`` namespace and polls them by
calling their :func:`get_counters` method.
calling their :func:`get_samples` method.

Plugins
=======
Expand All @@ -64,11 +64,11 @@ Pollster
Compute plugins are defined as subclasses of the
:class:`ceilometer.compute.plugin.ComputePollster` class as defined in
the ``ceilometer/compute/plugin.py`` file. Pollsters must implement one
method: ``get_counters(self, manager, context)``, which returns a
method: ``get_samples(self, manager, context)``, which returns a
sequence of ``Counter`` objects as defined in the
``ceilometer/counter.py`` file.

In the ``CPUPollster`` plugin, the ``get_counters`` method is implemented as a loop
In the ``CPUPollster`` plugin, the ``get_samples`` method is implemented as a loop
which, for each instances running on the local host, retrieves the cpu_time
from the hypervisor and sends back two ``Counter`` objects. The first one, named
"cpu", is of type "cumulative", meaning that between two polls, its value is
Expand Down
2 changes: 1 addition & 1 deletion nova_tests/test_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Pollster(object):
},
)

def get_counters(self, manager, cache, instance):
def get_samples(self, manager, cache, instance):
self.instances.append((manager, instance))
return [self.test_data]

Expand Down
6 changes: 3 additions & 3 deletions tests/agentbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@
class TestPollster:
test_data = default_test_data

def get_counters(self, manager, cache, instance=None):
def get_samples(self, manager, cache, instance=None):
self.counters.append((manager, instance))
return [self.test_data]


class TestPollsterException(TestPollster):
def get_counters(self, manager, cache, instance=None):
def get_samples(self, manager, cache, instance=None):
# Put an instance parameter here so that it can be used
# by both central manager and compute manager
# In future, we possibly don't need such hack if we
# combine the get_counters() function again
# combine the get_samples() function again
self.counters.append((manager, instance))
raise Exception()

Expand Down
20 changes: 10 additions & 10 deletions tests/compute/pollsters/test_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def setUp(self):
super(TestCPUPollster, self).setUp()

@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_counters(self):
def test_get_samples(self):
self.inspector.inspect_cpus(self.instance.name).AndReturn(
virt_inspector.CPUStats(time=1 * (10 ** 6), number=2))
self.inspector.inspect_cpus(self.instance.name).AndReturn(
Expand All @@ -50,12 +50,12 @@ def test_get_counters(self):

def _verify_cpu_metering(expected_time):
cache = {}
counters = list(pollster.get_counters(mgr, cache, self.instance))
self.assertEquals(len(counters), 1)
self.assertEqual(set([c.name for c in counters]),
samples = list(pollster.get_samples(mgr, cache, self.instance))
self.assertEquals(len(samples), 1)
self.assertEqual(set([s.name for s in samples]),
set(['cpu']))
assert counters[0].volume == expected_time
self.assertEquals(counters[0].resource_metadata.get('cpu_number'),
assert samples[0].volume == expected_time
self.assertEquals(samples[0].resource_metadata.get('cpu_number'),
2)
# ensure elapsed time between polling cycles is non-zero
time.sleep(0.001)
Expand All @@ -65,7 +65,7 @@ def _verify_cpu_metering(expected_time):
_verify_cpu_metering(2 * (10 ** 6))

@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_counters_no_caching(self):
def test_get_samples_no_caching(self):
self.inspector.inspect_cpus(self.instance.name).AndReturn(
virt_inspector.CPUStats(time=1 * (10 ** 6), number=2))
self.mox.ReplayAll()
Expand All @@ -74,7 +74,7 @@ def test_get_counters_no_caching(self):
pollster = cpu.CPUPollster()

cache = {}
counters = list(pollster.get_counters(mgr, cache, self.instance))
self.assertEquals(len(counters), 1)
self.assertEquals(counters[0].volume, 10 ** 6)
samples = list(pollster.get_samples(mgr, cache, self.instance))
self.assertEquals(len(samples), 1)
self.assertEquals(samples[0].volume, 10 ** 6)
self.assertEquals(len(cache), 0)
26 changes: 13 additions & 13 deletions tests/compute/pollsters/test_diskio.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,36 @@ def setUp(self):
self.mox.ReplayAll()

@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def _check_get_counters(self, factory, name, expected_volume):
def _check_get_samples(self, factory, name, expected_volume):
pollster = factory()

mgr = manager.AgentManager()
cache = {}
counters = list(pollster.get_counters(mgr, cache, self.instance))
assert counters
samples = list(pollster.get_samples(mgr, cache, self.instance))
assert samples
assert pollster.CACHE_KEY_DISK in cache
assert self.instance.name in cache[pollster.CACHE_KEY_DISK]

self.assertEqual(set([c.name for c in counters]),
self.assertEqual(set([s.name for s in samples]),
set([name]))

match = [c for c in counters if c.name == name]
match = [s for s in samples if s.name == name]
self.assertEquals(len(match), 1, 'missing counter %s' % name)
self.assertEquals(match[0].volume, expected_volume)
self.assertEquals(match[0].type, 'cumulative')

def test_disk_read_requests(self):
self._check_get_counters(disk.ReadRequestsPollster,
'disk.read.requests', 2L)
self._check_get_samples(disk.ReadRequestsPollster,
'disk.read.requests', 2L)

def test_disk_read_bytes(self):
self._check_get_counters(disk.ReadBytesPollster,
'disk.read.bytes', 1L)
self._check_get_samples(disk.ReadBytesPollster,
'disk.read.bytes', 1L)

def test_disk_write_requests(self):
self._check_get_counters(disk.WriteRequestsPollster,
'disk.write.requests', 4L)
self._check_get_samples(disk.WriteRequestsPollster,
'disk.write.requests', 4L)

def test_disk_write_bytes(self):
self._check_get_counters(disk.WriteBytesPollster,
'disk.write.bytes', 3L)
self._check_get_samples(disk.WriteBytesPollster,
'disk.write.bytes', 3L)
16 changes: 8 additions & 8 deletions tests/compute/pollsters/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ def setUp(self):
super(TestInstancePollster, self).setUp()

@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_counters_instance(self):
def test_get_samples_instance(self):
self.mox.ReplayAll()

mgr = manager.AgentManager()
pollster = pollsters_instance.InstancePollster()
counters = list(pollster.get_counters(mgr, {}, self.instance))
self.assertEquals(len(counters), 1)
self.assertEqual(counters[0].name, 'instance')
samples = list(pollster.get_samples(mgr, {}, self.instance))
self.assertEquals(len(samples), 1)
self.assertEqual(samples[0].name, 'instance')

@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def test_get_counters_instance_flavor(self):
def test_get_samples_instance_flavor(self):
self.mox.ReplayAll()

mgr = manager.AgentManager()
pollster = pollsters_instance.InstanceFlavorPollster()
counters = list(pollster.get_counters(mgr, {}, self.instance))
self.assertEquals(len(counters), 1)
self.assertEqual(counters[0].name, 'instance:m1.small')
samples = list(pollster.get_samples(mgr, {}, self.instance))
self.assertEquals(len(samples), 1)
self.assertEqual(samples[0].name, 'instance:m1.small')
Loading

0 comments on commit 082427d

Please sign in to comment.