Skip to content

Commit

Permalink
[helm] Support for Servicemonitor (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlamirault authored Feb 10, 2024
1 parent 9ba98c5 commit 383045b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
9 changes: 9 additions & 0 deletions deploy/helm/grafana-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,14 @@ It's easier to just manage this configuration outside of the operator.
| serviceAccount.annotations | object | `{}` | Annotations to add to the service account |
| serviceAccount.create | bool | `true` | Specifies whether a service account should be created |
| serviceAccount.name | string | `""` | The name of the service account to use. If not set and create is true, a name is generated using the fullname template |
| serviceMonitor | object | `{"additionalLabels":{},"enabled":false,"interval":"1m","metricRelabelings":[],"relabelings":[],"scrapeTimeout":"10s","targetLabels":[],"telemetryPath":"/metrics"}` | Enable this to use with Prometheus Operator |
| serviceMonitor.additionalLabels | object | `{}` | Set of labels to transfer from the Kubernetes Service onto the target |
| serviceMonitor.enabled | bool | `false` | When set true then use a ServiceMonitor to configure scraping |
| serviceMonitor.interval | string | `"1m"` | Set how frequently Prometheus should scrape |
| serviceMonitor.metricRelabelings | list | `[]` | MetricRelabelConfigs to apply to samples before ingestion |
| serviceMonitor.relabelings | list | `[]` | Set relabel_configs as per https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config |
| serviceMonitor.scrapeTimeout | string | `"10s"` | Set timeout for scrape |
| serviceMonitor.targetLabels | list | `[]` | Set of labels to transfer from the Kubernetes Service onto the target |
| serviceMonitor.telemetryPath | string | `"/metrics"` | Set path to metrics path |
| tolerations | list | `[]` | pod tolerations |
| watchNamespaces | string | `""` | Sets the WATCH_NAMESPACE environment variable, it defines which namespaces the operator should be listening for. By default it's all namespaces, if you only want to listen for the same namespace as the operator is deployed to look at namespaceScope. |
46 changes: 46 additions & 0 deletions deploy/helm/grafana-operator/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{{- if.Values.serviceMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ include "grafana-operator.fullname" . }}
namespace: {{ include "grafana-operator.namespace" . }}
labels:
{{- include "grafana-operator.labels" . | nindent 4 }}
{{- with .Values.additionalLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.serviceMonitor.additionalLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
jobLabel: {{ .Release.Name }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
selector:
matchLabels:
{{- include "grafana-operator.selectorLabels" . | nindent 6 }}
endpoints:
- port: metrics
path: {{ .Values.serviceMonitor.telemetryPath }}
{{- with .Values.serviceMonitor.interval }}
interval: {{ . }}
{{- end }}
{{- with .Values.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ . }}
{{- end }}
{{- if .Values.serviceMonitor.metricRelabelings }}
metricRelabelings:
{{ toYaml .Values.serviceMonitor.metricRelabelings | indent 4 }}
{{- end }}
{{- if .Values.serviceMonitor.relabelings }}
relabelings:
{{ toYaml .Values.serviceMonitor.relabelings | nindent 4 }}
{{- end }}
{{- if .Values.serviceMonitor.targetLabels }}
targetLabels:
{{- range .Values.serviceMonitor.targetLabels }}
- {{ . }}
{{- end }}
{{- end }}
{{- end }}
19 changes: 19 additions & 0 deletions deploy/helm/grafana-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,22 @@ tolerations: []

# -- pod affinity
affinity: {}

# -- Enable this to use with Prometheus Operator
serviceMonitor:
# -- When set true then use a ServiceMonitor to configure scraping
enabled: false
# -- Set of labels to transfer from the Kubernetes Service onto the target
additionalLabels: {}
# -- Set how frequently Prometheus should scrape
interval: 1m
# -- Set timeout for scrape
scrapeTimeout: 10s
# -- Set path to metrics path
telemetryPath: /metrics
# -- Set of labels to transfer from the Kubernetes Service onto the target
targetLabels: []
# -- MetricRelabelConfigs to apply to samples before ingestion
metricRelabelings: []
# -- Set relabel_configs as per https://prometheus.io/docs/prometheus/latest/configuration/configuration/#relabel_config
relabelings: []

0 comments on commit 383045b

Please sign in to comment.