apiVersion: operator.victoriametrics.com/v1beta1
kind: VMPodScrape
metadata:
  name: "{{ .Name }}"
  namespace: "{{ .Namespace }}"
  labels:
    scrape-by: "{{ .LabelScrapeBy }}"
    component-level: tidbgroup
spec:
  selector:
    matchLabels:
      app.kubernetes.io/component: tidb
      tags.tidbcloud.com/tidb-group: "{{ .TiDBGroup }}"
  namespaceSelector:
    matchNames:
    - "{{ .Namespace }}"
  podMetricsEndpoints:
  - port: status # tidb container
    scheme: https
    interval: 15s
    tlsConfig:
      insecureSkipVerify: true
      ca:
        secret:
          name: "db-tidb-cluster-secret"
          key: ca.crt
      cert:
        secret:
          name: "db-tidb-cluster-secret"
          key: tls.crt
      keySecret:
        name: "db-tidb-cluster-secret"
        key: tls.key
    relabelConfigs:
    - action: replace
      replacement: "{{ .TenantID }}"
      targetLabel: tenant_id
    - action: replace
      replacement: "{{ .ClusterID }}"
      targetLabel: cluster_id
    - action: replace
      replacement: "{{ .ClusterID }}"
      targetLabel: tidb_cluster_id
    - action: replace
      replacement: "{{ .VMAccountID }}"
      targetLabel: vm_account_id
    - action: replace
      replacement: "{{ .VMProjectID }}"
      targetLabel: vm_project_id
    - action: keep
      regex: "true"
      sourceLabels:
      - __meta_kubernetes_pod_annotation_prometheus_io_scrape
    - action: replace
      regex: (.+)
      sourceLabels:
      - __meta_kubernetes_pod_annotation_prometheus_io_path
      targetLabel: __metrics_path__
    - action: replace
      sourceLabels:
      - __meta_kubernetes_namespace
      targetLabel: namespace
    - action: replace
      sourceLabels:
      - __meta_kubernetes_pod_name
      targetLabel: pod_name
    - action: replace
      sourceLabels:
      - __meta_kubernetes_pod_name
      targetLabel: instance
    - action: replace
      sourceLabels:
      - __meta_kubernetes_pod_label_app_kubernetes_io_component
      targetLabel: component
  - port: metrics # audit container
    scheme: http
    interval: 15s
    tlsConfig:
      insecureSkipVerify: true
    relabelConfigs:
    - action: replace
      replacement: "{{ .TenantID }}"
      targetLabel: tenant_id
    - action: replace
      replacement: "{{ .ClusterID }}"
      targetLabel: cluster_id
    - action: replace
      replacement: "{{ .ClusterID }}"
      targetLabel: tidb_cluster_id
    - action: replace
      replacement: "{{ .VMAccountID }}"
      targetLabel: vm_account_id
    - action: replace
      replacement: "{{ .VMProjectID }}"
      targetLabel: vm_project_id
    - action: keep
      regex: "true"
      sourceLabels:
      - __meta_kubernetes_pod_annotation_prometheus_io_scrape
    - action: replace
      regex: (.+)
      sourceLabels:
      - __meta_kubernetes_pod_annotation_prometheus_io_path
      targetLabel: __metrics_path__
    - action: replace
      sourceLabels:
      - __meta_kubernetes_namespace
      targetLabel: namespace
    - action: replace
      sourceLabels:
      - __meta_kubernetes_pod_name
      targetLabel: pod_name
    - action: replace
      sourceLabels:
      - __meta_kubernetes_pod_name
      targetLabel: instance
    - action: replace
      replacement: tidb-audit
      targetLabel: component
