{{- with .Values.dynamicConfig.upload.logging }}
{{- if and .enabled $.Values.dynamicConfig.enabled $.Values.dynamicConfig.upload.enabled }}

---
apiVersion: logging.banzaicloud.io/v1beta1
kind: Flow
metadata:
  name: {{ include "collabora-online.fullname" $ }}-dynconfig-upload
spec:
  match:
    - select:
        labels:
          type: dynconfig
          {{- include "collabora-online.selectorLogLabels" $ | nindent 10 }}
        container_names:
          - "{{ $.Chart.Name }}-dynconfig-upload"

  filters:
    - parser:
        hash_value_field: "simple-upload"
        reserve_data: true
        remove_key_name_field: true
        parse:
          type: "multi_format"
          patterns:
            - format: "regexp"
              # for
              # [::ffff:172.17.87.208] [400] Upload failed with: That request is not supported
              expression: '^\[(?<ip>[a-f0-9\.:]+)\]\s\[(?<statuscode>\d+)\]\s(?<message>.*)'
              types: 'statuscode:integer'
            - format: "none"
    {{- if .ecs }}
    - record_transformer:
        enable_ruby: true
        records:
          - message: '${ record["simple-upload"]["message"] }'
            related.ip: '${ record["simple-upload"]["ip"] }'
            http.response.status_code: '${ record["simple-upload"]["statuscode"] }'
        remove_keys: "$['simple-upload']['message'],$['simple-upload']['ip'],$['simple-upload']['statuscode']"
    {{- end }}
    {{- with .additionalFilters }}
    {{- toYaml . | nindent 4 }}
    {{- end }}

  {{- with .globalOutputRefs }}
  globalOutputRefs:
    {{- toYaml . | nindent 4 }}
  {{- end }}
  {{- with .localOutputRefs }}
  localOutputRefs:
    {{- toYaml . | nindent 4 }}
  {{- end }}

{{- end }}{{/* end-if .enabled ... */}}
{{- end }}{{/* end-with .dynamicConfig.upload.logging */}}
