apiVersion: v1
kind: ConfigMap
metadata:
  name: agent-config-template
  namespace: observability
data:
  default-template: |
    name: test-template
    agentConfigs:
        - category: logs
          content: |
            data_dir: /vector-data-dir
              api:
                enabled: true
                address: 0.0.0.0:8686
                playground: false
              sources:
                all_logs:
                  type: kubernetes_logs
                internal_metrics:
                  type: internal_metrics
                journald:
                  type: journald

              transforms:
                route_logs:
                  type: route
                  inputs:
                    - all_logs
                  route:
                    tidb_cluster_general_logs: .kubernetes.pod_labels."app.kubernetes.io/managed-by" == "tidb-operator" && .kubernetes.container_name != "slowlog"
                    tidb_cluster_slow_logs: .kubernetes.pod_labels."app.kubernetes.io/managed-by" == "tidb-operator" && .kubernetes.container_name == "slowlog"
                    infra_logs: .kubernetes.pod_labels."app.kubernetes.io/managed-by" != "tidb-operator"

                multiline_slow_logs:
                  type: reduce
                  inputs:
                    - route_logs.tidb_cluster_slow_logs
                  starts_when:
                    type: vrl
                    source: |-
                      res, err = starts_with(.message, "# Time: ")
                      if err != null {
                        false
                      } else {
                        res
                      }
                  merge_strategies:
                    message: concat_newline

              sinks:
                s3_infra_logs:
                  type: aws_s3
                  inputs:
                    - route_logs.infra_logs
                  key_prefix: |-
                    tenant=${TENANT_ID}/project=${PROJECT_ID}/cluster=${CLUSTER_ID}/logs/infra_logs/node={{ `{{ kubernetes.pod_node_name }}` }}/namespace={{ `{{ kubernetes.pod_namespace }}` }}/pod={{ `{{ kubernetes.pod_name }}` }}/container={{ `{{ kubernetes.container_name }}` }}/
                  compression: none
                  batch:
                    max_bytes: 104857600 # 100MB
                    timeout_secs: 180 # 3 minutes
                  buffer:
                    type: disk
                    max_size: 1073741824 # 1GB
                  encoding:
                    codec: json
                  auth:
                    # hostNetwork must be enabled

                s3_tidb_cluster_logs:
                  type: aws_s3
                  inputs:
                    - route_logs.tidb_cluster_general_logs
                    - multiline_slow_logs
                  key_prefix: |-
                    tenant=${TENANT_ID}/project=${PROJECT_ID}/cluster=${CLUSTER_ID}/logs/tidb_cluster_logs/node={{ `{{ kubernetes.pod_node_name }}` }}/namespace={{ `{{ kubernetes.pod_namespace }}` }}/pod={{ `{{ kubernetes.pod_name }}` }}/container={{ `{{ kubernetes.container_name }}` }}/
                  compression: none
                  batch:
                    max_bytes: 104857600 # 100MB
                    timeout_secs: 180 # 3 minutes
                  buffer:
                    type: disk
                    max_size: 1073741824 # 1GB
                  encoding:
                    codec: json
                  auth:
                    # hostNetwork must be enabled

                s3_unmatched_kubernetes_logs:
                  type: aws_s3
                  inputs:
                    - route_logs._unmatched
                  key_prefix: |-
                    tenant=${TENANT_ID}/project=${PROJECT_ID}/cluster=${CLUSTER_ID}/logs/_unmatched_logs/
                  compression: none
                  batch:
                    max_bytes: 104857600 # 100MB
                    timeout_secs: 180 # 3 minutes
                  buffer:
                    type: disk
                    max_size: 1073741824 # 1GB
                  encoding:
                    codec: json
                  auth:
                    # hostNetwork must be enabled

                s3_journald_logs:
                  type: aws_s3
                  inputs:
                    - journald
                  key_prefix: |-
                    tenant=${TENANT_ID}/project=${PROJECT_ID}/cluster=${CLUSTER_ID}/logs/journald_logs/node={{ `{{ host }}` }}/
                  compression: none
                  batch:
                    max_bytes: 104857600 # 100MB
                    timeout_secs: 180 # 3 minutes
                  buffer:
                    type: disk
                    max_size: 1073741824 # 1GB
                  encoding:
                    codec: json
                  auth:
                    # hostNetwork must be enabled
        - category: metrics
          content: |
            data_dir: /vector-data-dir
              api:
                enabled: true
                address: 0.0.0.0:8686
                playground: false
              sources:
                tidb_metrics:
                  type: prometheus_remote_write
                  address: 0.0.0.0:9090
                internal_metrics:
                  type: internal_metrics
              sinks:
                remote_prometheus:
                  type: prometheus_remote_write
                  inputs:
                    - tidb_metrics
                  endpoint: http://vpce-006c5529a08d69fb2-i9x0ubnf.vpce-svc-0a44b494234617d54.us-west-2.vpce.amazonaws.com:9090/api/v1/write
                  buffer:
                    type: disk
                    max_size: 2000000000 # 2GB
                  request:
                    retry_attempts: 10
        - category: profiling
          content: content
        - category: trace
          content: content
    isDefault: true
