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

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