# helm upgrade --kube-context shoot--staging--625003c8 -n tidb1373933076658061430 -i -f ./examples/dedicated-shoot-log-daemonset.yaml vector-cluster-log ./

# env -- Set environment variables in Vector containers
## The examples below leverage examples from secrets.generic and assume no name overrides with a Release name of "vector"
env:
  - name: TENANT_ID
    value: "1369847559691427383"
  - name: PROJECT_ID
    value: "1369847559691427496"
  - name: CLUSTER_ID
    value: "1373933076658061430"
  # For debug usage
#  - name: VECTOR_LOG
#    value: aws_smithy_http=debug,vector=debug

# customConfig -- Override Vector's default configs, if used **all** options need to be specified
## This section supports using helm templates to populate dynamic values
## Ref: https://vector.dev/docs/reference/configuration/
customConfig:
  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
      region: us-west-2
      bucket: centralized-storage-dev-shared-aws-us-west-2
      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
        assume_role: arn:aws:iam::552185537300:role/observability-agent-writer

    s3_tidb_cluster_logs:
      type: aws_s3
      inputs:
        - route_logs.tidb_cluster_general_logs
        - multiline_slow_logs
      region: us-west-2
      bucket: centralized-storage-dev-shared-aws-us-west-2
      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
        assume_role: arn:aws:iam::552185537300:role/observability-agent-writer

    s3_unmatched_kubernetes_logs:
      type: aws_s3
      inputs:
        - route_logs._unmatched
      region: us-west-2
      bucket: centralized-storage-dev-shared-aws-us-west-2
      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
        assume_role: arn:aws:iam::552185537300:role/observability-agent-writer

    s3_journald_logs:
      type: aws_s3
      inputs:
        - journald
      region: us-west-2
      bucket: centralized-storage-dev-shared-aws-us-west-2
      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
        assume_role: arn:aws:iam::552185537300:role/observability-agent-writer

#    # Only for debug
#    debug_blackhole:
#      type: blackhole
#      inputs:
#        - route_logs.tidb_cluster_slow_logs
#        - multiline_slow_logs

# resources -- Set Vector resource requests and limits.
resources:
  requests:
    cpu: "50m"
    memory: "100Mi"
  limits:
    cpu: "500m"
    memory: "1000Mi"

role: "Agent"

## Configuration for Vector's data persistence
## Persistence always used for Agent role
persistence:
  hostPath:
    # persistence.hostPath.path -- Override path used for hostPath persistence
    ## Valid for Agent role
    path: "/var/lib/vector/01"

# Mount machine id to fix journalctl. Refer to https://github.com/vectordotdev/vector/issues/5225
# extraVolumes -- Additional Volumes to use with Vector Pods
extraVolumes:
  - name: machine-id
    hostPath:
      path: /etc/machine-id
      type: File

# extraVolumeMounts -- Additional Volume to mount into Vector Containers
extraVolumeMounts:
  - name: machine-id
    mountPath: /etc/machine-id
    readOnly: true

# rollWorkload -- Add a checksum of the generated ConfigMap to workload annotations
rollWorkload: true

## Define the Vector image to use
image:
  # image.repository -- Override default registry + name for Vector
  repository: timberio/vector
  # image.pullPolicy -- Vector image pullPolicy
  pullPolicy: IfNotPresent
  tag: 0.22.X-debian

## Configure a HorizontalPodAutoscaler for Vector
## Valid for Aggregator and Stateless-Aggregator roles
autoscaling:
  # autoscaling.enabled -- Enabled autoscaling for the Aggregator and Stateless-Aggregator
  enabled: false
  # autoscaling.minReplicas -- Minimum replicas for Vector's HPA

podDisruptionBudget:
  # podDisruptionBudget.enabled -- Enable a PodDisruptionBudget for Vector
  enabled: false

rbac:
  # rbac.create -- If true, create and use RBAC resources. Only valid for the Agent role
  create: true

psp:
  # psp.create -- If true, create a PodSecurityPolicy resource. PodSecurityPolicy is deprecated as of Kubernetes v1.21, and will be removed in v1.25
  ## Intended for use with the Agent role
  create: false

serviceAccount:
  # serviceAccount.create -- If true, create ServiceAccount
  create: true
  # serviceAccount.automountToken -- Automount API credentials for the Vector ServiceAccount
  automountToken: true

# tolerations -- Allow Vector to schedule on tainted nodes
tolerations:
  - operator: Exists

## Configuration for Vector's Service
service:
  # service.enabled -- If true, create and use a Service resource
  enabled: false

## Configuration for Vector's Ingress
ingress:
  # ingress.enabled -- If true, create and use an Ingress resource
  enabled: false

# livenessProbe -- Override default liveness probe settings, if customConfig is used requires customConfig.api.enabled true
## Requires Vector's API to be enabled
livenessProbe:
  httpGet:
    path: /health
    port: api

# readinessProbe -- Override default readiness probe settings, if customConfig is used requires customConfig.api.enabled true
## Requires Vector's API to be enabled
readinessProbe:
  httpGet:
    path: /health
    port: api

## Configure a PodMonitor for Vector
## Requires the PodMonitor CRD to be installed
podMonitor:
  # podMonitor.enabled -- If true, create a PodMonitor for Vector
  enabled: false

## Optional built-in HAProxy load balancer
haproxy:
  # haproxy.enabled -- If true, create a HAProxy load balancer
  enabled: false
