Skip to content

Commit

Permalink
Skip a cycle instead of retrying if a metric is not found in gnocchi
Browse files Browse the repository at this point in the history
In case a metric is not found in gnocchi, return nothing instead of retrying.
The metric is unlikely to be available during the next collection cycle.

Change-Id: I4b954b146b800255554449bb19eb4bed3cb87dd4
  • Loading branch information
lukapeschke committed Mar 21, 2019
1 parent 5c69644 commit 6404ec1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
27 changes: 20 additions & 7 deletions cloudkitty/collector/gnocchi.py
Expand Up @@ -13,8 +13,11 @@
# License for the specific language governing permissions and limitations
# under the License.
#
import six

from gnocchiclient import auth as gauth
from gnocchiclient import client as gclient
from gnocchiclient import exceptions as gexceptions
from keystoneauth1 import loading as ks_loading
from oslo_config import cfg
from oslo_log import log as logging
Expand Down Expand Up @@ -309,13 +312,23 @@ def _fetch_metric(self, metric_name, start, end,
# get groupby
groupby = self.conf[metric_name]['groupby']

return self._conn.aggregates.fetch(
op,
resource_type=resource_type,
start=ck_utils.ts2dt(start),
stop=ck_utils.ts2dt(end),
groupby=groupby,
search=self.extend_filter(*query_parameters))
try:
return self._conn.aggregates.fetch(
op,
resource_type=resource_type,
start=ck_utils.ts2dt(start),
stop=ck_utils.ts2dt(end),
groupby=groupby,
search=self.extend_filter(*query_parameters))
except (gexceptions.MetricNotFound, gexceptions.BadRequest) as e:
# FIXME(peschk_l): gnocchiclient seems to be raising a BadRequest
# when it should be raising MetricNotFound
if isinstance(e, gexceptions.BadRequest):
if 'Metrics not found' not in six.text_type(e):
raise
LOG.warning('[{scope}] Skipping this metric for the '
'current cycle.'.format(scope=project_id, err=e))
return []

def _format_data(self, metconf, data, resources_info=None):
"""Formats gnocchi data to CK data.
Expand Down
2 changes: 1 addition & 1 deletion releasenotes/notes/add-scope-key-58135c2a5c6dae68.yaml
@@ -1,5 +1,5 @@
---
other:
- |
The "scope_key" option is now defained in cloudkitty.conf and has been
The "scope_key" option is now defined in cloudkitty.conf and has been
removed from the cloudkitty and monasca collector's extra_args
@@ -0,0 +1,6 @@
---
fixes:
- |
The behaviour of the gnocchi collector has changed in case of a nonexistent
metric. Given that a nonexistent metric is unlikely to exist in the next
collection cycle, the metric is simply skipped.

0 comments on commit 6404ec1

Please sign in to comment.