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

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