Updated prometheus datasource tempest to support working with config file
Change-Id: I35fa08e9723a94e9611678efdcbbdb3a2826ff68
This commit is contained in:
parent
d6732c1e4c
commit
aca285b10c
@ -15,4 +15,8 @@
|
||||
|
||||
DEVSTACK_PATH="$BASE/new"
|
||||
|
||||
# Copy prometheus_conf.yaml to /etc/vitrage directory
|
||||
ETC_VITRAGE=/etc/vitrage/
|
||||
PROMETHES_CONF_PATH=vitrage-tempest-plugin/vitrage_tempest_plugin/tests/resources/prometheus/prometheus_conf.yaml
|
||||
sudo mkdir -p $ETC_VITRAGE && sudo cp $DEVSTACK_PATH/$PROMETHES_CONF_PATH $ETC_VITRAGE
|
||||
|
||||
|
@ -31,15 +31,17 @@ RESOLVED = 'resolved'
|
||||
class TestPrometheus(BaseTestEvents):
|
||||
"""Test class for Prometheus datasource"""
|
||||
|
||||
def test_send_prometheus_alert_without_resource_id(self):
|
||||
def test_send_prometheus_alert_on_host_without_resource_id(self):
|
||||
"""Sending an alert in Prometheus format should result in an alarm"""
|
||||
self._test_send_prometheus_alert(
|
||||
self._create_prometheus_alert_details('host123', FIRING))
|
||||
self._create_prometheus_alert_on_host_details('host123', FIRING))
|
||||
|
||||
def test_send_prometheus_alert_without_resource_id_v2(self):
|
||||
def test_send_prometheus_alert_on_instance_without_resource_id(self):
|
||||
"""Sending an alert in Prometheus format should result in an alarm"""
|
||||
self._test_send_prometheus_alert(
|
||||
self._create_prometheus_alert_details('host457', FIRING))
|
||||
self._create_prometheus_alert_on_instance_details('host457',
|
||||
'instance457',
|
||||
FIRING))
|
||||
|
||||
def _test_send_prometheus_alert(self, details):
|
||||
try:
|
||||
@ -52,19 +54,18 @@ class TestPrometheus(BaseTestEvents):
|
||||
# expect to get a 'prometheus.alarm', generated by Prometheus
|
||||
# datasource
|
||||
self.assertThat(api_alarms, matchers.HasLength(1),
|
||||
'Expected Prometheus alarm on host')
|
||||
'Expected Prometheus alarm')
|
||||
|
||||
alarm = api_alarms[0]
|
||||
self._check_alarm(alarm, details)
|
||||
|
||||
event_time = datetime.now()
|
||||
details['status'] = RESOLVED
|
||||
self._resolve_alerts(details)
|
||||
self._post_event(event_time, event_type, details)
|
||||
|
||||
api_alarms = wait_for_answer(2, 0.5, self._check_alarms)
|
||||
self.assertIsNotNone(api_alarms,)
|
||||
self.assertThat(api_alarms, IsEmpty(), 'Expected no alarms on '
|
||||
'host')
|
||||
self.assertThat(api_alarms, IsEmpty(), 'Expected no alarms')
|
||||
|
||||
except Exception as e:
|
||||
LOG.exception(e)
|
||||
@ -77,7 +78,13 @@ class TestPrometheus(BaseTestEvents):
|
||||
self.assertFalse(alarm[VProps.VITRAGE_IS_PLACEHOLDER])
|
||||
|
||||
@staticmethod
|
||||
def _create_prometheus_alert_details(hostname, status):
|
||||
def _resolve_alerts(details):
|
||||
details['status'] = RESOLVED
|
||||
for alert in details['alerts']:
|
||||
alert['status'] = RESOLVED
|
||||
|
||||
@staticmethod
|
||||
def _create_prometheus_alert_on_host_details(hostname, status):
|
||||
return {
|
||||
"status": status,
|
||||
"groupLabels": {
|
||||
@ -130,3 +137,47 @@ class TestPrometheus(BaseTestEvents):
|
||||
"mountpoint": "/"
|
||||
}
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _create_prometheus_alert_on_instance_details(hostname,
|
||||
instance,
|
||||
status):
|
||||
return {
|
||||
'status': status,
|
||||
'groupLabels': {
|
||||
'alertname': 'HighCpuOnVmAlert'
|
||||
},
|
||||
'groupKey': '{}:{alertname="HighCpuOnVmAlert"}',
|
||||
'commonAnnotations': {
|
||||
'description': 'Test alert to test libvirt exporter.\n',
|
||||
'title': 'High cpu usage on vm'
|
||||
},
|
||||
'alerts': [
|
||||
{
|
||||
'status': status,
|
||||
'labels': {
|
||||
'instance': hostname,
|
||||
'domain': instance,
|
||||
'job': 'libvirt',
|
||||
'alertname': 'HighCpuOnVmAlert',
|
||||
'severity': 'critical'
|
||||
},
|
||||
'endsAt': '2019-01-15T12:29:50.91446215Z',
|
||||
'generatorURL': 'http://devstack-rocky-release-4:9090',
|
||||
'startsAt': '2019-01-15T12:26:50.91446215Z',
|
||||
'annotations': {
|
||||
'description': 'Test alert to test libvirt exporter',
|
||||
'title': 'High cpu usage on vm'
|
||||
}
|
||||
}
|
||||
],
|
||||
'version': '4',
|
||||
'receiver': 'vitrage',
|
||||
'externalURL': 'http://devstack-rocky-release-4:9093',
|
||||
'commonLabels': {
|
||||
'instance': hostname,
|
||||
'job': 'libvirt',
|
||||
'severity': 'critical',
|
||||
'alertname': 'HighCpuOnVmAlert'
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
alerts:
|
||||
- key:
|
||||
alertname: HighCpuOnVmAlert
|
||||
job: libvirt
|
||||
resource:
|
||||
instance_name: domain
|
||||
host_id: instance
|
||||
- key:
|
||||
alertname: HighInodeUsage
|
||||
job: node
|
||||
resource:
|
||||
id: instance
|
Loading…
Reference in New Issue
Block a user