Gnocchi: don't fail to create valid alarm
When the Gnocchi resource or metric doesn't exists yet, we refuse to create the alarm and return a confusing 404. This change returns 200, in such case and removes the need to have the Gnocchi resource and metric existing, we just trust that the id/name provided by the use will exists. Depends-On: I810897e750c4b5a42bb3ada2f8a2488dbee609f4 Change-Id: I404daf0c30d4b3ced239a94b98d8a62bad71a6b6
This commit is contained in:
parent
55e63d4e2a
commit
5be04f1bf1
@ -99,26 +99,6 @@ class MetricOfResourceRule(AlarmGnocchiThresholdRule):
|
|||||||
'resource_type'])
|
'resource_type'])
|
||||||
return rule
|
return rule
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def validate_alarm(cls, alarm):
|
|
||||||
super(MetricOfResourceRule,
|
|
||||||
cls).validate_alarm(alarm)
|
|
||||||
|
|
||||||
conf = pecan.request.cfg
|
|
||||||
gnocchi_client = client.Client(
|
|
||||||
'1', keystone_client.get_session(conf),
|
|
||||||
interface=conf.service_credentials.interface,
|
|
||||||
region_name=conf.service_credentials.region_name)
|
|
||||||
|
|
||||||
rule = alarm.gnocchi_resources_threshold_rule
|
|
||||||
try:
|
|
||||||
gnocchi_client.resource.get(rule.resource_type,
|
|
||||||
rule.resource_id)
|
|
||||||
except exceptions.ClientException as e:
|
|
||||||
raise base.ClientSideError(e.message, status_code=e.code)
|
|
||||||
except Exception as e:
|
|
||||||
raise GnocchiUnavailable(e)
|
|
||||||
|
|
||||||
|
|
||||||
class AggregationMetricByResourcesLookupRule(AlarmGnocchiThresholdRule):
|
class AggregationMetricByResourcesLookupRule(AlarmGnocchiThresholdRule):
|
||||||
metric = wsme.wsattr(wtypes.text, mandatory=True)
|
metric = wsme.wsattr(wtypes.text, mandatory=True)
|
||||||
@ -176,6 +156,11 @@ class AggregationMetricByResourcesLookupRule(AlarmGnocchiThresholdRule):
|
|||||||
needed_overlap=0,
|
needed_overlap=0,
|
||||||
resource_type=rule.resource_type)
|
resource_type=rule.resource_type)
|
||||||
except exceptions.ClientException as e:
|
except exceptions.ClientException as e:
|
||||||
|
if e.code == 404:
|
||||||
|
# NOTE(sileht): We are fine here, we just want to ensure the
|
||||||
|
# 'query' payload is valid for Gnocchi If the metric
|
||||||
|
# doesn't exists yet, it doesn't matter
|
||||||
|
return
|
||||||
raise base.ClientSideError(e.message, status_code=e.code)
|
raise base.ClientSideError(e.message, status_code=e.code)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise GnocchiUnavailable(e)
|
raise GnocchiUnavailable(e)
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from gnocchiclient import client
|
from gnocchiclient import client
|
||||||
|
from gnocchiclient import exceptions
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
|
|
||||||
@ -61,9 +62,12 @@ class GnocchiResourceThresholdEvaluator(GnocchiBase):
|
|||||||
start=start, stop=end,
|
start=start, stop=end,
|
||||||
resource_id=rule['resource_id'],
|
resource_id=rule['resource_id'],
|
||||||
aggregation=rule['aggregation_method'])
|
aggregation=rule['aggregation_method'])
|
||||||
|
except exceptions.NotFound:
|
||||||
|
LOG.debug('metric %s or resource %s does not exists',
|
||||||
|
rule['metric'], rule['resource_id'])
|
||||||
|
return []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.warning(_LW('alarm stats retrieval failed: %s'),
|
LOG.warning(_LW('alarm stats retrieval failed: %s'), e)
|
||||||
e)
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
@ -83,6 +87,9 @@ class GnocchiAggregationMetricsThresholdEvaluator(GnocchiBase):
|
|||||||
start=start, stop=end,
|
start=start, stop=end,
|
||||||
aggregation=rule['aggregation_method'],
|
aggregation=rule['aggregation_method'],
|
||||||
needed_overlap=0)
|
needed_overlap=0)
|
||||||
|
except exceptions.NotFound:
|
||||||
|
LOG.debug('metrics %s does not exists', rule['metrics'])
|
||||||
|
return []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.warning(_LW('alarm stats retrieval failed: %s'), e)
|
LOG.warning(_LW('alarm stats retrieval failed: %s'), e)
|
||||||
return []
|
return []
|
||||||
@ -107,6 +114,9 @@ class GnocchiAggregationResourcesThresholdEvaluator(GnocchiBase):
|
|||||||
aggregation=rule['aggregation_method'],
|
aggregation=rule['aggregation_method'],
|
||||||
needed_overlap=0,
|
needed_overlap=0,
|
||||||
)
|
)
|
||||||
|
except exceptions.NotFound:
|
||||||
|
LOG.debug('metric %s does not exists', rule['metric'])
|
||||||
|
return []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.warning(_LW('alarm stats retrieval failed: %s'), e)
|
LOG.warning(_LW('alarm stats retrieval failed: %s'), e)
|
||||||
return []
|
return []
|
||||||
|
@ -2569,9 +2569,6 @@ class TestAlarmsRuleGnocchi(TestAlarmsBase):
|
|||||||
c.capabilities.list.return_value = {
|
c.capabilities.list.return_value = {
|
||||||
'aggregation_methods': ['count']}
|
'aggregation_methods': ['count']}
|
||||||
self.post_json('/alarms', params=json, headers=self.auth_headers)
|
self.post_json('/alarms', params=json, headers=self.auth_headers)
|
||||||
expected = mock.call.resource.get(
|
|
||||||
"instance", "209ef69c-c10c-4efb-90ff-46f4b2d90d2e")
|
|
||||||
self.assertIn(expected, c.mock_calls)
|
|
||||||
|
|
||||||
alarms = list(self.alarm_conn.get_alarms(enabled=False))
|
alarms = list(self.alarm_conn.get_alarms(enabled=False))
|
||||||
self.assertEqual(1, len(alarms))
|
self.assertEqual(1, len(alarms))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user