apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    release: self-monitoring
  name: self-monitoring-vmstorage
  namespace: {{ .Values.namespace.selfMonitoring }}
spec:
  endpoints:
  -  port: http
     path: /metrics
  namespaceSelector:
    matchNames:
    - "{{ .Release.Namespace }}"
  selector:
    matchLabels:
      app.kubernetes.io/instance: vmcluster
      app.kubernetes.io/name: vmstorage

---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    release: self-monitoring
  name: self-monitoring-vmselect
  namespace: {{ .Values.namespace.selfMonitoring }}
spec:
  endpoints:
  -  port: http
     path: /metrics
  namespaceSelector:
    matchNames:
    - "{{ .Release.Namespace }}"
  selector:
    matchLabels:
      app.kubernetes.io/instance: vmcluster
      app.kubernetes.io/name: vmselect

---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    release: self-monitoring
  name: self-monitoring-vminsert
  namespace: {{ .Values.namespace.selfMonitoring }}
spec:
  endpoints:
  -  port: http
     path: /metrics
  namespaceSelector:
    matchNames:
    - "{{ .Release.Namespace }}"
  selector:
    matchLabels:
      app.kubernetes.io/instance: vmcluster
      app.kubernetes.io/name: vminsert

---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    release: self-monitoring
  name: self-monitoring-regionalserver
  namespace: {{ .Values.namespace.selfMonitoring }}
spec:
  endpoints:
  -  port: metrics
     path: /metrics
  namespaceSelector:
    matchNames:
    - "{{ .Release.Namespace }}"
  selector:
    matchLabels:
      app: regionalservice

---
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
  labels:
    release: self-monitoring
  name: self-monitoring-user-prometheus
  namespace: {{ .Values.namespace.selfMonitoring }}
spec:
  podMetricsEndpoints:
  - port: web
    path: /metrics
    relabelings:
    - action: replace
      sourceLabels:  [__meta_kubernetes_pod_label_observability_pingcap_com_applicationID]
      targetLabel: application
    - action: replace
      sourceLabels:  [__meta_kubernetes_pod_label_observability_pingcap_com_cluster_id]
      targetLabel: cluster
    - action: replace
      sourceLabels:  [__meta_kubernetes_pod_label_observability_pingcap_com_tenantID]
      targetLabel: tenant
  namespaceSelector:
    any: true
  selector:
    matchExpressions:
      - {key: observability.pingcap.com/applicationID, operator: Exists}
      - {key: observability.pingcap.com/tenantID, operator: Exists}
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    release: self-monitoring
  name: self-monitoring-loki
  namespace: {{ .Values.namespace.selfMonitoring }}
spec:
  endpoints:
  - port: http-metrics
  namespaceSelector:
    matchNames:
    - "{{ .Release.Namespace }}"
  selector:
    matchLabels:
      app.kubernetes.io/instance: loki-ha
      app.kubernetes.io/name: loki-ha

---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    release: self-monitoring
  name: vmalert
  namespace: {{ .Values.namespace.selfMonitoring }}
spec:
  endpoints:
  - port: http
  namespaceSelector:
    matchNames:
    - "{{ .Release.Namespace }}"
  selector:
    matchLabels:
      app.kubernetes.io/name: vmalert
      app.kubernetes.io/instance: vmalert-shared
