Adds tags for inhibit and silence
The new silence and inhibit rules will include tags on the alarm that can be queried via the api. For more information and documentation see: https://review.openstack.org/#/c/466403 Change-Id: I85b8bfc9338ee17709ec30aeb4b807b3bc12404e
This commit is contained in:
parent
91941d8b44
commit
8781a256f0
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* (C) Copyright 2015,2016 Hewlett Packard Enterprise Development LP
|
||||
* (C) Copyright 2015-2017 Hewlett Packard Enterprise Development LP
|
||||
* Copyright 2017 FUJITSU LIMITED
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -43,6 +43,8 @@ CREATE TABLE `alarm` (
|
||||
`state` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
|
||||
`lifecycle_state` varchar(50) DEFAULT NULL,
|
||||
`link` varchar(512) DEFAULT NULL,
|
||||
`inhibited` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`silenced` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`created_at` datetime NOT NULL,
|
||||
`state_updated_at` datetime,
|
||||
`updated_at` datetime NOT NULL,
|
||||
|
@ -1,5 +1,6 @@
|
||||
---
|
||||
-- # Copyright 2017 FUJITSU LIMITED
|
||||
-- # (C) Copyright 2017 Hewlett Packard Enterprise Development LP
|
||||
---
|
||||
|
||||
SET statement_timeout = 0;
|
||||
@ -38,6 +39,8 @@ CREATE TABLE alarm (
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
lifecycle_state character varying(50),
|
||||
link character varying(512),
|
||||
inhibited boolean NOT NULL DEFAULT FALSE,
|
||||
silenced boolean NOT NULL DEFAULT FALSE,
|
||||
state character varying(20) NOT NULL,
|
||||
state_updated_at timestamp without time zone,
|
||||
alarm_definition_id character varying(36) NOT NULL
|
||||
|
@ -72,6 +72,8 @@ class AlarmsRepository(sql_repository.SQLRepository,
|
||||
a_s.c.created_at.label('created_timestamp'),
|
||||
a_s.c.lifecycle_state,
|
||||
a_s.c.link,
|
||||
a_s.c.inhibited,
|
||||
a_s.c.silenced,
|
||||
ad.c.id.label('alarm_definition_id'),
|
||||
ad.c.name.label('alarm_definition_name'),
|
||||
ad.c.severity,
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Copyright 2015 Robin Hood
|
||||
# Copyright 2016 FUJITSU LIMITED
|
||||
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
|
||||
# (C) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -33,6 +33,8 @@ def create_a_model(metadata=None):
|
||||
Column('state', String(20)),
|
||||
Column('lifecycle_state', String(50)),
|
||||
Column('link', String(512)),
|
||||
Column('inhibited', Boolean),
|
||||
Column('silenced', Boolean),
|
||||
Column('created_at', DateTime),
|
||||
Column('state_updated_at', DateTime),
|
||||
Column('updated_at', DateTime))
|
||||
|
@ -44,6 +44,8 @@ CREATE TABLE `alarm` (
|
||||
`state` varchar(20) NOT NULL,
|
||||
`lifecycle_state` varchar(50) DEFAULT NULL,
|
||||
`link` varchar(512) DEFAULT NULL,
|
||||
`inhibited` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`silenced` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`created_at` datetime NOT NULL,
|
||||
`state_updated_at` datetime,
|
||||
`updated_at` datetime NOT NULL,
|
||||
|
@ -439,6 +439,8 @@ class TestAlarmRepoDB(base.BaseTestCase):
|
||||
'id': '1',
|
||||
'lifecycle_state': 'OPEN',
|
||||
'link': 'http://somesite.com/this-alarm-info',
|
||||
'inhibited': False,
|
||||
'silenced': False,
|
||||
'metrics': [{'dimensions': {'instance_id': '123',
|
||||
'service': 'monitoring'},
|
||||
'name': 'cpu.idle_perc'},
|
||||
@ -454,6 +456,8 @@ class TestAlarmRepoDB(base.BaseTestCase):
|
||||
'id': '2',
|
||||
'lifecycle_state': 'OPEN',
|
||||
'link': 'http://somesite.com/this-alarm-info',
|
||||
'inhibited': False,
|
||||
'silenced': False,
|
||||
'metrics': [{'dimensions': {'instance_id': '123',
|
||||
'service': 'monitoring'},
|
||||
'name': 'cpu.idle_perc'}],
|
||||
@ -467,6 +471,8 @@ class TestAlarmRepoDB(base.BaseTestCase):
|
||||
'id': '234111',
|
||||
'lifecycle_state': None,
|
||||
'link': None,
|
||||
'inhibited': False,
|
||||
'silenced': False,
|
||||
'metrics': [
|
||||
{'dimensions': {'hostname': 'roland',
|
||||
'region': 'colorado',
|
||||
@ -488,6 +494,8 @@ class TestAlarmRepoDB(base.BaseTestCase):
|
||||
'id': '3',
|
||||
'lifecycle_state': None,
|
||||
'link': 'http://somesite.com/this-alarm-info',
|
||||
'inhibited': False,
|
||||
'silenced': False,
|
||||
'metrics': [{'dimensions': {'flavor_id': '222'},
|
||||
'name': 'cpu.idle_perc'}],
|
||||
'state': 'ALARM',
|
||||
@ -541,6 +549,8 @@ class TestAlarmRepoDB(base.BaseTestCase):
|
||||
u'state': alarm_row['state'],
|
||||
u'lifecycle_state': alarm_row['lifecycle_state'],
|
||||
u'link': alarm_row['link'],
|
||||
u'inhibited': alarm_row['inhibited'],
|
||||
u'silenced': alarm_row['silenced'],
|
||||
u'state_updated_timestamp':
|
||||
alarm_row['state_updated_timestamp'].isoformat() +
|
||||
'Z',
|
||||
@ -871,3 +881,27 @@ class TestAlarmRepoDB(base.BaseTestCase):
|
||||
'expression': 'avg(cpu.idle_perc{flavor_id=777, image_id=888, device=1}) > 10',
|
||||
'sub_alarm_id': '43'}]
|
||||
self.assertEqual(sub_alarms, expected)
|
||||
|
||||
def test_silence_inhibit_tag_true(self):
|
||||
silence_query = "UPDATE alarm SET silenced=1 WHERE id=1"
|
||||
inhibit_query = "UPDATE alarm SET inhibited=1 WHERE id=1"
|
||||
with self.engine.begin() as conn:
|
||||
conn.execute(silence_query)
|
||||
conn.execute(inhibit_query)
|
||||
|
||||
self.alarm1['inhibited'] = True
|
||||
self.alarm1['silenced'] = True
|
||||
|
||||
res = self.repo.get_alarms(tenant_id='Not a tenant id', limit=1)
|
||||
self.assertEqual(res, [])
|
||||
|
||||
tenant_id = 'bob'
|
||||
res = self.repo.get_alarms(tenant_id=tenant_id, limit=1000)
|
||||
res = self.helper_builder_result(res)
|
||||
|
||||
expected = [self.alarm1,
|
||||
self.alarm2,
|
||||
self.alarm_compound,
|
||||
self.alarm3]
|
||||
|
||||
self.assertEqual(res, expected)
|
||||
|
@ -267,6 +267,8 @@ class Alarms(alarms_api_v2.AlarmsV2API,
|
||||
u'state': alarm_row['state'],
|
||||
u'lifecycle_state': alarm_row['lifecycle_state'],
|
||||
u'link': alarm_row['link'],
|
||||
u'inhibited': alarm_row['inhibited'],
|
||||
u'silenced': alarm_row['silenced'],
|
||||
u'state_updated_timestamp':
|
||||
alarm_row['state_updated_timestamp'].isoformat() +
|
||||
'Z',
|
||||
@ -322,6 +324,8 @@ class Alarms(alarms_api_v2.AlarmsV2API,
|
||||
u'state': alarm_row['state'],
|
||||
u'lifecycle_state': alarm_row['lifecycle_state'],
|
||||
u'link': alarm_row['link'],
|
||||
u'inhibited': alarm_row['inhibited'],
|
||||
u'silenced': alarm_row['silenced'],
|
||||
u'state_updated_timestamp':
|
||||
alarm_row['state_updated_timestamp'].isoformat() +
|
||||
'Z',
|
||||
|
@ -1053,17 +1053,18 @@ class TestAlarms(base.BaseMonascaTest):
|
||||
break
|
||||
|
||||
def _verify_alarm_keys(self, response_body):
|
||||
self.assertTrue(set(['id',
|
||||
'links',
|
||||
'alarm_definition',
|
||||
'metrics',
|
||||
'state',
|
||||
'lifecycle_state',
|
||||
'link',
|
||||
'state_updated_timestamp',
|
||||
'updated_timestamp',
|
||||
'created_timestamp']) ==
|
||||
set(response_body))
|
||||
expected_keys = ['id',
|
||||
'links',
|
||||
'alarm_definition',
|
||||
'metrics',
|
||||
'state',
|
||||
'lifecycle_state',
|
||||
'link',
|
||||
'state_updated_timestamp',
|
||||
'updated_timestamp',
|
||||
'created_timestamp']
|
||||
for key in expected_keys:
|
||||
self.assertIn(key, response_body)
|
||||
|
||||
def _verify_metric_in_alarm(self, metric, expected_metric):
|
||||
self.assertEqual(metric['dimensions'], expected_metric['dimensions'])
|
||||
|
Loading…
x
Reference in New Issue
Block a user