Merge "Fix aggregator _get_unique_key method"

This commit is contained in:
Jenkins 2014-07-18 19:10:19 +00:00 committed by Gerrit Code Review
commit 30a2c65968
2 changed files with 59 additions and 2 deletions

View File

@ -1442,3 +1442,55 @@ class BasePipelineTestCase(test.BaseTestCase):
pipe.flush(None)
publisher = pipeline_manager.pipelines[0].publishers[0]
self.assertEqual(1, len(publisher.samples))
def test_aggregator_without_authentication(self):
transformer_cfg = [
{
'name': 'aggregator',
'parameters': {'size': 2},
},
]
self._set_pipeline_cfg('transformers', transformer_cfg)
self._set_pipeline_cfg('counters', ['storage.objects.outgoing.bytes'])
counters = [
sample.Sample(
name='storage.objects.outgoing.bytes',
type=sample.TYPE_DELTA,
volume=26,
unit='B',
user_id=None,
project_id=None,
resource_id='test_resource',
timestamp=timeutils.utcnow().isoformat(),
resource_metadata={'version': '1.0'}
),
sample.Sample(
name='storage.objects.outgoing.bytes',
type=sample.TYPE_DELTA,
volume=16,
unit='B',
user_id=None,
project_id=None,
resource_id='test_resource',
timestamp=timeutils.utcnow().isoformat(),
resource_metadata={'version': '2.0'}
)
]
pipeline_manager = pipeline.PipelineManager(self.pipeline_cfg,
self.transformer_manager)
pipe = pipeline_manager.pipelines[0]
pipe.publish_samples(None, [counters[0]])
pipe.flush(None)
publisher = pipe.publishers[0]
self.assertEqual(0, len(publisher.samples))
pipe.publish_samples(None, [counters[1]])
pipe.flush(None)
publisher = pipe.publishers[0]
self.assertEqual(1, len(publisher.samples))
self.assertEqual(42, getattr(publisher.samples[0], 'volume'))
self.assertEqual("test_resource", getattr(publisher.samples[0],
'resource_id'))

View File

@ -213,8 +213,13 @@ class AggregatorTransformer(ScalingTransformer):
self.key_attributes.append(name)
def _get_unique_key(self, s):
non_aggregated_keys = "-".join([getattr(s, field)
for field in self.key_attributes])
# NOTE(arezmerita): in samples generated by ceilometer middleware,
# when accessing without authentication publicly readable/writable
# swift containers, the project_id and the user_id are missing.
# They will be replaced by <undefined> for unique key construction.
keys = ['<undefined>' if getattr(s, f) is None else getattr(s, f)
for f in self.key_attributes]
non_aggregated_keys = "-".join(keys)
# NOTE(sileht): it assumes, a meter always have the same unit/type
return "%s-%s-%s" % (s.name, s.resource_id, non_aggregated_keys)