{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "prometheus-mysql-exporter.fullname" . }}
  labels:
    app: {{ template "prometheus-mysql-exporter.name" . }}
    chart: {{ template "prometheus-mysql-exporter.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  {{- if .Values.serviceMonitor.additionalLabels }}
{{ toYaml .Values.serviceMonitor.additionalLabels | indent 4 }}
  {{- end }}
spec:
  selector:
    matchLabels:
      app: {{ template "prometheus-mysql-exporter.name" . }}
      release: {{ .Release.Name }}
  {{- with .Values.serviceMonitor.jobLabel }}
  jobLabel: {{ . | quote}}
  {{- end }}
  {{- with .Values.serviceMonitor.targetLabels }}
  targetLabels:
{{ toYaml . | trim | indent 4 -}}
  {{- end }}
  {{- with .Values.serviceMonitor.podTargetLabels }}
  podTargetLabels:
{{ toYaml . | trim | indent 4 -}}
  {{- end }}
  endpoints:
    - path: /metrics
      port: {{ .Values.service.name }}
  {{- if .Values.serviceMonitor.interval }}
      interval: {{ .Values.serviceMonitor.interval }}
  {{- end }}
  {{- if .Values.serviceMonitor.scrapeTimeout }}
      scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
  {{- end }}
  {{- if .Values.serviceMonitor.metricRelabelings }}
      metricRelabelings: {{ toYaml .Values.serviceMonitor.metricRelabelings | nindent 8 }}
  {{- end }}
{{- end }}