Skip to content

Commit

Permalink
[change] Removed charts which have empty data #349
Browse files Browse the repository at this point in the history
Closes #349

Co-authored-by: Federico Capoano <[email protected]>
  • Loading branch information
Aryamanz29 and nemesifier authored May 5, 2022
1 parent e0d0fb2 commit 4dbed03
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openwisp_monitoring/device/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def _get_charts_data(self, charts, time, timezone):
# prepare chart dict
try:
chart_dict = chart.read(time=time, x_axys=x_axys, timezone=timezone)
if not chart_dict['traces']:
continue
chart_dict['description'] = chart.description
chart_dict['title'] = chart.title.format(
metric=chart.metric, **chart.metric.tags
Expand Down
11 changes: 11 additions & 0 deletions openwisp_monitoring/device/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,17 @@ def test_histogram_csv_none_value(self):
self.assertEqual(rows[-2].strip().split(','), ['http2', '100'])
self.assertEqual(rows[-1].strip().split(','), ['ssh', '0'])

def test_get_device_metrics_empty(self):
d = self._create_device(organization=self._create_org())
m = self._create_object_metric(name='test_metric', content_object=d)
c = Chart(metric=m, configuration='dummy') # empty chart
c.full_clean()
c.save()
self.assertEqual(Chart.objects.count(), 1)
response = self.client.get(self._url(d.pk.hex, d.key))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data['charts'], [])

def test_get_device_metrics_400_bad_timezone(self):
dd = self.create_test_data(no_resources=True)
d = self.device_model.objects.get(pk=dd.pk)
Expand Down

0 comments on commit 4dbed03

Please sign in to comment.