apiVersion: logging.banzaicloud.io/v1beta1
kind: Logging
metadata:
  name: gateway-logging
  namespace: logging
spec:
  enableRecreateWorkloadOnImmutableFieldChange: true
  errorOutputRef: error-file
  fluentd:
    fluentLogDestination: stdout
    bufferStorageVolume:
      pvc:
        spec:
          accessModes:
            - ReadWriteOnce
          resources:
            requests:
              storage: 40Gi
          storageClassName: gp2
          volumeMode: Filesystem  
    fluentOutLogrotate:
      enabled: true
      path: /fluentd/log/out
      age: "15"
    security:
      securityContext:
        runAsNonRoot: false
        runAsGroup: 0
        runAsUser: 0      
    scaling:
      drain:
        enabled: true
    metrics:
      serviceMonitor: true 
    logLevel: debug

  controlNamespace: logging
  watchNamespaces: ["zoomiq"]

---
apiVersion: logging.banzaicloud.io/v1beta1
kind: FluentbitAgent
metadata:
  # Use the name of the logging resource
  name: gateway-logging
  namespace: logging
spec:
  logLevel: debug
  # customParsers: |
  #   [PARSER]
  #       Name    timestampparser
  #       Format    json
  #       Time_Key    asctime
  #       Time_Format    %Y-%m-%d %H:%M:%S.%L
  #       Time_Keep    true    
  customConfigSecret: fluentbit-config
  # inputTail:
  #   Path: "/var/log/containers/*/*/*.log"
  #   Refresh_Interval: "10"
  #   Skip_Long_Lines: "true"
  #   Mem_Buf_Limit: "5MB"
  #   Parser: "timestampparser"
  #   Tag: "kube.*"
  # filterModify:
  #   - rules:
  #     - Remove:
  #         key: threadName
  #     - Remove:
  #         key: processName
    # - conditions:
    #   - Key_value_matches:
    #       key: Match
    #       value: "kube.var.log.containers.*"

---
apiVersion: logging.banzaicloud.io/v1beta1
kind: Flow
metadata:
  name: gateway-flow
  namespace: zoomiq
spec:
  filters:
    - stdout: {}
    - prometheus:
       metrics:
       - name: gateway_topic_request_count
         desc: The total number of pending requests in the gateway topic.
         type: gauge
         key: pending_count
       labels:
         host: ${hostname}
  match:
    - select: {}
  localOutputRefs:
   - file
# ---
# apiVersion: logging.banzaicloud.io/v1beta1
# kind: Output
# metadata:
#   name: null-output
#   namespace: zoomiq  
# spec:
#   nullout: {}
---
apiVersion: logging.banzaicloud.io/v1beta1
kind: ClusterOutput
metadata:
  name: error-file
  namespace: logging
spec:
  file:
    path: /buffers/${tag}/error.log
---
apiVersion: logging.banzaicloud.io/v1beta1
kind: ClusterOutput
metadata:
  name: file
spec:
  file:
    path: /buffers/logs/%Y/%m/%d/${tag}
    append: true
    format:
      type: single_value
      message_key: log
      add_newline: false
    buffer:
      timekey: 1d
      timekey_wait: 5m
      flush_mode: interval
      flush_interval: 15s
      timekey_zone: "+0800"
# ---
# apiVersion: logging.banzaicloud.io/v1beta1
# kind: ClusterOutput
# metadata:
#   name: output-file
#   namespace: logging
# spec:
#   file:
#     path: /fluentd/log/${tag}/output
#     append: true