{{- if and ( .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" ) ( .Values.monitoring.serviceMonitor.enabled ) ( .Values.monitoring.enabled ) }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
{{- if .Values.monitoring.serviceMonitor.labels }}
  labels:
{{ toYaml .Values.monitoring.serviceMonitor.labels | indent 4}}
{{- end }}
  name: {{ template "filebeat.fullname" . }}-prometheus-exporter
{{- if .Values.monitoring.serviceMonitor.namespace }}
  namespace: {{ .Values.monitoring.serviceMonitor.namespace }}
{{- end }}
spec:
  endpoints:
  - targetPort: {{ .Values.monitoring.exporterPort }}
{{- if .Values.monitoring.serviceMonitor.interval }}
    interval: {{ .Values.monitoring.serviceMonitor.interval }}
{{- end }}
{{- if .Values.monitoring.serviceMonitor.telemetryPath }}
    path: {{ .Values.monitoring.serviceMonitor.telemetryPath }}
{{- end }}
  jobLabel: {{ template "filebeat.fullname" . }}-prometheus-exporter
  namespaceSelector:
    matchNames:
    - {{ .Release.Namespace }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ template "filebeat.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}