summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Weingärtner <rafael@apache.org>2022-09-11 17:02:11 -0300
committerEdward Hope-Morley <edward.hope-morley@canonical.com>2023-03-28 15:17:52 +0100
commit5968c822bebbaa47ef71d56abb4b7c2bd41fa7b9 (patch)
tree497971320cc601861a3e73c40c30ba44d0a8184f
parent7c121c45ed500beb2914f4038466508a19f28708 (diff)
downloadceilometer-stable/zed.tar.gz
Properly handle 'resource_id' as None for Gnocchi publisherstable/zed
This issue is related to [1]. In Python 3 (I did not check exactly in which version), the following code was throwing an error `data.sort(key=operator.attrgetter('resource_id'))`. Therefore, this patch is proposing a solution for such situations to properly handle samples where the `resource_id` is None. Of course, `resource_id` cannot be None in Gnocchi. However, that can be properly handled by removing the metric to be pushed from the `gnocchi_resource.yml` file. Which is what we were doing when we proposed [1]. The problem is that the sort is happening before that part of the code is executed, to decide if the sample should be ignored or not. [1] https://review.opendev.org/c/openstack/ceilometer/+/746717 Change-Id: Ie8eb42df3d5b9505160c9e9d6b86bdaa9a02d16a (cherry picked from commit b7c2c7ca965659255e9a611666e58b024c27d804)
-rw-r--r--ceilometer/tests/unit/publisher/test_gnocchi.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/ceilometer/tests/unit/publisher/test_gnocchi.py b/ceilometer/tests/unit/publisher/test_gnocchi.py
index 9a9125fb..b7b0dcab 100644
--- a/ceilometer/tests/unit/publisher/test_gnocchi.py
+++ b/ceilometer/tests/unit/publisher/test_gnocchi.py
@@ -375,18 +375,30 @@ class PublisherTest(base.BaseTestCase):
@mock.patch('ceilometer.publisher.gnocchi.GnocchiPublisher'
'.batch_measures')
def test_unhandled_meter_with_no_resource_id(self, fake_batch):
- samples = [sample.Sample(
- name='unknown.meter',
- unit='GB',
- type=sample.TYPE_GAUGE,
- volume=2,
- user_id='test_user',
- project_id='test_project',
- source='openstack',
- timestamp='2014-05-08 20:23:48.028195',
- resource_id=None,
- resource_metadata={}
- )]
+ samples = [
+ sample.Sample(
+ name='unknown.meter',
+ unit='GB',
+ type=sample.TYPE_GAUGE,
+ volume=2,
+ user_id='test_user',
+ project_id='test_project',
+ source='openstack',
+ timestamp='2014-05-08 20:23:48.028195',
+ resource_id=None,
+ resource_metadata={}),
+ sample.Sample(
+ name='unknown.meter',
+ unit='GB',
+ type=sample.TYPE_GAUGE,
+ volume=2,
+ user_id='test_user',
+ project_id='test_project',
+ source='openstack',
+ timestamp='2014-05-08 20:23:48.028195',
+ resource_id="Some-other-resource-id",
+ resource_metadata={})
+ ]
url = netutils.urlsplit("gnocchi://")
d = gnocchi.GnocchiPublisher(self.conf.conf, url)
d._already_checked_archive_policies = True