apiVersion: operator.victoriametrics.com/v1beta1
kind: VMPodScrape
metadata:
  name: "{{ .Name }}"
  namespace: "{{ .Namespace }}"
  labels:
    scrape-by: "{{ .LabelScrapeBy }}"
    component-level: tidbgroup
spec:
  selector: {}
  namespaceSelector:
    matchNames:
    - "{{ .Namespace }}"
  podMetricsEndpoints:
  - honorLabels: true
    interval: 15s
    scheme: http
    params:
      collect[]:
      - cpu
    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
    - sourceLabels:
      - __meta_kubernetes_pod_annotation_prometheus_io_scrape
      action: keep
      regex: "true"
    - sourceLabels:
      - __meta_kubernetes_pod_label_app_kubernetes_io_component
      action: keep
      regex: "pd|tikv|tidb|tiflash|worker-tidb|tikv-worker|tiproxy"
    - sourceLabels:
      - __meta_kubernetes_pod_host_ip
      action: replace
      regex: (.+)
      replacement: "$1:9100"
      targetLabel: __address__
    - sourceLabels:
      - __meta_kubernetes_pod_label_app_kubernetes_io_instance
      action: replace
      targetLabel: cluster
    - sourceLabels:
      - __meta_kubernetes_pod_node_name
      action: replace
      targetLabel: instance
    - sourceLabels:
      - __meta_kubernetes_pod_label_app_kubernetes_io_component
      action: replace
      targetLabel: component
    - sourceLabels:
      - component
      regex: "worker-tidb|tikv-worker|pd"
      targetLabel: component_group
      replacement: "worker"
      action: replace
    - sourceLabels:
      - component
      regex: "tidb|tikv|tiproxy|tiflash"
      targetLabel: component_group
      replacement: "core"
      action: replace
    - action: labeldrop
      regex: "component"
    - action: labeldrop
      regex: "container"
    - action: labeldrop
      regex: "pod"
    - sourceLabels:
      - __meta_kubernetes_namespace
      - __meta_kubernetes_pod_label_app_kubernetes_io_instance
      separator: '-'
      targetLabel: tidb_cluster
    metricRelabelConfigs:
    - sourceLabels:
      - __name__
      action: keep
      regex: 'node_cpu_seconds_total'
