Add DEFAULT_ARCHIVE_POLICY config option for gnocchi
Added a DEFAULT_ARCHIVE_POLICY option to Gnocchi plugin, The user can now configure the archive policy that the metrics should use. Change-Id: I445c4bc98b6431a39cf805a00b6237d8090a0b98
This commit is contained in:
parent
6ecac9f099
commit
1defcfb65c
@ -59,6 +59,8 @@ class Config(object):
|
|||||||
CfgParam('OS_TENANT_NAME', None, six.text_type),
|
CfgParam('OS_TENANT_NAME', None, six.text_type),
|
||||||
CfgParam('VERBOSE', False, bool),
|
CfgParam('VERBOSE', False, bool),
|
||||||
CfgParam('LIBVIRT_METER_ENABLED', False, bool),
|
CfgParam('LIBVIRT_METER_ENABLED', False, bool),
|
||||||
|
# Gnocchi only
|
||||||
|
CfgParam('DEFAULT_ARCHIVE_POLICY', None, six.text_type),
|
||||||
|
|
||||||
CfgParam('LIBVIRT_CONN_URI', 'qemu:///system', six.text_type),
|
CfgParam('LIBVIRT_CONN_URI', 'qemu:///system', six.text_type),
|
||||||
]
|
]
|
||||||
|
@ -30,13 +30,14 @@ ROOT_LOGGER = logging.getLogger(collectd_ceilometer.__name__)
|
|||||||
class Sender(common_sender.Sender):
|
class Sender(common_sender.Sender):
|
||||||
"""Sends the JSON serialized data to Gnocchi"""
|
"""Sends the JSON serialized data to Gnocchi"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, config):
|
||||||
"""Create the Sender instance
|
"""Create the Sender instance
|
||||||
|
|
||||||
The cofinguration must be initialized before the object is created.
|
The cofinguration must be initialized before the object is created.
|
||||||
"""
|
"""
|
||||||
super(Sender, self).__init__()
|
super(Sender, self).__init__()
|
||||||
self._meter_ids = {}
|
self._meter_ids = {}
|
||||||
|
self._config = config
|
||||||
|
|
||||||
def _on_authenticated(self):
|
def _on_authenticated(self):
|
||||||
# get the uri of service endpoint
|
# get the uri of service endpoint
|
||||||
@ -100,9 +101,13 @@ class Sender(common_sender.Sender):
|
|||||||
|
|
||||||
def _create_metric(self, metername, endpoint, unit):
|
def _create_metric(self, metername, endpoint, unit):
|
||||||
url = "{}/v1/metric/".format(endpoint)
|
url = "{}/v1/metric/".format(endpoint)
|
||||||
payload = json.dumps({"name": metername,
|
data = {"name": metername,
|
||||||
"unit": unit,
|
"unit": unit,
|
||||||
})
|
}
|
||||||
|
if self._config.DEFAULT_ARCHIVE_POLICY:
|
||||||
|
data["archive_policy_name"] = self._config.DEFAULT_ARCHIVE_POLICY
|
||||||
|
|
||||||
|
payload = json.dumps(data)
|
||||||
result = self._perform_request(url, payload, self._auth_token)
|
result = self._perform_request(url, payload, self._auth_token)
|
||||||
metric_id = json.loads(result.text)['id']
|
metric_id = json.loads(result.text)['id']
|
||||||
LOGGER.debug("metric_id=%s", metric_id)
|
LOGGER.debug("metric_id=%s", metric_id)
|
||||||
|
@ -44,7 +44,7 @@ class Writer(object):
|
|||||||
def __init__(self, meters, config):
|
def __init__(self, meters, config):
|
||||||
self._meters = meters
|
self._meters = meters
|
||||||
self._samples = SampleContainer()
|
self._samples = SampleContainer()
|
||||||
self._sender = gnocchi_sender.Sender()
|
self._sender = gnocchi_sender.Sender(config)
|
||||||
self._config = config
|
self._config = config
|
||||||
|
|
||||||
def write(self, vl, data):
|
def write(self, vl, data):
|
||||||
|
@ -165,7 +165,8 @@ class TestPlugin(unittest.TestCase):
|
|||||||
CEILOMETER_TIMEOUT=1000,
|
CEILOMETER_TIMEOUT=1000,
|
||||||
OS_USERNAME='tester',
|
OS_USERNAME='tester',
|
||||||
OS_PASSWORD='testpasswd',
|
OS_PASSWORD='testpasswd',
|
||||||
OS_TENANT_NAME='service')
|
OS_TENANT_NAME='service',
|
||||||
|
DEFAULT_ARCHIVE_POLICY='')
|
||||||
|
|
||||||
@mock.patch.object(plugin, 'Plugin', autospec=True)
|
@mock.patch.object(plugin, 'Plugin', autospec=True)
|
||||||
@mock.patch.object(plugin, 'Config', autospec=True)
|
@mock.patch.object(plugin, 'Config', autospec=True)
|
||||||
|
@ -87,6 +87,7 @@ class TestConfig(TestCase):
|
|||||||
OS_USERNAME='tester',
|
OS_USERNAME='tester',
|
||||||
OS_PASSWORD='testpasswd',
|
OS_PASSWORD='testpasswd',
|
||||||
OS_TENANT_NAME='service',
|
OS_TENANT_NAME='service',
|
||||||
|
DEFAULT_ARCHIVE_POLICY='',
|
||||||
LIBVIRT_METER_ENABLED=False)
|
LIBVIRT_METER_ENABLED=False)
|
||||||
|
|
||||||
@mock.patch.object(settings, 'LOGGER', autospec=True)
|
@mock.patch.object(settings, 'LOGGER', autospec=True)
|
||||||
|
@ -253,7 +253,7 @@ class TestPlugin(unittest.TestCase):
|
|||||||
@mock.patch.object(common_sender.Sender, '_perform_request', spec=callable)
|
@mock.patch.object(common_sender.Sender, '_perform_request', spec=callable)
|
||||||
@mock.patch.object(common_sender, 'ClientV3', autospec=True)
|
@mock.patch.object(common_sender, 'ClientV3', autospec=True)
|
||||||
@mock_collectd()
|
@mock_collectd()
|
||||||
@mock_config()
|
@mock_config(DEFAULT_ARCHIVE_POLICY='')
|
||||||
@mock_value()
|
@mock_value()
|
||||||
def test_request_error(
|
def test_request_error(
|
||||||
self, data, config, collectd, ClientV3, perf_req):
|
self, data, config, collectd, ClientV3, perf_req):
|
||||||
|
Loading…
Reference in New Issue
Block a user