{{ if and .Values.prometheus.jmx.enabled .Values.prometheus.operator.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "kafka.fullname" . }}
  namespace: {{ include "serviceMonitor.namespace" . | default .Release.Namespace  }}
  labels:
  {{- include "kafka.monitor.labels" . | nindent 4 }}
  {{- toYaml .Values.prometheus.operator.serviceMonitor.selector | nindent 4 }}
spec:
  selector:
    matchLabels:
    {{- include "kafka.broker.matchLabels" . | nindent 6 }}
  endpoints:
  - port: jmx-exporter
    interval: {{ .Values.prometheus.jmx.interval }}
  {{- if .Values.prometheus.jmx.scrapeTimeout }}
    scrapeTimeout: {{ .Values.prometheus.jmx.scrapeTimeout }}
  {{- end }}
  namespaceSelector:
    matchNames:
      - {{ .Release.Namespace }}
{{ end }}
---
{{ if and .Values.prometheus.kafka.enabled .Values.prometheus.operator.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "kafka.fullname" . }}-exporter
  namespace: {{ include "serviceMonitor.namespace" . }}
  labels:
  {{- include "kafka.monitor.labels" . | nindent 4 }}
  {{ toYaml .Values.prometheus.operator.serviceMonitor.selector | nindent 4 }}
spec:
  selector:
    matchLabels:
    {{- include "kafka.monitor.matchLabels" . | nindent 6 }}
  endpoints:
  - port: kafka-exporter
    interval: {{ .Values.prometheus.kafka.interval }}
  {{- if .Values.prometheus.kafka.scrapeTimeout }}
    scrapeTimeout: {{ .Values.prometheus.kafka.scrapeTimeout }}
  {{- end }}
  namespaceSelector:
    matchNames:
      - {{ .Release.Namespace }}
{{ end }}
