Skip a cycle instead of retrying if a metric is not found in gnocchi

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
This commit is contained in:
Luka Peschke 2019-03-21 12:19:51 +01:00
parent 5c6964469b
commit 6404ec1569
3 changed files with 27 additions and 8 deletions

View File

@ -13,8 +13,11 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
import six
from gnocchiclient import auth as gauth from gnocchiclient import auth as gauth
from gnocchiclient import client as gclient from gnocchiclient import client as gclient
from gnocchiclient import exceptions as gexceptions
from keystoneauth1 import loading as ks_loading from keystoneauth1 import loading as ks_loading
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
@ -309,6 +312,7 @@ class GnocchiCollector(collector.BaseCollector):
# get groupby # get groupby
groupby = self.conf[metric_name]['groupby'] groupby = self.conf[metric_name]['groupby']
try:
return self._conn.aggregates.fetch( return self._conn.aggregates.fetch(
op, op,
resource_type=resource_type, resource_type=resource_type,
@ -316,6 +320,15 @@ class GnocchiCollector(collector.BaseCollector):
stop=ck_utils.ts2dt(end), stop=ck_utils.ts2dt(end),
groupby=groupby, groupby=groupby,
search=self.extend_filter(*query_parameters)) 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): def _format_data(self, metconf, data, resources_info=None):
"""Formats gnocchi data to CK data. """Formats gnocchi data to CK data.

View File

@ -1,5 +1,5 @@
--- ---
other: 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 removed from the cloudkitty and monasca collector's extra_args

View File

@ -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.