custom log format

intro

as an example, here we are adding the compression field to the log format

ingress tweak

    vi ~/ingress-nginx-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: ingress-nginx-controller
  namespace: ingress-nginx
data:
  log-format-upstream: '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$proxy_upstream_name] [$proxy_alternative_upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status $req_id "$gzip_ratio"'
  http-snippet: |
    gzip              on;
    gzip_comp_level   4;
    gzip_proxied      any;
    gzip_types        text/html text/plain text/css text/xml text/javascript application/javascript application/json;

apply

    kubectl apply -f ~/ingress-nginx-cm.yaml
    kubectl get cm -n ingress-nginx

more options

gzip_buffers        4 8k;
gzip_disable        "msie6";
gzip_http_version   1.1;
gzip_min_length     1000;
gzip_proxied        any;
gzip_types          ...
gzip_vary           on;

that seems to break gzip

    #enable-brotli: "true"

fluent-bit tweak

   [FILTER]
        name parser
        match kube.*
        #key_name log
        key_name message
        parser ingress-gzip

    [PARSER]
        Name        ingress-gzip
        Format      regex
        Regex       ^(?<host>[^ ]*) - (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*) "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" (?<request_length>[^ ]*) (?<request_time>[^ ]*) \[(?<proxy_upstream_name>[^ ]*)\] (\[(?<proxy_alternative_upstream_name>[^ ]*)\] )?(?<upstream_addr>[^ ]*) (?<upstream_response_length>[^ ]*) (?<upstream_response_time>[^ ]*) (?<upstream_status>[^ ]*) (?<reg_id>[^ ]*) "(?<gzip>[^\"]*)".*$
        Time_Key    time
        Time_Format %d/%b/%Y:%H:%M:%S %z

resources

nginx

https://nginx.org/en/docs/http/ngx_http_gzip_module.html

https://stackoverflow.com/questions/15999606/enable-gzip-compression-with-nginx

https://stackoverflow.com/questions/35707812/nginx-gzip-compression-not-working

ingress

https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/

https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#gzip-level

https://stackoverflow.com/questions/52782415/nginx-ingress-config-map-snippets-being-ignored-by-the-nginx-conf

gzip

https://serverfault.com/questions/253074/what-is-the-best-nginx-compression-gzip-level

https://superuser.com/questions/269936/how-do-i-know-the-gzip-compression-level

flb

https://docs.fluentbit.io/manual/pipeline/filters/parser

https://github.com/fluent/fluent-bit/blob/master/conf/parsers.conf


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun