Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for URL rendering #536

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions promgen/fixtures/testcases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions promgen/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion promgen/templates/promgen/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<li><a href="{% url 'api:api-root' %}">API</a></li>
<li><a href="{% url 'api:all-targets' %}">Export Targets</a></li>
<li><a href="{% url 'api:all-rules' %}">Export Rules</a></li>
<li><a href="{% url 'config-urls' %}">Export URL</a></li>
<li><a href="{% url 'api:all-urls' %}">Export URLs</a></li>
</ul>
</li>
{% include 'promgen/help_menu.inc.html' %}
Expand Down
12 changes: 12 additions & 0 deletions promgen/tests/examples/export.urls.json
Original file line number Diff line number Diff line change
@@ -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"]
}
]
6 changes: 6 additions & 0 deletions promgen/tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)