Merge "Properly handle 'resource_id' as None for Gnocchi publisher"
This commit is contained in:
commit
b461ca1f18
|
@ -325,7 +325,18 @@ class GnocchiPublisher(publisher.ConfigPublisherBase):
|
|||
|
||||
# NOTE(sileht): skip sample generated by gnocchi itself
|
||||
data = [s for s in data if not self._is_gnocchi_activity(s)]
|
||||
data.sort(key=operator.attrgetter('resource_id'))
|
||||
|
||||
def value_to_sort(object_to_sort):
|
||||
value = object_to_sort.resource_id
|
||||
if not value:
|
||||
LOG.debug("Resource ID was not defined for sample data [%s]. "
|
||||
"Therefore, we will use an empty string as the "
|
||||
"resource ID.", object_to_sort)
|
||||
value = ''
|
||||
|
||||
return value
|
||||
|
||||
data.sort(key=value_to_sort)
|
||||
resource_grouped_samples = itertools.groupby(
|
||||
data, key=operator.attrgetter('resource_id'))
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue