diff --git a/promgen/fixtures/testcases.yaml b/promgen/fixtures/testcases.yaml index 31b0d427e..39543c9d8 100644 --- a/promgen/fixtures/testcases.yaml +++ b/promgen/fixtures/testcases.yaml @@ -70,3 +70,13 @@ job: node port: 9100 enabled: false +- model: promgen.probe + pk: 1 + fields: + module: fixture_test +- model: promgen.url + pk: 1 + fields: + project: 1 + probe: 1 + url: probe.example.com diff --git a/promgen/rest.py b/promgen/rest.py index 335f984b2..a080dbd10 100644 --- a/promgen/rest.py +++ b/promgen/rest.py @@ -39,6 +39,13 @@ def targets(self, request): content_type="application/json", ) + @action(detail=False, methods=["get"], renderer_classes=[renderers.renderers.JSONRenderer]) + def urls(self, request): + return HttpResponse( + prometheus.render_urls(), + content_type="application/json", + ) + class ShardViewSet(viewsets.ModelViewSet): queryset = models.Shard.objects.all() diff --git a/promgen/templates/promgen/navbar.html b/promgen/templates/promgen/navbar.html index 7fd28b468..bce3861b6 100644 --- a/promgen/templates/promgen/navbar.html +++ b/promgen/templates/promgen/navbar.html @@ -36,7 +36,7 @@
  • API
  • Export Targets
  • Export Rules
  • -
  • Export URL
  • +
  • Export URLs
  • {% include 'promgen/help_menu.inc.html' %} diff --git a/promgen/tests/examples/export.urls.json b/promgen/tests/examples/export.urls.json new file mode 100644 index 000000000..16197b29c --- /dev/null +++ b/promgen/tests/examples/export.urls.json @@ -0,0 +1,12 @@ +[ + { + "labels": { + "__param_module": "fixture_test", + "__shard": "test-shard", + "job": "fixture_test", + "project": "test-project", + "service": "test-service" + }, + "targets": ["probe.example.com"] + } +] diff --git a/promgen/tests/test_renderers.py b/promgen/tests/test_renderers.py index 337c6c160..8d725badd 100644 --- a/promgen/tests/test_renderers.py +++ b/promgen/tests/test_renderers.py @@ -23,3 +23,9 @@ def test_global_targets(self): response = self.client.get(reverse("api:all-targets")) self.assertEqual(response.status_code, 200) self.assertEqual(response.json(), expected) + + def test_global_urls(self): + expected = tests.Data("examples", "export.urls.json").json() + response = self.client.get(reverse("api:all-urls")) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json(), expected)