{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }}

{{- if not .Values.cluster.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "milvus.standalone.fullname" . }}
  labels:
{{ include "milvus.labels" . | indent 4 }}
    {{- if .Values.metrics.serviceMonitor.additionalLabels }}
{{ toYaml .Values.metrics.serviceMonitor.additionalLabels | indent 4 }}
    {{- end }}
    component: "standalone"
spec:
  endpoints:
    - honorLabels: true
      interval: {{ .Values.metrics.serviceMonitor.interval }}
      scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }}
      path: /metrics
      port: metrics
  namespaceSelector:
    matchNames:
      - {{ .Release.Namespace }}
  selector:
    matchLabels:
{{ include "milvus.matchLabels" . | indent 6 }}
      component: standalone
  targetLabels:
    - app.kubernetes.io/name
    - app.kubernetes.io/instance
    - component
{{- end }}

---
{{- if .Values.cluster.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "milvus.fullname" . }}
  labels:
{{ include "milvus.labels" . | indent 4 }}
    {{- if .Values.metrics.serviceMonitor.additionalLabels }}
{{ toYaml .Values.metrics.serviceMonitor.additionalLabels | indent 4 }}
    {{- end }}
spec:
  endpoints:
    - honorLabels: true
      interval: {{ .Values.metrics.serviceMonitor.interval }}
      scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }}
      path: /metrics
      port: metrics
  namespaceSelector:
    matchNames:
      - {{ .Release.Namespace }}
  selector:
    matchLabels:
{{ include "milvus.matchLabels" . | indent 6 }}
  targetLabels:
    - app.kubernetes.io/name
    - app.kubernetes.io/instance
    - component
{{- end }}
{{- end }}
