{{- if .Values.configs.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: {{ include "cortex.configsFullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "cortex.configsLabels" . | nindent 4 }}
    {{- if .Values.configs.serviceMonitor.additionalLabels }}
{{ toYaml .Values.configs.serviceMonitor.additionalLabels | indent 4 }}
    {{- end }}
  {{- if .Values.configs.serviceMonitor.annotations }}
  annotations:
{{ toYaml .Values.configs.serviceMonitor.annotations | indent 4 }}
  {{- end }}
spec:
  selector:
    matchLabels:
      {{- include "cortex.configsSelectorLabels" . | nindent 6 }}
  namespaceSelector:
    matchNames:
      - {{ .Release.Namespace | quote }}
  endpoints:
  - port: http-metrics
    {{- if .Values.configs.serviceMonitor.interval }}
    interval: {{ .Values.configs.serviceMonitor.interval }}
    {{- end }}
    {{- if .Values.configs.serviceMonitor.scrapeTimeout }}
    scrapeTimeout: {{ .Values.configs.serviceMonitor.scrapeTimeout }}
    {{- end }}
    {{- if .Values.configs.serviceMonitor.relabelings }}
    relabelings:
    {{- toYaml .Values.configs.serviceMonitor.relabelings | nindent 4 }}
    {{- end }}
    {{- if .Values.configs.serviceMonitor.metricRelabelings }}
    metricRelabelings:
    {{- toYaml .Values.configs.serviceMonitor.metricRelabelings | nindent 4 }}
    {{- end }}
    {{- with .Values.configs.serviceMonitor.extraEndpointSpec }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
{{- end }}
