Remove deprecated archive policy map for Gnocchi

Change-Id: I3de9685dad82f02fc2f4b2b680cf4eac8fe1ca66
This commit is contained in:
Julien Danjou 2015-09-25 16:36:29 +02:00
parent c4f0ce7163
commit 6fa2f7d522
3 changed files with 4 additions and 71 deletions

View File

@ -1,8 +1,5 @@
#
# Copyright 2014 eNovance
#
# Authors: Julien Danjou <julien@danjou.info>
# Mehdi Abaakouk <mehdi.abaakouk@enovance.com>
# Copyright 2014-2015 eNovance
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@ -51,11 +48,6 @@ dispatcher_opts = [
default="low",
help='The archive policy to use when the dispatcher '
'create a new metric.'),
cfg.StrOpt('archive_policy_file',
default='gnocchi_archive_policy_map.yaml',
deprecated_for_removal=True,
help=_('The Yaml file that defines per metric archive '
'policies.')),
cfg.StrOpt('resources_definition_file',
default='gnocchi_resources.yaml',
help=_('The Yaml file that defines mapping between samples '
@ -74,20 +66,6 @@ def log_and_ignore_unexpected_workflow_error(func):
return log_and_ignore
class LegacyArchivePolicyDefinition(object):
def __init__(self, definition_cfg):
self.cfg = definition_cfg
if self.cfg is None:
LOG.debug("No archive policy file found! Using default config.")
def get(self, metric_name):
if self.cfg is not None:
for metric, policy in self.cfg.items():
# Support wild cards such as disk.*
if fnmatch.fnmatch(metric_name, metric):
return policy
class ResourcesDefinitionException(Exception):
def __init__(self, message, definition_cfg):
super(ResourcesDefinitionException, self).__init__(message)
@ -105,11 +83,8 @@ class ResourcesDefinition(object):
JSONPATH_RW_PARSER = parser.ExtentedJsonPathParser()
def __init__(self, definition_cfg, default_archive_policy,
legacy_archive_policy_definition):
def __init__(self, definition_cfg, default_archive_policy):
self._default_archive_policy = default_archive_policy
self._legacy_archive_policy_definition =\
legacy_archive_policy_definition
self.cfg = definition_cfg
for field, field_type in self.MANDATORY_FIELDS.items():
@ -163,9 +138,7 @@ class ResourcesDefinition(object):
def metrics(self):
metrics = {}
for t in self.cfg['metrics']:
archive_policy = self.cfg.get(
'archive_policy',
self._legacy_archive_policy_definition.get(t))
archive_policy = self.cfg.get('archive_policy')
metrics[t] = dict(archive_policy_name=archive_policy or
self._default_archive_policy)
return metrics
@ -178,7 +151,6 @@ class GnocchiDispatcher(dispatcher.Base):
self.filter_service_activity = (
conf.dispatcher_gnocchi.filter_service_activity)
self._ks_client = keystone_client.get_client()
self.gnocchi_archive_policy_data = self._load_archive_policy(conf)
self.resources_definition = self._load_resources_definitions(conf)
self._gnocchi_project_id = None
@ -207,24 +179,9 @@ class GnocchiDispatcher(dispatcher.Base):
except ValueError:
data = {}
legacy_archive_policies = cls._load_archive_policy(conf)
return [ResourcesDefinition(r, conf.dispatcher_gnocchi.archive_policy,
legacy_archive_policies)
return [ResourcesDefinition(r, conf.dispatcher_gnocchi.archive_policy)
for r in data.get('resources', [])]
@classmethod
def _load_archive_policy(cls, conf):
policy_config_file = cls._get_config_file(
conf, conf.dispatcher_gnocchi.archive_policy_file)
data = {}
if policy_config_file is not None:
with open(policy_config_file) as data_file:
try:
data = yaml.safe_load(data_file)
except ValueError:
data = {}
return LegacyArchivePolicyDefinition(data)
@property
def gnocchi_project_id(self):
if self._gnocchi_project_id is not None:

View File

@ -26,9 +26,7 @@ from oslotest import mockpatch
import requests
import six
import six.moves.urllib.parse as urlparse
import tempfile
import testscenarios
import yaml
from ceilometer.dispatcher import gnocchi
from ceilometer import service as ceilometer_service
@ -157,21 +155,6 @@ class DispatcherTest(base.BaseTestCase):
fake_process_resource.assert_called_with(self.resource_id,
mock.ANY)
def test_archive_policy_map_config(self):
archive_policy_map = yaml.dump({
'foo.*': 'low'
})
archive_policy_cfg_file = tempfile.NamedTemporaryFile(
mode='w+b', prefix="foo", suffix=".yaml")
archive_policy_cfg_file.write(archive_policy_map.encode())
archive_policy_cfg_file.seek(0)
self.conf.conf.dispatcher_gnocchi.archive_policy_file = (
archive_policy_cfg_file.name)
d = gnocchi.GnocchiDispatcher(self.conf.conf)
legacy = d._load_archive_policy(self.conf.conf)
self.assertEqual(legacy.get('foo.disk.rate'), "low")
archive_policy_cfg_file.close()
def test_activity_filter_match_project_id(self):
self.samples[0]['project_id'] = (
'a2d42c23-d518-46b6-96ab-3fba2e146859')

View File

@ -1,7 +0,0 @@
# This file is used to map a metric name to corresponding archive policy
# and used by the ceilometer dispatcher.
# Format: <metric_name>: <policy>
#cpu_utils: "high"
#disk.*: "low"