root: fix prometheus path in ServiceMonitor, return WWW-Authenticate header so basic auth is sent

This commit is contained in:
Jens Langhammer 2020-01-17 10:55:11 +01:00
parent 9bdff14403
commit 7bf7bde856
3 changed files with 6 additions and 3 deletions

View File

@ -18,6 +18,7 @@ spec:
name: {{ include "passbook.fullname" . }}-secret-key
key: monitoring_username
port: http
path: /metrics/
interval: 10s
selector:
matchLabels:

View File

@ -2,7 +2,7 @@
from base64 import b64encode
from django.conf import settings
from django.http import Http404, HttpRequest, HttpResponse
from django.http import HttpRequest, HttpResponse
from django.views import View
from django_prometheus.exports import ExportToDjangoView
@ -18,6 +18,8 @@ class MetricsView(View):
expected = b64encode(str.encode(credentials)).decode()
if auth_type != "Basic" or credentials != expected:
raise Http404
response = HttpResponse(status=401)
response['WWW-Authenticate'] = 'Basic realm="passbook-monitoring"'
return response
return ExportToDjangoView(request)

View File

@ -35,7 +35,7 @@ for _passbook_app in get_apps():
urlpatterns += [
# Administration
path("administration/django/", admin.site.urls),
path("metrics", MetricsView.as_view(), name="metrics"),
path("metrics/", MetricsView.as_view(), name="metrics"),
]
if settings.DEBUG: