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

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