Skip to content

Commit

Permalink
feat(openfga): add servicemonitor to OpenFGA chart (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
cstruck authored Mar 28, 2024
1 parent 158e55a commit 9b43bda
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 3 deletions.
2 changes: 1 addition & 1 deletion charts/openfga/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: openfga
description: A Kubernetes Helm chart for the OpenFGA project.

type: application
version: 0.1.41
version: 0.2.0
appVersion: "v1.5.1"

home: "https://openfga.github.io/helm-charts"
Expand Down
10 changes: 9 additions & 1 deletion charts/openfga/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ If release name contains chart name it will be used as a full name.
{{- end }}
{{- end }}

{{/*
Expand the namespace of the release.
Allows overriding it for multi-namespace deployments in combined charts.
*/}}
{{- define "openfga.namespace" -}}
{{- default .Release.Namespace .Values.namespaceOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
Expand Down Expand Up @@ -68,4 +76,4 @@ Return true if a secret object should be created
{{- if not (or .Values.global.postgresql.auth.existingSecret .Values.auth.existingSecret) -}}
{{- true -}}
{{- end -}}
{{- end -}}
{{- end -}}
52 changes: 52 additions & 0 deletions charts/openfga/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{- if and .Values.telemetry.metrics.enabled .Values.telemetry.metrics.serviceMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "openfga.fullname" . }}
{{- if .Values.telemetry.metrics.serviceMonitor.namespace }}
namespace: {{ .Values.telemetry.metrics.serviceMonitor.namespace }}
{{- else }}
namespace: {{ include "openfga.namespace" . }}
{{- end }}
labels:
{{- include "openfga.labels" . | nindent 4 }}
{{- if .Values.telemetry.metrics.serviceMonitor.additionalLabels }}
{{- toYaml .Values.telemetry.metrics.serviceMonitor.additionalLabels | nindent 4 }}
{{- end }}
{{- if .Values.telemetry.metrics.serviceMonitor.annotations }}
annotations: {{ toYaml .Values.telemetry.metrics.serviceMonitor.annotations | nindent 4 }}
{{- end }}
spec:
endpoints:
- port: metrics
interval: {{ .Values.telemetry.metrics.serviceMonitor.scrapeInterval }}
scrapeTimeout: {{ .Values.telemetry.metrics.serviceMonitor.scrapeTimeout }}
{{- if .Values.telemetry.metrics.serviceMonitor.honorLabels }}
honorLabels: true
{{- end }}
{{- if .Values.telemetry.metrics.serviceMonitor.relabelings }}
relabelings: {{ toYaml .Values.telemetry.metrics.serviceMonitor.relabelings | nindent 8 }}
{{- end }}
{{- if .Values.telemetry.metrics.serviceMonitor.metricRelabelings }}
metricRelabelings: {{ toYaml .Values.telemetry.metrics.serviceMonitor.metricRelabelings | nindent 8 }}
{{- end }}
{{- if .Values.telemetry.metrics.serviceMonitor.jobLabel }}
jobLabel: {{ .Values.telemetry.metrics.serviceMonitor.jobLabel | quote }}
{{- end }}
{{- if .Values.telemetry.metrics.serviceMonitor.namespaceSelector }}
namespaceSelector: {{ toYaml .Values.telemetry.metrics.serviceMonitor.namespaceSelector | nindent 4 }}
{{- else }}
namespaceSelector:
matchNames:
- {{ include "openfga.namespace" . }}
{{- end }}
{{- if .Values.telemetry.metrics.serviceMonitor.targetLabels }}
targetLabels:
{{- range .Values.telemetry.metrics.serviceMonitor.targetLabels }}
- {{ . }}
{{- end }}
{{- end }}
selector:
matchLabels:
{{- include "openfga.selectorLabels" . | nindent 6 }}
{{- end }}
62 changes: 61 additions & 1 deletion charts/openfga/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,66 @@
"description": "enable/disable prometheus metrics on the '/metrics' endpoint",
"default": true
},
"serviceMonitor": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean",
"description": "enable/disable installation of serviceMonitor custom resource",
"default": false
},
"additionalLabels": {
"type": "object",
"description": "additional labels to be added to the serivceMonitor resource",
"default": {}
},
"annotations": {
"type": "object",
"description": "annotations to be added to the serviceMonitor resource",
"default": {}
},
"jobLabel": {
"type": "string",
"description": "the label to use to retrieve the job name from",
"default": "app.kubernetes.io/name"
},
"namespace": {
"type": "string",
"description": "namespace where the serviceMonitor resource should be installed to",
"default": ""
},
"namespaceSelector": {
"type": "object",
"description": "which namespaces should be scraped",
"default": {}
},
"scrapeInterval": {
"type": "string",
"description": "prometheus scrape interval",
"default": "30s"
},
"scrapeTimeout": {
"type": "string",
"description": "prometheus scrape timeout",
"default": "10s"
},
"targetLabels": {
"type": "array",
"description": "additional target labels to scrape",
"default": []
},
"relabelings": {
"type": "array",
"description": "add job relabelings",
"default": []
},
"metricRelabelings": {
"type": "array",
"description": "add metric relabelings",
"default": []
}
}
},
"addr": {
"type": "string",
"description": "the host:port address to serve the prometheus metrics server on",
Expand Down Expand Up @@ -887,4 +947,4 @@
"common": {}
},
"additionalProperties": false
}
}
50 changes: 50 additions & 0 deletions charts/openfga/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,56 @@ telemetry:
##
enabled: true

serviceMonitor:
## @param telemetry.metrics.serviceMonitor.enabled enable/disable installation of serviceMonitor custom resource
##
enabled: false

## @param telemetry.metrics.serviceMonitor.additionalLabels additional labels to be added to the serivceMonitor resource
##
additionalLabels: {}

## @param telemetry.metrics.serviceMonitor.annotations annotations to be added to the serviceMonitor resource
##
annotations: {}

## @param telemetry.metrics.serviceMonitor.jobLabel the label to use to retrieve the job name from
##
jobLabel: "app.kubernetes.io/name"

## @param telemetry.metrics.serviceMonitor.namespace namespace where the serviceMonitor resource should be installed to
##
namespace: ""

## @param telemetry.metrics.serviceMonitor.namespaceSelector which namespaces should be scraped
##
## Default: scrape .Release.Namespace or namespaceOverride only
## To scrape all, use the following:
## namespaceSelector:
## any: true
##
namespaceSelector: {}

## @param telemetry.metrics.serviceMonitor.scrapeInterval prometheus scrape interval
##
scrapeInterval: 30s

## @param telemetry.metrics.serviceMonitor.scrapeTimeout prometheus scrape timeout
##
scrapeTimeout: 10s

## @param telemetry.metrics.serviceMonitor.targetLabels additional target labels to scrape
##
targetLabels: []

## @param telemetry.metrics.serviceMonitor.relabelings add job relabelings
##
relabelings: []

## @param telemetry.metrics.serviceMonitor.metricRelabelings add metric relabelings
##
metricRelabelings: []

## @param telemetry.metrics.addr the host:port address to serve the Metrics server on
addr: 0.0.0.0:2112

Expand Down

0 comments on commit 9b43bda

Please sign in to comment.