From 6404ec1569ab9cd71a01738390157fc5d7ab1796 Mon Sep 17 00:00:00 2001 From: Luka Peschke Date: Thu, 21 Mar 2019 12:19:51 +0100 Subject: [PATCH] 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 --- cloudkitty/collector/gnocchi.py | 27 ++++++++++++++----- .../notes/add-scope-key-58135c2a5c6dae68.yaml | 2 +- ...f-nonexistent-metric-ba56a671e68f5bf5.yaml | 6 +++++ 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 releasenotes/notes/skip-period-if-nonexistent-metric-ba56a671e68f5bf5.yaml diff --git a/cloudkitty/collector/gnocchi.py b/cloudkitty/collector/gnocchi.py index ceedaa7d..38751817 100644 --- a/cloudkitty/collector/gnocchi.py +++ b/cloudkitty/collector/gnocchi.py @@ -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 @@ -309,13 +312,23 @@ class GnocchiCollector(collector.BaseCollector): # 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. diff --git a/releasenotes/notes/add-scope-key-58135c2a5c6dae68.yaml b/releasenotes/notes/add-scope-key-58135c2a5c6dae68.yaml index 0f9185a4..e0a8aa55 100644 --- a/releasenotes/notes/add-scope-key-58135c2a5c6dae68.yaml +++ b/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 diff --git a/releasenotes/notes/skip-period-if-nonexistent-metric-ba56a671e68f5bf5.yaml b/releasenotes/notes/skip-period-if-nonexistent-metric-ba56a671e68f5bf5.yaml new file mode 100644 index 00000000..a984238d --- /dev/null +++ b/releasenotes/notes/skip-period-if-nonexistent-metric-ba56a671e68f5bf5.yaml @@ -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.