apiVersion: v1
kind: ConfigMap
metadata:
  name: fluent-bit-config
  namespace: default
  labels:
    k8s-app: fluent-bit
data:
  # Configuration files: server, input, filters and output
  # ======================================================
  fluent-bit-service.conf: |-
    [SERVICE]
        Flush        5
        Daemon       Off
        Log_Level    info
        HTTP_Server  On
        HTTP_Listen  0.0.0.0
        HTTP_PORT    2020
        Parsers_File parsers.conf

  fluent-bit-input.conf: |-
    [INPUT]
        Name             tail
        Path             /var/log/containers/*.log
        Parser           docker
        DB               /var/log/flb_kube.db
        Tag              kube.*
        Refresh_Interval 5
        Mem_Buf_Limit    128MB
        Skip_Long_Lines  On
        Exclude_Path     /var/log/containers/*_game-*.log


  fluent-bit-filter.conf: |-
    [FILTER]
        Name                kubernetes
        Match               kube.*
        Kube_Tag_Prefix     kube.var.log.containers.
        Kube_URL            https://kubernetes.default.svc.cluster.local: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
        K8S-Logging.Parser  On
        K8S-Logging.Exclude Off
        Merge_Log_Key       logfield

    [FILTER]
        Name          parser
        Match         kube.*
        Key_Name      log
        Parser        hazelcast
        Reserve_Data  On

  fluent-bit-output.conf: |-
    [OUTPUT]
        Name            es
        Match           kube.*
        Host            elasticsearch
        Port            9200
        Logstash_Format On
        Retry_Limit     10
        Time_Key        @timestamp
        # Type            _doc
        Replace_Dots    On
        HTTP_User       elastic
        HTTP_Passwd     changeme
        tls             off
        tls.verify      Off
        Logstash_Prefix kubernetes_cluster

  fluent-bit.conf: |-
    @INCLUDE fluent-bit-service.conf
    @INCLUDE fluent-bit-input.conf
    @INCLUDE fluent-bit-filter.conf
    @INCLUDE fluent-bit-output.conf

  parsers.conf: |-
    [PARSER]
        Name   json
        Format json
        Time_Key time
        Time_Format %d/%b/%Y:%H:%M:%S %z

    [PARSER]
        Name        docker
        Format      json
        Time_Key    time
        Time_Format %Y-%m-%dT%H:%M:%S.%L
        Time_Keep   On

    [PARSER]
        Name    hazelcast
        Format  regex
        Regex   ^*HealthMonitor(.)*heap.memory.used\/total=(?<heapPercentageUsed>[\d.]+)%(.)*major.gc.count=(?<majorGcCount>[\d]+),(.)*thread.count=(?<threadCount>[\d]+),(.)*$