{{- if .Values.serviceMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ printf "%s-federation-service-monitor" .Release.Namespace | quote }}
  namespace: "jfrog-saas-{{ .Values.serviceMonitor.region }}-kube-prom"
  labels:
    {{- include "common.labels.standard" . | nindent 4 }}
    app: {{ .Values.serviceMonitor.kubePromApp }}
    release: jfrog-saas-{{ .Values.serviceMonitor.region }}-kube-prom
  {{- if .Values.commonAnnotations }} # TODO [elads] - can discard this?
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}

spec:
  endpoints:
    - path: /rtfs/api/v1/metrics
      {{- if .Values.serviceMonitor.bearerTokenFile }}
      bearerTokenFile: {{ .Values.serviceMonitor.bearerTokenFile }}
      {{- else }}
      bearerTokenSecret:
        key: token
        name: {{ .Values.serviceMonitor.tokenName }}
      {{- end }}
      honorLabels: true
      interval: {{ .Values.serviceMonitor.interval }}
      scheme: http
      scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
      targetPort: 8082
      tlsConfig:
        insecureSkipVerify: true
  jobLabel: {{ .Values.serviceMonitor.jobLabel }}
  additionalLabels: # TODO [elads] - can discard this? since have metadata.labels.release already ?
    release: jfrog-saas-{{ .Values.serviceMonitor.region }}-kube-prom
  namespaceSelector:
    any: false
    matchNames:
    - {{ .Release.Namespace | quote }}
  selector:
    matchLabels:
      app.kubernetes.io/name: artifactory-federation # federation-be ?
{{- end }}