apiVersion: v1
kind: ConfigMap
metadata:
  name: fluentd-config
  namespace: the-order
data:
  fluent.conf: |
    <source>
      @type tail
      path /var/log/containers/*.log
      pos_file /var/log/fluentd-containers.log.pos
      tag kubernetes.*
      read_from_head true
      <parse>
        @type json
        time_key time
        time_format %Y-%m-%dT%H:%M:%S.%NZ
        keep_time_key true
      </parse>
    </source>

    <filter kubernetes.**>
      @type kubernetes_metadata
    </filter>

    <filter kubernetes.**>
      @type record_transformer
      <record>
        cluster_name the-order
        environment ${ENVIRONMENT:-production}
      </record>
    </filter>

    <match kubernetes.**>
      @type opensearch
      host opensearch.logging.svc.cluster.local
      port 9200
      index_name the-order-logs
      type_name _doc
      logstash_format true
      logstash_prefix the-order
      logstash_dateformat %Y.%m.%d
      include_tag_key true
      tag_key @log_name
      flush_interval 10s
      <buffer>
        @type file
        path /var/log/fluentd-buffers/kubernetes.system.buffer
        flush_mode interval
        retry_type exponential_backoff
        flush_thread_count 2
        flush_interval 5s
        retry_max_interval 30
        retry_timeout 60m
        chunk_limit_size 2M
        queue_limit_length 8
        overflow_action block
      </buffer>
    </match>

