{{- if .Values.monitoring.serviceMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "pulse.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "pulse.labels" . | nindent 4 }}
    {{- with .Values.monitoring.serviceMonitor.labels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
spec:
  selector:
    matchLabels:
      {{- include "pulse.selectorLabels" . | nindent 6 }}
  endpoints:
    - port: http
      {{- with .Values.monitoring.serviceMonitor.interval }}
      interval: {{ . }}
      {{- end }}
      {{- with .Values.monitoring.serviceMonitor.scrapeTimeout }}
      scrapeTimeout: {{ . }}
      {{- end }}
      path: {{ .Values.monitoring.serviceMonitor.path | default "/metrics" }}
      {{- with .Values.monitoring.serviceMonitor.relabelings }}
      relabelings:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.monitoring.serviceMonitor.metricRelabelings }}
      metricRelabelings:
        {{- toYaml . | nindent 8 }}
      {{- end }}
{{- end }}
