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 service monitor for simple configuration of prometheus metrics #11

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
37 changes: 37 additions & 0 deletions charts/kpow/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,40 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
If all metrics should be exported
*/}}
{{- define "kpow.monitor.exportAllMetrics" -}}
{{- with .Values.serviceMonitor.metrics }}
{{- if and (eq (len .clusters) 0) (eq (len .schemas) 0) }}
{{- print true }}
{{- else }}
{{- print false }}
{{- end }}
{{- end }}
{{- end }}

{{/*
If all offsets should be exported
*/}}
{{- define "kpow.monitor.exportAllOffsets" -}}
{{- with .Values.serviceMonitor.offsets }}
{{- if and (eq (len .topics) 0) (eq (len .clusters) 0) }}
{{- print true }}
{{- else }}
{{- print false }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Generate service monitor endpoint
*/}}
{{- define "kpow.monitor.endpoint" -}}
{{- $endpoint := index . 0 }}
{{- $values := index . 1 }}
- interval: {{ $values.serviceMonitor.interval | default "15s" }}
port: {{ $values.service.port }}
path: {{ $endpoint }}
{{- end }}
43 changes: 43 additions & 0 deletions charts/kpow/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- if .Values.serviceMonitor.enabled }}
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
{{ .Values.serviceMonitor.labels | toYaml | nindent 4 }}
name: {{ include "kpow.fullname" . }}
spec:
endpoints:
{{- if eq (include "kpow.monitor.exportAllMetrics" .) "true" }}
{{- include "kpow.monitor.endpoint" (list "/metrics/v1" .Values) | nindent 4 }}
{{- else }}
{{- range .Values.serviceMonitor.metrics.clusters }}
{{- $metricsClusterEndpoint := printf "/metrics/v1/cluster/%s" . }}
{{- include "kpow.monitor.endpoint" (list $metricsClusterEndpoint $.Values) | nindent 4 }}
{{- end }}
{{- range .Values.serviceMonitor.metrics.schemas}}
{{- $schemaEndpoint := printf "/metrics/v1/schema/%s" . }}
{{- include "kpow.monitor.endpoint" (list $schemaEndpoint $.Values) | nindent 4 }}
{{- end }}
{{- end }}
{{- if eq (include "kpow.monitor.exportAllOffsets" .) "true" }}
{{- include "kpow.monitor.endpoint" (list "/offsets/v1" .Values) | nindent 4 }}
{{- else }}
{{- range .Values.serviceMonitor.offsets.topics }}
{{- $topicEndpoint := printf "/offsets/v1/topic/%s" . }}
{{- include "kpow.monitor.endpoint" (list $topicEndpoint $.Values) | nindent 4 }}
{{- end }}
{{- range .Values.serviceMonitor.offsets.clusters}}
{{- $offsetClusterEndpoint := printf "/offsets/v1/cluster/%s" . }}
{{- include "kpow.monitor.endpoint" (list $offsetClusterEndpoint $.Values) | nindent 4 }}
{{- end }}
{{- end }}
{{- if .Values.serviceMonitor.offsets.groups }}
{{- include "kpow.monitor.endpoint" (list "/group-offsets/v1" .Values) | nindent 4 }}
{{- end }}
jobLabel: {{ .Values.serviceMonitor.jobLabel }}
namespaceSelector:
{{- .Values.serviceMonitor.namespaceSelector | toYaml | nindent 4 }}
selector:
{{- .Values.serviceMonitor.selector | toYaml | nindent 4 }}
{{- end }}
16 changes: 15 additions & 1 deletion charts/kpow/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,18 @@ tolerations: []

affinity: {}

labels: {}
labels: {}

serviceMonitor:
enabled: false
metrics:
clusters: []
schemas: []
offsets:
groups: true
topics: []
clusters: []
labels: {}
jobLabel: null
namespaceSelector: {}
selector: {}