Skip to content

Commit a01133d

Browse files
Maurice MeyerAMecea
authored andcommitted
Add ServiceMonitor for prometheus.
This commit adds a ServiceMonitor that is deployed when the CRD exists. Fixes #214.
1 parent 818452a commit a01133d

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1515

1616
## [0.4.0] - TBD
1717
### Added
18+
* Added a `ServiceMonitor` to the operator chart that scrapes all MySQL instances.
1819
* Added a test suite for RunCloneCommand logic, along with a mock backup server.
1920
* Added checks for service availability when cloning.
2021
* Added "fail fast" logic when unexpected errors occur during cloning/download.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This is a ServicMonitor for the MySQL clusters, not the operator itself.
2+
# To scrape the operator, we need https://github.com/presslabs/mysql-operator/issues/151 first.
3+
{{ if .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" -}}{{ if .Values.serviceMonitor.enabled -}}
4+
apiVersion: monitoring.coreos.com/v1
5+
kind: ServiceMonitor
6+
metadata:
7+
name: {{ template "mysql-operator.fullname" . }}
8+
labels:
9+
{{- include "mysql-operator.labels" . | nindent 4 }}
10+
{{- if .Values.serviceMonitor.additionalLabels }}
11+
{{ toYaml .Values.serviceMonitor.additionalLabels }}
12+
{{- end }}
13+
spec:
14+
{{- if .Values.serviceMonitor.jobLabel }}
15+
jobLabel: {{ .Values.serviceMonitor.jobLabel }}
16+
{{- end }}
17+
{{- if .Values.serviceMonitor.targetLabels }}
18+
targetLabels: {{ .Values.serviceMonitor.targetLabels }}
19+
{{- end }}
20+
{{- if .Values.serviceMonitor.podTargetLabels }}
21+
podTargetLabels: {{ .Values.serivceMonitor.podTargetLabels }}
22+
{{- end }}
23+
endpoints:
24+
- interval: {{ .Values.serviceMonitor.interval }}
25+
scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
26+
port: prometheus
27+
path: /metrics
28+
namespaceSelector: {{ toYaml .Values.serviceMonitor.namespaceSelector | nindent 4 }}
29+
selector: {{ toYaml .Values.serviceMonitor.selector | nindent 4 }}
30+
{{ end -}}{{ end -}}

charts/mysql-operator/values.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ installCRDs: true
1212
# in which namespace to watch for resource, leave empty to watch in all namespaces
1313
watchNamespace:
1414

15+
# The operator will install a ServiceMonitor if you have prometheus-operator installed.
16+
serviceMonitor:
17+
enabled: true
18+
## Additional labels for the serviceMonitor. Useful if you have multiple prometheus operators running to select only specific ServiceMonitors
19+
# additionalLabels:
20+
# prometheus: prom-internal
21+
interval: 10s
22+
scrapeTimeout: 3s
23+
# jobLabel:
24+
# targetLabels:
25+
# podTargetLabels:
26+
namespaceSelector:
27+
any: true
28+
selector:
29+
matchLabels:
30+
app.kubernetes.io/managed-by: mysql.presslabs.org
31+
app.kubernetes.io/name: mysql
32+
1533
nodeSelector: {}
1634
tolerations: []
1735
resources: {}

0 commit comments

Comments
 (0)