apiVersion: operator.victoriametrics.com/v1beta1
kind: VMPodScrape
metadata:
  name: "db-{{ .InstanceID }}-tikv"
  namespace: "{{ .Namespace }}"
  labels:
    scrape-by: "{{ .LabelScrapeBy }}"
    db-instance-id: "{{ .InstanceID }}"
    component-level: sharedpool
spec:
  selector:
    matchLabels:
      app.kubernetes.io/component: tikv
      app.kubernetes.io/instance: "db-{{ .InstanceID }}"
  namespaceSelector:
    matchNames:
    - "{{ .Namespace }}"
  podMetricsEndpoints:
  - port: status
    scheme: https
    interval: 15s
    tlsConfig:
      insecureSkipVerify: true
      ca:
        secret:
          name: "db-cluster-client-secret"
          key: ca.crt
      cert:
        secret:
          name: "db-cluster-client-secret"
          key: tls.crt
      keySecret:
        name: "db-cluster-client-secret"
        key: tls.key
    relabelConfigs:
    - action: replace
      replacement: "{{ .SharedPoolID }}"
      targetLabel: sharedpool_id
    - action: replace
      replacement: "{{ .SharedPoolID }}"
      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
    metricRelabelConfigs:
    - action: drop
      if: 'tikv_status_server_request_duration_seconds_bucket{path=~"/dfs/[0-9]+$"}'
    - action: drop
      if: 'tikv_status_server_request_duration_seconds_sum{path=~"/dfs/[0-9]+$"}'
    - action: drop
      if: 'tikv_status_server_request_duration_seconds_count{path=~"/dfs/[0-9]+$"}'
