role: Aggregator
image:
  repository: "{{ .ImageRepo }}"
  tag: "{{ .ImageTag }}"
replicas: {{ .Replicas }}
resources: {{ .Resources }}
podPriorityClassName: "{{ .PriorityClassName }}"
podLabels:
  vector.dev/exclude: "false"
  app: tidb-vector
dnsPolicy: ClusterFirstWithHostNet
podHostNetwork: true
nodeSelector:
  o11y.tidbcloud.com/component: o11y
  o11y.tidbcloud.com/cluster: "{{ .ClusterID }}"
tolerations:
- key: o11y-dedicated
  operator: Equal
  value: o11y
  effect: NoExecute
- key: o11y-cluster
  operator: Equal
  value: "{{ .ClusterID }}"
  effect: NoExecute
service:
  enabled: false
persistence:
  enabled: true
  size: 20Gi
  storageClassName: o11y-metric-agent
  hostPath:
    enabled: false
containerPorts:
  - name: prom-exporter
    containerPort: 9699
    protocol: TCP
  - name: api
    containerPort: 8687
    protocol: TCP
readinessProbe:
  httpGet:
    path: /health
    port: api
  timeoutSeconds: 10
livenessProbe:
  httpGet:
    path: /health
    port: api
  initialDelaySeconds: 30
  periodSeconds: 30
  failureThreshold: 10
  timeoutSeconds: 10
extraVolumes:
- name: cluster-tls
  secret:
    secretName: db-cluster-client-secret
extraVolumeMounts:
- name: cluster-tls
  mountPath: /var/lib/cluster-assets-tls
  readOnly: true
affinity:
  podAntiAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
            - key: app
              operator: In
              values:
                - tidb-vector
        topologyKey: kubernetes.io/hostname
dataDir: /vector-data-dir
customConfig:
  data_dir: /vector-data-dir
  api:
    enabled: true
    address: 0.0.0.0:8687
    playground: false
  sources:
    internal_metrics:
      type: internal_metrics
    topsql:
      type: topsql
      pd_address: db-pd:2379
      tls:
        ca_path: "/var/lib/cluster-assets-tls/ca.crt"
        crt_path: "/var/lib/cluster-assets-tls/tls.crt"
        key_path: "/var/lib/cluster-assets-tls/tls.key"
      top_n: 10
    topsql_v2:
      type: "topsql_v2"
      downsampling_interval: 60
      keep_top_n: 100
      pd_address: db-pd:2379
      tls:
        ca_path: /var/lib/cluster-assets-tls/ca.crt
        crt_path: /var/lib/cluster-assets-tls/tls.crt
        key_path: /var/lib/cluster-assets-tls/tls.key
    conprof:
      type: conprof
      pd_address: db-pd:2379
      topology_mode: k8s
      topology_fetch_interval_seconds: 60
      jeprof_fetch_mode: rust
      topology_k8s:
        component_label_key: "app.kubernetes.io/component"
        component_label_to_instance_type:
          tiproxy: tiproxy
          tidb: tidb
          pd: pd
          tikv: tikv
          tiflash: tiflash
      tls:
        ca_path: "/var/lib/cluster-assets-tls/ca.crt"
        crt_path: "/var/lib/cluster-assets-tls/tls.crt"
        key_path: "/var/lib/cluster-assets-tls/tls.key"
      components_profile_types:
        pd:
          cpu: true
          heap: true
          mutex: true
          goroutine: true
        tidb:
          cpu: true
          heap: true
          mutex: true
          goroutine: true
        tikv:
          cpu: false
          heap: false
          jeheap: true
          mutex: false
          goroutine: false
        tiflash:
          cpu: false
          heap: false
          mutex: false
          goroutine: false
        tiproxy:
          cpu: true
          heap: true
          mutex: true
          goroutine: true
        lightning:
          cpu: true
          heap: true
          mutex: true
          goroutine: true
    keyviz:
      type: keyviz
      pd_address: db-pd:2379
      tls:
        ca_path: "/var/lib/cluster-assets-tls/ca.crt"
        crt_path: "/var/lib/cluster-assets-tls/tls.crt"
        key_path: "/var/lib/cluster-assets-tls/tls.key"
      max_requests_per_round: 1
  transforms:
    topsql_add_meta:
      type: remap
      inputs: ["topsql"]
      source: |
        .labels.provider = "{{ .Vendor }}"
        .labels.region = "{{ .Region }}"
        .labels.k8s_cluster_name = "{{ .ClusterName }}"
        .labels.k8s_namespace = "tidb{{ .ClusterID }}"
        .labels.project_id = "{{ .ProjectID }}"
        .labels.tenant_id = "{{ .TenantID }}"
        .labels.cluster_id = "{{ .ClusterID }}"
    route_by_type:
      type: "route"
      inputs:
        - "topsql_v2"
      route:
        non_meta_logs: '.source_table == "tidb_topsql" || .source_table == "tikv_topsql" || .source_table == "tikv_topregion"'
        meta_logs: '.source_table == "topsql_sql_meta" || .source_table == "topsql_plan_meta"'
    conprof_add_meta:
      type: remap
      inputs: ["conprof"]
      source: |
        .key_prefix = join!(["0", "{{ .TenantID }}", "{{ .ProjectID }}", "{{ .ClusterID }}", "profiles", .filename], separator: "/")
    keyviz_add_meta:
      type: remap
      inputs: ["keyviz"]
      source: |
        .key_prefix = join!(["0", "{{ .TenantID }}", "{{ .ProjectID }}", "{{ .ClusterID }}", "regions", .filename], separator: "/")
  sinks:
    internal_metrics_exporter:
      type: prometheus_exporter
      inputs: ["internal_metrics"]
      address: "0.0.0.0:9699"
    topsql_vm:
      type: vm_import
      inputs: ["topsql_add_meta"]
      endpoint: "{{ .VMImportURL }}"
      batch:
        max_events: 1000
        max_bytes: 1048576 # 1MiB
        timeout_secs: 1
      buffer:
        type: disk
        max_size: 536870912 # 512MiB
        when_full: drop_newest
    deltalake_local:
      auth:
        assume_role: "{{ .RoleARN }}"
      type: "topsql_data_deltalake"
      inputs:
        - "route_by_type.non_meta_logs"
      base_path: "s3://{{ .Bucket }}/deltalake/org={{ .TenantID }}/cluster={{ .ClusterID }}/type=topsql"
      bucket: "{{ .Bucket }}"
      region: "{{ .Region }}"
      batch_size: 262144
      max_delay_secs: 300
      timeout_secs: 30
      acknowledgements:
        enabled: true
    deltalake_local_meta:
      auth:
        assume_role: "{{ .RoleARN }}"
      type: "topsql_meta_deltalake"
      inputs:
        - "route_by_type.meta_logs"
      base_path: "s3://{{ .Bucket }}/deltalake/org={{ .TenantID }}/cluster={{ .ClusterID }}/type=topsql"
      bucket: "{{ .Bucket }}"
      region: "{{ .Region }}"
      batch_size: 65536
      max_delay_secs: 120
      meta_cache_capacity: 1000000
      timeout_secs: 30
      acknowledgements:
        enabled: true
    conprof_s3:
      type: aws_s3
      inputs: ["conprof_add_meta"]
      encoding:
        codec: raw_message
      region: "{{ .Region }}"
      bucket: "{{ .Bucket }}"
      key_prefix: {{ "'{{ `{{ key_prefix }}` }}'" }}
      filename_time_format: ""
      filename_append_uuid: false
      batch:
        max_bytes: 1 # DO NOT BATCH
        max_events: 1
        timeout_secs: 1
      auth:
        assume_role: "{{ .RoleARN }}"
    keyviz_s3:
      type: aws_s3
      inputs: ["keyviz_add_meta"]
      encoding:
        codec: raw_message
      region: "{{ .Region }}"
      bucket: "{{ .Bucket }}"
      key_prefix: {{ "'{{ `{{ key_prefix }}` }}'" }}
      filename_time_format: ""
      filename_append_uuid: false
      batch:
        max_bytes: 1 # DO NOT BATCH
        max_events: 1
        timeout_secs: 1
      auth:
        assume_role: "{{ .RoleARN }}"
