Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable L4 stream logging #5768

Merged
merged 4 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions apisix/cli/ngx_tpl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ stream {
lua_ssl_trusted_certificate {* ssl.ssl_trusted_certificate *};
{% end %}

# for stream logs, off by default
{% if stream.enable_access_log == true then %}
log_format main escape={* stream.access_log_format_escape *} '{* stream.access_log_format *}';

access_log {* stream.access_log *} main buffer=16384 flush=3;
{% end %}

# stream configuration snippet starts
{% if stream_configuration_snippet then %}
{* stream_configuration_snippet *}
Expand Down
5 changes: 5 additions & 0 deletions conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ nginx_config: # config for render the template to generate n
# - TEST_ENV

stream:
enable_access_log: false # enable access log or not, default false
access_log: logs/access_stream.log
access_log_format: "$remote_addr [$time_local] $protocol $status $bytes_sent $bytes_received $session_time"
# create your custom log format by visiting http://nginx.org/en/docs/varindex.html
access_log_format_escape: default # allows setting json or default characters escaping in variables
lua_shared_dict:
etcd-cluster-health-check-stream: 10m
lrucache-lock-stream: 10m
Expand Down
37 changes: 37 additions & 0 deletions t/cli/test_access_log.sh
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,40 @@ fi

make stop
echo "passed: should find upstream scheme"

# check stream logs
echo '
apisix:
stream_proxy: # UDP proxy
udp:
- "127.0.0.1:9200"

nginx_config:
stream:
enable_access_log: true
access_log_format: "$remote_addr $protocol test_stream_access_log_format"
' > conf/config.yaml

make init

grep "test_stream_access_log_format" conf/nginx.conf > /dev/null
if [ ! $? -eq 0 ]; then
echo "failed: stream access_log_format in nginx.conf doesn't change"
exit 1
fi
echo "passed: stream access_log_format in nginx.conf is ok"

# check if logs are being written
make run
sleep 0.1
# sending single udp packet
echo -n "hello" | nc -4u -w0 localhost 9200
sleep 4
tail -n 1 logs/access_stream.log > output.log

if ! grep '127.0.0.1 UDP test_stream_access_log_format' output.log; then
echo "failed: should have found udp log entry"
cat output.log
exit 1
fi
echo "passed: logs are being dumped for stream proxy"