---
apiVersion: v1
kind: ConfigMap
metadata:
  name: fluent-bit
  namespace: fluent-bit
  labels:
    app: fluent-bit
data:
  fluent-bit.conf: |
    [SERVICE]
        Flush        5
        Daemon       Off
        Log_Level    ${LOG_LEVEL}
        HTTP_Server  On
        HTTP_Listen  0.0.0.0
        HTTP_Port    2020
        Parsers_File parsers.conf
        Parsers_File parsers_custom.conf

    [INPUT]
        Name              tail
        Path              /var/log/containers/*.log
        Multiline.Parser  docker, cri
        Tag               kube.*
        Refresh_Interval  5
        Buffer_Chunk_Size 256k
        Buffer_Max_Size   256k
        Mem_Buf_Limit     128MB
        Skip_Long_Lines   Off
        DB                /tail-db/tail-containers-state.db
        DB.Sync           Normal

    [FILTER]
        Name                kubernetes
        Match               kube.*
        Buffer_Size         256k
        Kube_Tag_Prefix     kube.var.log.containers.
        Kube_URL            https://kubernetes.default.svc:443
        Kube_CA_File        /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
        Kube_Token_File     /var/run/secrets/kubernetes.io/serviceaccount/token
        Merge_Log           On
        Merge_Log_Key       content
        K8S-Logging.Parser  On
        K8S-Logging.Exclude On

    [FILTER]
        Name  modify
        Match *
        Add   cluster fluent-bit-clickhouse

    [OUTPUT]
        Name                  clickhouse
        Match                 *
        Address               clickhouse-clickhouse.clickhouse.svc.cluster.local:9000
        Database              logs
        Username              admin
        Password              admin
        Write_Timeout         20
        Read_Timeout          10
        Async_Insert          true
        Wait_For_Async_Insert true
        Batch_Size            1000
        Flush_Interval        10s
        Force_Number_Fields   content.duration,content.upstream_service_time
        Log_Format            json
        Log_Level             debug

  parsers.conf: |
    [PARSER]
        Name        logfmt
        Format      logfmt
