Browse Source

Merge "Don't throw exception when missing metrics" into stable/train

tags/3.0.1^0
Zuul 8 months ago
committed by Gerrit Code Review
parent
commit
e37bbf3be3
7 changed files with 27 additions and 33 deletions
  1. +0
    -3
      watcher/decision_engine/datasources/base.py
  2. +6
    -7
      watcher/decision_engine/datasources/ceilometer.py
  3. +11
    -10
      watcher/decision_engine/datasources/gnocchi.py
  4. +3
    -0
      watcher/decision_engine/datasources/grafana.py
  5. +4
    -4
      watcher/decision_engine/datasources/monasca.py
  6. +2
    -4
      watcher/tests/decision_engine/datasources/test_base.py
  7. +1
    -5
      watcher/tests/decision_engine/datasources/test_grafana_helper.py

+ 0
- 3
watcher/decision_engine/datasources/base.py View File

@@ -19,8 +19,6 @@ import time
from oslo_config import cfg
from oslo_log import log

from watcher.common import exception

CONF = cfg.CONF
LOG = log.getLogger(__name__)

@@ -79,7 +77,6 @@ class DataSourceBase(object):
LOG.warning("Retry {0} of {1} while retrieving metrics retry "
"in {2} seconds".format(i+1, num_retries, timeout))
time.sleep(timeout)
raise exception.DataSourceNotAvailable(datasource=self.NAME)

@abc.abstractmethod
def query_retry_reset(self, exception_instance):


+ 6
- 7
watcher/decision_engine/datasources/ceilometer.py View File

@@ -136,19 +136,18 @@ class CeilometerHelper(base.DataSourceBase):

def list_metrics(self):
"""List the user's meters."""
try:
meters = self.query_retry(f=self.ceilometer.meters.list)
except Exception:
meters = self.query_retry(f=self.ceilometer.meters.list)
if not meters:
return set()
else:
return meters

def check_availability(self):
try:
self.query_retry(self.ceilometer.resources.list)
except Exception:
status = self.query_retry(self.ceilometer.resources.list)
if status:
return 'available'
else:
return 'not available'
return 'available'

def query_sample(self, meter_name, query, limit=1):
return self.query_retry(f=self.ceilometer.samples.list,


+ 11
- 10
watcher/decision_engine/datasources/gnocchi.py View File

@@ -52,17 +52,16 @@ class GnocchiHelper(base.DataSourceBase):
self.gnocchi = self.osc.gnocchi()

def check_availability(self):
try:
self.query_retry(self.gnocchi.status.get)
except Exception:
status = self.query_retry(self.gnocchi.status.get)
if status:
return 'available'
else:
return 'not available'
return 'available'

def list_metrics(self):
"""List the user's meters."""
try:
response = self.query_retry(f=self.gnocchi.metric.list)
except Exception:
response = self.query_retry(f=self.gnocchi.metric.list)
if not response:
return set()
else:
return set([metric['name'] for metric in response])
@@ -91,8 +90,9 @@ class GnocchiHelper(base.DataSourceBase):
f=self.gnocchi.resource.search, **kwargs)

if not resources:
raise exception.ResourceNotFound(name='gnocchi',
id=resource_id)
LOG.warning("The {0} resource {1} could not be "
"found".format(self.NAME, resource_id))
return

resource_id = resources[0]['id']

@@ -110,6 +110,7 @@ class GnocchiHelper(base.DataSourceBase):
statistics = self.query_retry(
f=self.gnocchi.metric.get_measures, **kwargs)

return_value = None
if statistics:
# return value of latest measure
# measure has structure [time, granularity, value]
@@ -120,7 +121,7 @@ class GnocchiHelper(base.DataSourceBase):
# 1/10 th of actual CFM
return_value *= 10

return return_value
return return_value

def get_host_cpu_usage(self, resource, period, aggregate,
granularity=300):


+ 3
- 0
watcher/decision_engine/datasources/grafana.py View File

@@ -179,6 +179,9 @@ class GrafanaHelper(base.DataSourceBase):
kwargs = {k: v for k, v in raw_kwargs.items() if k and v}

resp = self.query_retry(self._request, **kwargs)
if not resp:
LOG.warning("Datasource {0} is not available.".format(self.NAME))
return

result = translator.extract_result(resp.content)



+ 4
- 4
watcher/decision_engine/datasources/monasca.py View File

@@ -73,11 +73,11 @@ class MonascaHelper(base.DataSourceBase):
self.monasca = self.osc.monasca()

def check_availability(self):
try:
self.query_retry(self.monasca.metrics.list)
except Exception:
result = self.query_retry(self.monasca.metrics.list)
if result:
return 'available'
else:
return 'not available'
return 'available'

def list_metrics(self):
# TODO(alexchadin): this method should be implemented in accordance to


+ 2
- 4
watcher/tests/decision_engine/datasources/test_base.py View File

@@ -19,7 +19,6 @@
import mock
from oslo_config import cfg

from watcher.common import exception
from watcher.decision_engine.datasources import base as datasource
from watcher.tests import base

@@ -61,9 +60,8 @@ class TestBaseDatasourceHelper(base.BaseTestCase):
helper = datasource.DataSourceBase()
helper.query_retry_reset = mock.Mock()

# Maximum number of retries exceeded query_retry should raise error
self.assertRaises(exception.DataSourceNotAvailable,
helper.query_retry, f=method)
# Maximum number of retries exceeded query_retry should return None
self.assertIsNone(helper.query_retry(f=method))
# query_retry_reset should be called twice
helper.query_retry_reset.assert_has_calls(
[mock.call(exc), mock.call(exc)])

+ 1
- 5
watcher/tests/decision_engine/datasources/test_grafana_helper.py View File

@@ -132,11 +132,7 @@ class TestGrafana(base.BaseTestCase):

t_grafana = grafana.GrafanaHelper(osc=mock.Mock())

self.assertRaises(
exception.DataSourceNotAvailable,
t_grafana.get_host_cpu_usage,
self.m_compute_node
)
self.assertIsNone(t_grafana.get_host_cpu_usage(self.m_compute_node))

def test_no_metric_raise_error(self):
"""Test raising error when specified meter does not exist"""


Loading…
Cancel
Save