Skip to content

Commit

Permalink
add more uniqueness to cache key, and test for key
Browse files Browse the repository at this point in the history
  • Loading branch information
Kapil Thangavelu committed Oct 18, 2016
1 parent cc6090f commit 294e882
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion c7n/filters/metrics.py
Expand Up @@ -150,7 +150,11 @@ def process_resource_set(self, resource_set):
# the statistics/average over those resources.
dimensions = self.get_dimensions(r)
collected_metrics = r.setdefault('c7n.metrics', {})
key = "%s.%s" % (self.namespace, self.metric)
# Note this annotation cache is policy scoped, not across
# policies, still the lack of full qualification on the key
# means multiple filters within a policy using the same metric
# across different periods or dimensions would be problematic.
key = "%s.%s.%s" % (self.namespace, self.metric, self.statistics)
if key not in collected_metrics:
collected_metrics[key] = client.get_metric_statistics(
Namespace=self.namespace,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_s3.py
Expand Up @@ -107,6 +107,9 @@ def test_metrics(self):
resources = p.run()
self.assertEqual(len(resources), 1)
self.assertEqual(resources[0]['Name'], 'custodian-skunk-trails')
self.assertTrue('c7n.metrics' in resources[0])
self.assertTrue(
'AWS/S3.NumberOfObjects.Average' in resources[0]['c7n.metrics'])


class BucketDelete(BaseTest):
Expand Down

0 comments on commit 294e882

Please sign in to comment.