Skip to content

feat: support backlog in listen and if= condition in access_log via nginx_config - #14031

Open
Ethan-Zhang-ZH wants to merge 2 commits into
apache:masterfrom
Ethan-Zhang-ZH:feat/issue-14022
Open

Ethan-Zhang-ZH wants to merge 2 commits into
apache:masterfrom
Ethan-Zhang-ZH:feat/issue-14022

Conversation

@Ethan-Zhang-ZH

Copy link
Copy Markdown

Description

Please refer to #14022. This PR implements both enhancements proposed there.

1. backlog for listen sockets

nginx_config:
  http:
    node_listen:
      - ip: 0.0.0.0
        port: 9080
        backlog: 8192   # optional, absent -> rendered as today (nginx default 511)

Renders the backlog=N parameter of the nginx listen directive, so operators can
size the pending connections queue from config.yaml instead of relying on the default
511 (which can overflow under connection spikes even when host-level
net.core.somaxconn is tuned).

2. if= condition for access_log

nginx_config:
  http:
    access_log_if: $loggable   # optional, absent -> rendered as today
    http_configuration_snippet: |
      map $status $loggable {
          default 1;
      }

Renders an if=<condition> parameter on the access_log directive. The condition is
evaluated in the log phase and can reference variables declared via
http_configuration_snippet (map / split_clients), enabling log sampling or
per-status / per-endpoint log exclusion with plain nginx config, without any Lua plugin.
It is also the generic fix for #10407.

Changes

  • apisix/cli/ops.lua: pass an optional, validated backlog (positive integer) through listen_table_insert
  • apisix/cli/ngx_tpl.lua: render backlog=N and if=<condition> when configured (output is byte-identical when absent)
  • conf/config.yaml.example: document both fields
  • t/cli/test_main.sh: backlog rendering + invalid-value test cases
  • t/cli/test_access_log.sh: if= rendered / not-rendered test cases

Both fields are optional and fully backward compatible. All t/cli suites touched by
these changes pass locally.

Fixes #14022

Allow an optional `backlog` field per node_listen item, which renders
the `backlog=N` parameter of the nginx listen directive. This lets
operators size the pending connections queue from config.yaml instead
of relying on the default 511, which can overflow under connection
spikes when only the host-level net.core.somaxconn is tuned.

Fixes part of apache#14022

Signed-off-by: zhangshumin01 <10682145+Ethan-Zhang-ZH@users.noreply.github.com>
Allow an optional `access_log_if` field under nginx_config.http, which
renders an `if=<condition>` parameter on the access_log directive. The
condition is evaluated in the log phase and can reference variables
declared via http_configuration_snippet (map / split_clients), enabling
log sampling or per-status/per-endpoint log exclusion with plain nginx
config, without any Lua plugin.

Fixes part of apache#14022

Signed-off-by: zhangshumin01 <10682145+Ethan-Zhang-ZH@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: support backlog in listen and if= condition in access_log via nginx_config

1 participant