Ethan-Zhang-ZH opened a new issue, #14022:
URL: https://github.com/apache/apisix/issues/14022
### Description
I'd like to propose two small config-surface enhancements to
`apisix/cli/ngx_tpl.lua`.
Both are currently impossible without patching the template or maintaining a
custom
nginx.conf, but nginx itself fully supports them.
**1. `backlog` for listen sockets**
Currently `node_listen` renders:
```nginx
listen {* item.ip *}:{* item.port *} default_server {% if enable_reuseport
then %} reuseport {% end %};
```
There is no way to tune `backlog=N` from `config.yaml`. Under connection
spikes the
kernel accept queue can overflow (SYN drops, `TCP: request_sock_TCP:
Possible SYN
flooding on port 9080`), and operators have to fix `net.core.somaxconn` on
the host
but still cannot raise nginx's backlog (default 511) for APISIX.
Proposal: allow an optional `backlog` field per listener:
```yaml
nginx_config:
http:
node_listen: # 9080
- ip: 0.0.0.0
port: 9080
backlog: 8192 # optional, absent -> rendered as today
```
**2. `if=` condition for access_log**
Currently the access log is rendered as:
```nginx
access_log {* http.access_log *} main buffer={* http.access_log_buffer *}
flush=3;
```
nginx supports `access_log path [format [buffer=size] [gzip[=level]]
[flush=time] [if=condition]]`
(https://nginx.org/en/docs/http/ngx_http_log_module.html). The condition is
evaluated
in the log phase and can reference variables defined by
`map`/`split_clients`, which
makes things like log sampling or per-status/per-endpoint log exclusion
possible with
plain nginx config — no Lua plugin needed.
Note that nginx's parser treats the 2nd parameter unconditionally as the
format name;
`if=` is only recognized from the 3rd parameter onward. Since the template
already
appends `main` right after the path, an optional `if=` can simply be
inserted after
`main` (before or after `buffer=`, both are accepted), which keeps the
current output
byte-for-byte identical when the option is absent.
Proposal:
```yaml
nginx_config:
http:
access_log_if: $loggable # optional; renders `... main buffer=16384
flush=3 if=$loggable;`
```
The condition variable itself would be declared by users via
`nginx_config.http_configuration_snippet`, e.g. sampling 200s into a
separate file:
```nginx
# http_configuration_snippet
map $status $loggable_200 {
~^200$ $sample_flag;
default 1;
}
map $request_id $sample_flag {
default "";
}
access_log logs/access_200_sample.log main if=$loggable_200;
```
### Motivation
- **backlog**: production gateways behind high-QPS ingress regularly hit
accept-queue
overflow during traffic spikes and restarts (warm-up), and the only
supported knob
today is the host-level `somaxconn`. Exposing `backlog` closes the gap.
- **if=**: log volume is a common operational pain. `if=` is the standard
nginx
mechanism for conditional logging (status filtering, sampling, excluding
health
checks / endpoints with sensitive query params). It would also be the
generic fix
for #10407, which asks for excluding certain endpoints from access logging.
Both changes are template-only (`ngx_tpl.lua` + `conf/config.yaml.example` +
docs),
optional fields, fully backward compatible. I'm willing to submit the PRs.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]