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

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