Merge "Skip duplicate meter definitions"
This commit is contained in:
commit
b273b6c460
@ -23,7 +23,7 @@ from stevedore import extension
|
||||
|
||||
from ceilometer.agent import plugin_base
|
||||
from ceilometer import declarative
|
||||
from ceilometer.i18n import _LE
|
||||
from ceilometer.i18n import _LE, _LW
|
||||
from ceilometer import sample
|
||||
from ceilometer import utils
|
||||
|
||||
@ -182,8 +182,13 @@ class ProcessMeterNotifications(plugin_base.NotificationBase):
|
||||
{}, cfg.CONF.meter.meter_definitions_cfg_file,
|
||||
pkg_resources.resource_filename(__name__, "data/meters.yaml"))
|
||||
|
||||
definitions = []
|
||||
definitions = {}
|
||||
for meter_cfg in reversed(meters_cfg['metric']):
|
||||
if meter_cfg.get('name') in definitions:
|
||||
# skip duplicate meters
|
||||
LOG.warning(_LW("Skipping duplicate meter definition %s")
|
||||
% meter_cfg)
|
||||
continue
|
||||
if (meter_cfg.get('volume') != 1
|
||||
or not cfg.CONF.notification.disable_non_metric_meters):
|
||||
try:
|
||||
@ -193,8 +198,8 @@ class ProcessMeterNotifications(plugin_base.NotificationBase):
|
||||
% dict(err=six.text_type(me)))
|
||||
LOG.error(errmsg)
|
||||
else:
|
||||
definitions.append(md)
|
||||
return definitions
|
||||
definitions[meter_cfg['name']] = md
|
||||
return definitions.values()
|
||||
|
||||
def get_targets(self, conf):
|
||||
"""Return a sequence of oslo_messaging.Target
|
||||
|
@ -349,12 +349,11 @@ class TestMeterProcessing(test.BaseTestCase):
|
||||
resource_id="$.payload.resource_id",
|
||||
project_id="$.payload.project_id")]})
|
||||
self._load_meter_def_file(cfg)
|
||||
c = list(self.handler.process_notification(NOTIFICATION))
|
||||
self.assertEqual(2, len(c))
|
||||
s1 = c[0].as_dict()
|
||||
self.assertEqual('test2', s1['name'])
|
||||
s2 = c[1].as_dict()
|
||||
self.assertEqual('test1', s2['name'])
|
||||
data = list(self.handler.process_notification(NOTIFICATION))
|
||||
self.assertEqual(2, len(data))
|
||||
expected_names = ['test1', 'test2']
|
||||
for s in data:
|
||||
self.assertTrue(s.as_dict()['name'] in expected_names)
|
||||
|
||||
def test_unmatched_meter(self):
|
||||
cfg = yaml.dump(
|
||||
@ -674,3 +673,23 @@ class TestMeterProcessing(test.BaseTestCase):
|
||||
self.assertEqual(1600, s1['volume'])
|
||||
self.assertEqual("prefix-tianst.sh.intel.com",
|
||||
s1['resource_id'])
|
||||
|
||||
def test_duplicate_meter(self):
|
||||
cfg = yaml.dump(
|
||||
{'metric': [dict(name="test1",
|
||||
event_type="test.create",
|
||||
type="delta",
|
||||
unit="B",
|
||||
volume="$.payload.volume",
|
||||
resource_id="$.payload.resource_id",
|
||||
project_id="$.payload.project_id"),
|
||||
dict(name="test1",
|
||||
event_type="test.create",
|
||||
type="delta",
|
||||
unit="B",
|
||||
volume="$.payload.volume",
|
||||
resource_id="$.payload.resource_id",
|
||||
project_id="$.payload.project_id")]})
|
||||
self._load_meter_def_file(cfg)
|
||||
c = list(self.handler.process_notification(NOTIFICATION))
|
||||
self.assertEqual(1, len(c))
|
||||
|
@ -0,0 +1,10 @@
|
||||
|
||||
|
||||
---
|
||||
fixes:
|
||||
- >
|
||||
[`bug 1536498 <https://bugs.launchpad.net/ceilometer/+bug/1536498>`_]
|
||||
Patch to fix duplicate meter definitions causing duplicate samples.
|
||||
If a duplicate is found, log a warning and skip the meter definition.
|
||||
Note that the first occurance of a meter will be used and any following
|
||||
duplicates will be skipped from processing.
|
Loading…
Reference in New Issue
Block a user