{{ if and (or .Values.prometheus.exporter.enabled .Values.rabbitmqPrometheusPlugin.enabled) .Values.prometheus.operator.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "rabbitmq-ha.fullname" . }}
  namespace: {{ .Values.prometheus.operator.serviceMonitor.namespace }}
  labels:
{{- if .Values.prometheus.operator.serviceMonitor.selector }}
{{ toYaml .Values.prometheus.operator.serviceMonitor.selector | indent 4 }}
{{- end }}
spec:
  selector:
    matchLabels:
      app: {{ template "rabbitmq-ha.name" . }}
      release: {{ .Release.Name }}
  endpoints:
  - interval: {{ .Values.prometheus.operator.serviceMonitor.interval }}
  {{- if .Values.prometheus.operator.serviceMonitor.scrapeTimeout }}
    scrapeTimeout: {{ .Values.prometheus.operator.serviceMonitor.scrapeTimeout }}
  {{- end }}
  {{- if .Values.rabbitmqPrometheusPlugin.enabled }}
    port: metrics
    path: {{ .Values.rabbitmqPrometheusPlugin.path }}
  {{- else }}
    port: exporter
  {{- end }}
  namespaceSelector:
    any: true
{{- end }}
