From 3d73aac3abda21982f312ca5bb9a9e9611a0eb08 Mon Sep 17 00:00:00 2001 From: "Langhammer, Jens" Date: Fri, 8 Nov 2019 12:24:02 +0100 Subject: [PATCH] helm(minor): add service monitors --- helm/passbook/templates/static-sm.yaml | 15 +++++++++++++++ helm/passbook/templates/web-service.yaml | 3 ++- helm/passbook/templates/web-sm.yaml | 22 ++++++++++++++++++++++ passbook/root/monitoring.py | 4 +++- passbook/root/urls.py | 2 +- 5 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 helm/passbook/templates/static-sm.yaml create mode 100644 helm/passbook/templates/web-sm.yaml diff --git a/helm/passbook/templates/static-sm.yaml b/helm/passbook/templates/static-sm.yaml new file mode 100644 index 000000000..22f961b39 --- /dev/null +++ b/helm/passbook/templates/static-sm.yaml @@ -0,0 +1,15 @@ +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/name: {{ include "passbook.name" . }} + helm.sh/chart: {{ include "passbook.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + name: {{ include "passbook.fullname" . }}-static-monitoring +spec: + endpoints: + - port: http + selector: + matchLabels: + k8s.passbook.io/component: static diff --git a/helm/passbook/templates/web-service.yaml b/helm/passbook/templates/web-service.yaml index d6564161f..4f600974a 100644 --- a/helm/passbook/templates/web-service.yaml +++ b/helm/passbook/templates/web-service.yaml @@ -4,9 +4,10 @@ metadata: name: {{ include "passbook.fullname" . }}-web labels: app.kubernetes.io/name: {{ include "passbook.name" . }} - helm.sh/chart: {{ include "passbook.chart" . }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/managed-by: {{ .Release.Service }} + helm.sh/chart: {{ include "passbook.chart" . }} + k8s.passbook.io/component: web spec: type: {{ .Values.service.type }} ports: diff --git a/helm/passbook/templates/web-sm.yaml b/helm/passbook/templates/web-sm.yaml new file mode 100644 index 000000000..cbdd24e48 --- /dev/null +++ b/helm/passbook/templates/web-sm.yaml @@ -0,0 +1,22 @@ +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + labels: + app.kubernetes.io/name: {{ include "passbook.name" . }} + helm.sh/chart: {{ include "passbook.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + name: {{ include "passbook.fullname" . }}-web-monitoring +spec: + endpoints: + - basicAuth: + password: + name: {{ include "passbook.fullname" . }}-secret-key + key: secret_key + username: + name: {{ include "passbook.fullname" . }}-secret-key + key: monitoring_username + port: http + selector: + matchLabels: + k8s.passbook.io/component: web diff --git a/passbook/root/monitoring.py b/passbook/root/monitoring.py index 625d81f97..c7c824715 100644 --- a/passbook/root/monitoring.py +++ b/passbook/root/monitoring.py @@ -1,10 +1,12 @@ """Metrics view""" from base64 import b64encode + from django.conf import settings +from django.http import Http404, HttpRequest, HttpResponse from django.views import View -from django.http import HttpRequest, HttpResponse, Http404 from django_prometheus.exports import ExportToDjangoView + class MetricsView(View): """Wrapper around ExportToDjangoView, using http-basic auth""" diff --git a/passbook/root/urls.py b/passbook/root/urls.py index b960b1178..9f7f4e6c9 100644 --- a/passbook/root/urls.py +++ b/passbook/root/urls.py @@ -6,8 +6,8 @@ from django.views.generic import RedirectView from structlog import get_logger from passbook.core.views import error -from passbook.root.monitoring import MetricsView from passbook.lib.utils.reflection import get_apps +from passbook.root.monitoring import MetricsView LOGGER = get_logger() admin.autodiscover()