forked from GithubBackups/healthchecks
Return max notification_id in metrics.
This commit is contained in:
parent
98310eeeaa
commit
3730c67c80
@ -1,6 +1,6 @@
|
|||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from hc.api.models import Check, Flip, Ping
|
from hc.api.models import Channel, Check, Flip, Notification, Ping
|
||||||
from hc.test import BaseTestCase
|
from hc.test import BaseTestCase
|
||||||
|
|
||||||
|
|
||||||
@ -33,6 +33,18 @@ class MetricsTestCase(BaseTestCase):
|
|||||||
doc = r.json()
|
doc = r.json()
|
||||||
self.assertEqual(doc["max_ping_id"], last_ping.id)
|
self.assertEqual(doc["max_ping_id"], last_ping.id)
|
||||||
|
|
||||||
|
def test_it_returns_max_notification_id(self):
|
||||||
|
check = Check.objects.create(project=self.project, status="down")
|
||||||
|
channel = Channel.objects.create(project=self.project, kind="email")
|
||||||
|
Notification.objects.create(owner=check, channel=channel, check_status="down")
|
||||||
|
last_notification = Notification.objects.last()
|
||||||
|
|
||||||
|
r = self.client.get(self.url, HTTP_X_METRICS_KEY="foo")
|
||||||
|
self.assertEqual(r.status_code, 200)
|
||||||
|
|
||||||
|
doc = r.json()
|
||||||
|
self.assertEqual(doc["max_notification_id"], last_notification.id)
|
||||||
|
|
||||||
@override_settings(METRICS_KEY=None)
|
@override_settings(METRICS_KEY=None)
|
||||||
def test_it_handles_unset_metrics_key(self):
|
def test_it_handles_unset_metrics_key(self):
|
||||||
r = self.client.get(self.url, HTTP_X_METRICS_KEY="foo")
|
r = self.client.get(self.url, HTTP_X_METRICS_KEY="foo")
|
||||||
|
@ -329,10 +329,12 @@ def metrics(request):
|
|||||||
if key != settings.METRICS_KEY:
|
if key != settings.METRICS_KEY:
|
||||||
return HttpResponseForbidden()
|
return HttpResponseForbidden()
|
||||||
|
|
||||||
doc = {}
|
doc = {
|
||||||
doc["ts"] = int(time.time())
|
"ts": int(time.time()),
|
||||||
doc["max_ping_id"] = Ping.objects.values_list("id", flat=True).last()
|
"max_ping_id": Ping.objects.values_list("id", flat=True).last(),
|
||||||
doc["num_unprocessed_flips"] = Flip.objects.filter(processed__isnull=True).count()
|
"max_notification_id": Notification.objects.values_list("id", flat=True).last(),
|
||||||
|
"num_unprocessed_flips": Flip.objects.filter(processed__isnull=True).count(),
|
||||||
|
}
|
||||||
|
|
||||||
return JsonResponse(doc)
|
return JsonResponse(doc)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user