root: fix prometheus path in ServiceMonitor, return WWW-Authenticate header so basic auth is sent
This commit is contained in:
parent
9bdff14403
commit
7bf7bde856
|
@ -18,6 +18,7 @@ spec:
|
||||||
name: {{ include "passbook.fullname" . }}-secret-key
|
name: {{ include "passbook.fullname" . }}-secret-key
|
||||||
key: monitoring_username
|
key: monitoring_username
|
||||||
port: http
|
port: http
|
||||||
|
path: /metrics/
|
||||||
interval: 10s
|
interval: 10s
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
|
|
||||||
from django.conf import settings
|
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.views import View
|
||||||
from django_prometheus.exports import ExportToDjangoView
|
from django_prometheus.exports import ExportToDjangoView
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@ class MetricsView(View):
|
||||||
expected = b64encode(str.encode(credentials)).decode()
|
expected = b64encode(str.encode(credentials)).decode()
|
||||||
|
|
||||||
if auth_type != "Basic" or credentials != expected:
|
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)
|
return ExportToDjangoView(request)
|
||||||
|
|
|
@ -35,7 +35,7 @@ for _passbook_app in get_apps():
|
||||||
urlpatterns += [
|
urlpatterns += [
|
||||||
# Administration
|
# Administration
|
||||||
path("administration/django/", admin.site.urls),
|
path("administration/django/", admin.site.urls),
|
||||||
path("metrics", MetricsView.as_view(), name="metrics"),
|
path("metrics/", MetricsView.as_view(), name="metrics"),
|
||||||
]
|
]
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
|
|
Reference in New Issue