Skip to content

NGF does not separate log format for multiple gateways? #3566

Closed
@hongyecc

Description

@hongyecc

Describe the bug
I am testing to separate traffics and logs for my applications. seems this is not working. I am using version 2.0.1.
My configuration: 3 apps in 2 namespaces and each app has its own gateway and log formatting configure

I was expecting to see only one formatting snipptsfilter be pushed to one gateway pod, but I am seeing following on app1 gateway: (similar on app2 and app3 gateway pods)

include /etc/nginx/includes/SnippetsFilter_http_app2_app2-http-logging.conf;
include /etc/nginx/includes/SnippetsFilter_http_app2_app3-http-logging.conf;
include /etc/nginx/includes/SnippetsFilter_http_app1_app1-http-logging.conf;

nginx will complain if the log_format is using same name, With different names, the incoming request is logged 3 times

To Reproduce
Steps to reproduce the behavior:

  1. snippets deployments: (I used same configure to run test, they can be different)
    `- apiVersion: gateway.nginx.org/v1alpha1
    kind: SnippetsFilter
    metadata:
    name: app1-http-logging
    namespace: app1
    spec:
    snippets:
    • context: http
      value: |
      log_format json_combined escape=json '{'
      ""time": "$time_iso8601","
      ""time_local": "$time_local","
      ""x-forward-for": "$proxy_add_x_forwarded_for","
      ""server_addr": "$server_addr","
      ""server_name": "$server_name","
      ""TraceID": "$http_x_b3_traceid""
      '}';
      access_log /dev/stdout json_combined;
  • apiVersion: gateway.nginx.org/v1alpha1
    kind: SnippetsFilter
    metadata:
    name: app2-http-logging
    namespace: app2
    spec:
    snippets:

    • context: http
      value: |
      log_format json_combined escape=json '{'
      ""time": "$time_iso8601","
      ""time_local": "$time_local","
      ""x-forward-for": "$proxy_add_x_forwarded_for","
      ""server_addr": "$server_addr","
      ""server_name": "$server_name","
      ""TraceID": "$http_x_b3_traceid""
      '}';
      access_log /dev/stdout json_combined;
  • apiVersion: gateway.nginx.org/v1alpha1
    kind: SnippetsFilter
    metadata:
    generation: 1
    name: app3-http-logging
    namespace: app2
    spec:
    snippets:

    • context: http
      value: |
      log_format json_combined escape=json '{'
      ""time": "$time_iso8601","
      ""time_local": "$time_local","
      ""x-forward-for": "$proxy_add_x_forwarded_for","
      ""server_addr": "$server_addr","
      ""server_name": "$server_name","
      ""TraceID": "$http_x_b3_traceid""
      '}';
      access_log /dev/stdout json_combined;`
  1. View logs on 'controller pod'
{"level":"error","ts":"2025-06-30T14:26:21Z","logger":"eventHandler","msg":"Failed to update NGINX configuration","error":"msg: Config apply failed, rolling back config; error: failed validating config NGINX config test failed exit status 1: 2025/06/30 14:26:21 [emerg] 103640#103640: duplicate \"log_format\" name \"json_combined\" in /etc/nginx/includes/SnippetsFilter_http_app1_app1-http-logging.conf:37\nnginx: [emerg] duplicate \"log_format\" name \"json_combined\" in /etc/nginx/includes/SnippetsFilter_http_app1_app1-http-logging.conf:37\nnginx: configuration file /etc/nginx/nginx.conf test failed\n","stacktrace":"github.com/nginx/nginx-gateway-fabric/internal/controller.(*eventHandlerImpl).waitForStatusUpdates\n\t/home/runner/work/nginx-gateway-fabric/nginx-gateway-fabric/internal/controller/handler.go:262"}

If I give "log_format" different names, controller pod is not complaining any more and configure was reloaded successfully but request is logged 3 times

  1. See errorExpected behavior
    A clear and concise description of what you expected to happen.

What am expecting is only log_format configuration intended to the application (by name and name space) is pushed to the gateway pod. So with my configuration, only following should be pushed to app1 gateway pod:

include /etc/nginx/includes/SnippetsFilter_http_app1_app1-http-logging.conf;

Your environment

  • Version of the NGINX Gateway Fabric - release version or a specific commit. The first line of the nginx-gateway container logs includes the commit info.

NAMESPACE: nginx-gateway
STATUS: deployed
REVISION: 7
CHART: nginx-gateway-fabric
VERSION: 2.0.1
APP_VERSION: 2.0.1

  • Version of Kubernetes
  • Kubernetes platform (e.g. Mini-kube or GCP)
  • Details on how you expose the NGINX Gateway Fabric Pod (e.g. Service of type LoadBalancer or port-forward)
  • Logs of NGINX container: kubectl -n <nginx-deployment-namespace> logs deployments/<nginx-deployment>
  • NGINX Configuration: kubectl -n <nginx-deployment-namespace> exec -it deployments/<nginx-deployment> -- nginx -T

Additional context
Add any other context about the problem here. Any log files you want to share.

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions