Skip to content

Commit

Permalink
Don't use gnocchiclient during publisher init
Browse files Browse the repository at this point in the history
We can't create archive policies in publisher init because if it fail
because Gnocchi is not yet ready the publisher fail to load. Ceilometer
will work, but samples will go to nowhere.

This change creates/checks archive policies when we publish a sample for
the very first time. If that fail because Gnocchi is not ready, this
will just retry next time Ceilometer will publish samples.

Closes-Bug: #1752420

Change-Id: Ib6b4da54592ad99a4e6561a73473b6c7ec73a21f
  • Loading branch information
Mehdi Abaakouk authored and dchavoll committed Aug 15, 2018
1 parent bb4692d commit 717e968
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
16 changes: 10 additions & 6 deletions ceilometer/publisher/gnocchi.py
Expand Up @@ -246,7 +246,7 @@ def __init__(self, conf, parsed_url):
self._already_logged_event_types = set()
self._already_logged_metric_names = set()

self.ensures_archives_policies()
self._already_configured_archive_policies = False

@staticmethod
def _load_definitions(conf, archive_policy_override,
Expand All @@ -273,11 +273,13 @@ def _load_definitions(conf, archive_policy_override,
return resource_defs, data.get("archive_policies", [])

def ensures_archives_policies(self):
for ap in self.archive_policies_definition:
try:
self._gnocchi.archive_policy.get(ap["name"])
except gnocchi_exc.ArchivePolicyNotFound:
self._gnocchi.archive_policy.create(ap)
if not self._already_configured_archive_policies:
for ap in self.archive_policies_definition:
try:
self._gnocchi.archive_policy.get(ap["name"])
except gnocchi_exc.ArchivePolicyNotFound:
self._gnocchi.archive_policy.create(ap)
self._already_configured_archive_policies = True

@property
def gnocchi_project_id(self):
Expand Down Expand Up @@ -325,6 +327,8 @@ def _get_resource_definition_from_event(self, event_type):
return rd, operation

def publish_samples(self, data):
self.ensures_archives_policies()

# NOTE(sileht): skip sample generated by gnocchi itself
data = [s for s in data if not self._is_gnocchi_activity(s)]
data.sort(key=operator.attrgetter('resource_id'))
Expand Down
4 changes: 1 addition & 3 deletions ceilometer/tests/unit/publisher/test_gnocchi.py
Expand Up @@ -649,8 +649,6 @@ def test_event_workflow(self, fakeclient_cls):
self.useFixture(utils_fixture.TimeFixture(now))

expected_calls = [
mock.call.archive_policy.get("ceilometer-low"),
mock.call.archive_policy.get("ceilometer-low-rate"),
mock.call.resource.search('instance_network_interface',
search_params),
mock.call.resource.search('instance_disk', search_params),
Expand Down Expand Up @@ -680,7 +678,7 @@ def test_event_workflow(self, fakeclient_cls):
IMAGE_DELETE_START,
VOLUME_DELETE_START,
FLOATINGIP_DELETE_END])
self.assertEqual(10, len(fakeclient.mock_calls))
self.assertEqual(8, len(fakeclient.mock_calls))
for call in expected_calls:
self.assertIn(call, fakeclient.mock_calls)

Expand Down

0 comments on commit 717e968

Please sign in to comment.