{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if and .Values.coordinator.enabled .Values.coordinator.metrics.enabled .Values.coordinator.metrics.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ template "milvus.coordinator.fullname" . }}
  namespace: {{ default (include "common.names.namespace" .) .Values.coordinator.metrics.serviceMonitor.namespace | quote }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.coordinator.metrics.serviceMonitor.labels .Values.commonLabels ) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: milvus
    app.kubernetes.io/component: coordinator
  {{- if or .Values.commonAnnotations .Values.coordinator.metrics.serviceMonitor.annotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.coordinator.metrics.serviceMonitor.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  {{- if .Values.coordinator.metrics.serviceMonitor.jobLabel }}
  jobLabel: {{ .Values.coordinator.metrics.serviceMonitor.jobLabel }}
  {{- end }}
  selector:
    matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 6 }}
      {{- if .Values.coordinator.metrics.serviceMonitor.selector }}
      {{- include "common.tplvalues.render" (dict "value" .Values.coordinator.metrics.serviceMonitor.selector "context" $) | nindent 6 }}
      {{- end }}
      app.kubernetes.io/part-of: milvus
      app.kubernetes.io/component: coordinator
  endpoints:
    - port: http-metrics
      {{- if .Values.coordinator.metrics.serviceMonitor.interval }}
      interval: {{ .Values.coordinator.metrics.serviceMonitor.interval }}
      {{- end }}
      {{- if .Values.coordinator.metrics.serviceMonitor.scrapeTimeout }}
      scrapeTimeout: {{ .Values.coordinator.metrics.serviceMonitor.scrapeTimeout }}
      {{- end }}
      {{- if .Values.coordinator.metrics.serviceMonitor.honorLabels }}
      honorLabels: {{ .Values.coordinator.metrics.serviceMonitor.honorLabels }}
      {{- end }}
      {{- if .Values.coordinator.metrics.serviceMonitor.metricRelabelings }}
      metricRelabelings: {{- toYaml .Values.coordinator.metrics.serviceMonitor.metricRelabelings | nindent 6 }}
      {{- end }}
      {{- if .Values.coordinator.metrics.serviceMonitor.relabelings }}
      relabelings: {{- toYaml .Values.coordinator.metrics.serviceMonitor.relabelings | nindent 6 }}
      {{- end }}
  namespaceSelector:
    matchNames:
      - {{ include "common.names.namespace" . | quote }}
{{- end }}
