Hide Graph Metric action of alarm when Grafana is not available
When Grafana integration is not available, click the action button of Graph Metric will go to a non-existing Grafana page. Added logic to hide the Graph Metric button when Grafana integration is not avaialable. Also added unit tests for the changes. Story: 2005906 Task: 34165 Change-Id: I617a0c609450bf015ddf6e98fd672723a2660071
This commit is contained in:
parent
6d1ac152a6
commit
43f285394f
@ -15,6 +15,7 @@
|
||||
|
||||
import json
|
||||
|
||||
from django.conf import settings
|
||||
from django import template
|
||||
from django.urls import reverse
|
||||
from django.urls import reverse_lazy
|
||||
@ -25,7 +26,6 @@ from horizon import tables
|
||||
|
||||
from monitoring.alarms import constants
|
||||
from monitoring import api
|
||||
from monitoring.config import local_settings
|
||||
from monitoring.overview import constants as ov_constants
|
||||
|
||||
|
||||
@ -159,7 +159,7 @@ class GraphMetric(tables.LinkAction):
|
||||
self.attrs['target'] = '_blank'
|
||||
try:
|
||||
region = self.table.request.user.services_region
|
||||
grafana_url = getattr(local_settings, 'GRAFANA_URL').get(region, '')
|
||||
grafana_url = getattr(settings, 'GRAFANA_URL').get(region, '')
|
||||
url = grafana_url + \
|
||||
'/dashboard/script/drilldown.js'
|
||||
metric = datum['metrics'][0]['name']
|
||||
@ -179,7 +179,8 @@ class GraphMetric(tables.LinkAction):
|
||||
return url + query
|
||||
|
||||
def allowed(self, request, datum=None):
|
||||
return datum['metrics']
|
||||
return (getattr(settings, 'GRAFANA_URL', None) is not None and
|
||||
datum['metrics'])
|
||||
|
||||
|
||||
class ShowAlarmDefinition(tables.LinkAction):
|
||||
|
@ -15,6 +15,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from mock import Mock
|
||||
|
||||
import monitoring.alarms.tables
|
||||
@ -46,3 +47,18 @@ class GraphMetricLinkActionTests(TestCase):
|
||||
r'&threshold=[{"name": "metric1"}, {"name": "metric \u2461"}]'
|
||||
r'&api=http://foo/api/'
|
||||
)
|
||||
|
||||
def test_allowed_grafana_links(self):
|
||||
allowed = self.get_allowed()
|
||||
self.assertEqual(allowed, False)
|
||||
|
||||
@override_settings(GRAFANA_URL={'CustomRegion': '/grafana'})
|
||||
def test_allowed_grafana_links_nonempty(self):
|
||||
allowed = self.get_allowed()
|
||||
self.assertEqual(allowed, 'metrics')
|
||||
|
||||
def get_allowed(self):
|
||||
table_mock = Mock()
|
||||
table_mock.request.build_absolute_uri.return_value = u"http://foo/api/"
|
||||
link_action = monitoring.alarms.tables.GraphMetric(table=table_mock)
|
||||
return link_action.allowed(table_mock.request, {'metrics': 'metrics'})
|
||||
|
Loading…
x
Reference in New Issue
Block a user