api: deprecate and disable combination alarms

The combination alarms are officially deprecated and disabled by
default. Set api.enable_combination_alarms to True to enable them.
Existing alarms will still be evaluated, but access to them via the API
is linked to whether that configuration option is turned on or off.

Change-Id: Ic972473d7a19591e74f93afb5c826e3e56e12746
This commit is contained in:
Julien Danjou 2016-05-18 11:45:28 +02:00
parent 3f3697ec5a
commit 20abf3b1fb
4 changed files with 94 additions and 20 deletions

View File

@ -34,4 +34,11 @@ OPTS = [
cfg.BoolOpt('pecan_debug',
default=False,
help='Toggle Pecan Debug Middleware.'),
cfg.BoolOpt('enable_combination_alarms',
default=False,
help="Enable deprecated combination alarms.",
deprecated_for_removal=True,
deprecated_reason="Combination alarms are deprecated. "
"This option and combination alarms will be "
"removed in Aodh 5.0."),
]

View File

@ -289,6 +289,10 @@ class Alarm(base.Base):
@staticmethod
def check_rule(alarm):
if (not pecan.request.cfg.api.enable_combination_alarms
and alarm.type == 'combination'):
raise base.ClientSideError("Unavailable alarm type")
rule = '%s_rule' % alarm.type
if getattr(alarm, rule) in (wtypes.Unset, None):
error = _("%(rule)s must be set for %(type)s"

View File

@ -1184,7 +1184,7 @@ class TestAlarms(TestAlarmsBase):
'enabled': False,
'name': 'added_alarm',
'state': 'ok',
'type': 'combination',
'type': 'gnocchi_resources_threshold',
'ok_actions': ['http://something/ok'],
'alarm_actions': ['http://something/alarm'],
'insufficient_data_actions': ['http://something/no'],
@ -1206,15 +1206,25 @@ class TestAlarms(TestAlarmsBase):
expect_errors=True, status=400,
headers=self.auth_headers)
self.assertEqual(
"combination_rule must be set for combination type alarm",
"gnocchi_resources_threshold_rule must "
"be set for gnocchi_resources_threshold type alarm",
resp.json['error_message']['faultstring'])
def test_post_alarm_with_duplicate_actions(self):
body = {
'name': 'dup-alarm-actions',
'type': 'combination',
'combination_rule': {
'alarm_ids': ['a', 'b'],
'type': 'threshold',
'threshold_rule': {
'meter_name': 'ameter',
'query': [{'field': 'metadata.field',
'op': 'eq',
'value': '5',
'type': 'string'}],
'comparison_operator': 'le',
'statistic': 'count',
'threshold': 50,
'evaluation_periods': '3',
'period': '180',
},
'alarm_actions': ['http://no.where', 'http://no.where']
}
@ -1229,9 +1239,18 @@ class TestAlarms(TestAlarmsBase):
self.CONF.set_override('alarm_max_actions', 1, group='api')
body = {
'name': 'alarm-with-many-actions',
'type': 'combination',
'combination_rule': {
'alarm_ids': ['a', 'b'],
'type': 'threshold',
'threshold_rule': {
'meter_name': 'ameter',
'query': [{'field': 'metadata.field',
'op': 'eq',
'value': '5',
'type': 'string'}],
'comparison_operator': 'le',
'statistic': 'count',
'threshold': 50,
'evaluation_periods': '3',
'period': '180',
},
'alarm_actions': ['http://no.where', 'http://no.where2']
}
@ -1244,9 +1263,18 @@ class TestAlarms(TestAlarmsBase):
def test_post_alarm_normal_user_set_log_actions(self):
body = {
'name': 'log_alarm_actions',
'type': 'combination',
'combination_rule': {
'alarm_ids': ['a', 'b'],
'type': 'threshold',
'threshold_rule': {
'meter_name': 'ameter',
'query': [{'field': 'metadata.field',
'op': 'eq',
'value': '5',
'type': 'string'}],
'comparison_operator': 'le',
'statistic': 'count',
'threshold': 50,
'evaluation_periods': '3',
'period': '180',
},
'alarm_actions': ['log://']
}
@ -1260,9 +1288,18 @@ class TestAlarms(TestAlarmsBase):
def test_post_alarm_normal_user_set_test_actions(self):
body = {
'name': 'test_alarm_actions',
'type': 'combination',
'combination_rule': {
'alarm_ids': ['a', 'b'],
'type': 'threshold',
'threshold_rule': {
'meter_name': 'ameter',
'query': [{'field': 'metadata.field',
'op': 'eq',
'value': '5',
'type': 'string'}],
'comparison_operator': 'le',
'statistic': 'count',
'threshold': 50,
'evaluation_periods': '3',
'period': '180',
},
'alarm_actions': ['test://']
}
@ -1276,9 +1313,18 @@ class TestAlarms(TestAlarmsBase):
def test_post_alarm_admin_user_set_log_test_actions(self):
body = {
'name': 'admin_alarm_actions',
'type': 'combination',
'combination_rule': {
'alarm_ids': ['a', 'b'],
'type': 'threshold',
'threshold_rule': {
'meter_name': 'ameter',
'query': [{'field': 'metadata.field',
'op': 'eq',
'value': '5',
'type': 'string'}],
'comparison_operator': 'le',
'statistic': 'count',
'threshold': 50,
'evaluation_periods': '3',
'period': '180',
},
'alarm_actions': ['test://', 'log://']
}
@ -1294,9 +1340,18 @@ class TestAlarms(TestAlarmsBase):
def test_post_alarm_without_actions(self):
body = {
'name': 'alarm_actions_none',
'type': 'combination',
'combination_rule': {
'alarm_ids': ['a', 'b'],
'type': 'threshold',
'threshold_rule': {
'meter_name': 'ameter',
'query': [{'field': 'metadata.field',
'op': 'eq',
'value': '5',
'type': 'string'}],
'comparison_operator': 'le',
'statistic': 'count',
'threshold': 50,
'evaluation_periods': '3',
'period': '180',
},
'alarm_actions': None
}
@ -2388,6 +2443,7 @@ class TestAlarmsRuleCombination(TestAlarmsBase):
def setUp(self):
super(TestAlarmsRuleCombination, self).setUp()
self.CONF.set_override("enable_combination_alarms", True, "api")
for alarm in default_alarms(self.auth_headers):
self.alarm_conn.create_alarm(alarm)

View File

@ -0,0 +1,7 @@
---
deprecations:
- The combination alarms are officially deprecated and disabled by default.
Set api.enable_combination_alarms to True to enable them.
Existing alarms will still be evaluated, but access to them via the API is
linked to whether that configuration option is turned on or off.
It's advised to use composite alarms instead.