{{- if .Values.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "prometheus-pushgateway.fullname" .  }}
  {{- if .Values.serviceMonitor.namespace }}
  namespace: {{ .Values.serviceMonitor.namespace }}
  {{- end }}
  labels:
{{ template "prometheus-pushgateway.defaultLabels" merge (dict "extraLabels" .Values.serviceMonitor.additionalLabels) .  }}
spec:
  endpoints:
  - port: http
    {{- if .Values.serviceMonitor.interval }}
    interval: {{ .Values.serviceMonitor.interval }}
    {{- end }}
    {{- if .Values.serviceMonitor.scrapeTimeout }}
    scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
    {{- end }}
    path: /metrics
    honorLabels: {{ .Values.serviceMonitor.honorLabels }}
    {{- if .Values.serviceMonitor.metricRelabelings }}
    metricRelabelings:
    {{- tpl (toYaml .Values.serviceMonitor.metricRelabelings | nindent 4) . }}
    {{- end }}
    {{- if .Values.serviceMonitor.relabelings }}
    relabelings:
    {{ toYaml .Values.serviceMonitor.relabelings | nindent 4 }}
    {{- end }}
  namespaceSelector:
    matchNames:
      - {{ .Release.Namespace }}
  selector:
    matchLabels:
      app: {{ template "prometheus-pushgateway.name" . }}
      release: {{ .Release.Name }}
{{- end -}}
