apiVersion: operator.victoriametrics.com/v1beta1
kind: VMPodScrape
metadata:
  name: "{{ .Name }}"
  namespace: "{{ .Namespace }}"
  labels:
    scrape-by: "{{ .LabelScrapeBy }}"
    keyspace-name: "{{ .ClusterID }}"
    vm-account-id: "{{ .VMAccountID }}"
    vm-project-id: "{{ .VMProjectID }}"
spec:
  selector:
    matchLabels:
      app.kubernetes.io/component: tidb
      tags.tidbcloud.com/tidb-group: "{{ .TiDBGroup }}"
  namespaceSelector:
    matchNames:
    - "{{ .Namespace }}"
  podMetricsEndpoints:
  - interval: 15s
    scheme: https
    port: status
    tlsConfig:
      insecureSkipVerify: true
      ca:
        secret:
          name: "{{ .TLSSecretName }}"
          key: ca.crt
      cert:
        secret:
          name: "{{ .TLSSecretName }}"
          key: tls.crt
      keySecret:
        name: "{{ .TLSSecretName }}"
        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
