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

Conversation

bisakhmondal
Copy link
Member

@bisakhmondal bisakhmondal commented Dec 10, 2021

What this PR does / why we need it:

closes #5400

Pre-submission checklist:

  • Did you explain what problem does this PR solve? Or what new features have been added?
  • Have you added corresponding test cases?
  • Have you modified the corresponding document?
  • Is this PR backward compatible? If it is not backward compatible, please discuss on the mailing list first

@@ -174,6 +174,11 @@ nginx_config: # config for render the template to generate n
# - TEST_ENV

stream:
enable_access_log: true # enable access log or not, default true
access_log: logs/access_stream.log
access_log_format: "$remote_addr [$time_local] $status $bytes_sent $session_time $upstream_connect_time \"$protocol://$upstream_addr\""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spacewander by consulting http://nginx.org/en/docs/varindex.html, I created the log format. Do you think we can do better? Do let me know. Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use Nginx's basic format in its example?

log_format basic '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time';

See https://nginx.org/en/docs/stream/ngx_stream_log_module.html.

Kong also uses it too: https://github.com/Kong/kong/blob/d65101fe80fd7ac9870a84d34d81bda8bcb461ac/kong/templates/nginx_kong_stream.lua#L3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

Copy link
Member

@spacewander spacewander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


access_log {* stream.access_log *} main buffer=16384 flush=3;
{% end %}
open_log_file_cache max=1000 inactive=60;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need it, as the log file name doesn't contain variable. There is only one open log file.
See https://nginx.org/en/docs/http/ngx_http_log_module.html#open_log_file_cache

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. Thanks

@@ -261,7 +271,7 @@ http {

access_log {* http.access_log *} main buffer=16384 flush=3;
{% end %}
open_file_cache max=1000 inactive=60;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open_file_cache is there: https://nginx.org/en/docs/http/ngx_http_core_module.html#open_file_cache
This directive is different from open_log_file_cache.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack

@@ -174,6 +174,11 @@ nginx_config: # config for render the template to generate n
# - TEST_ENV

stream:
enable_access_log: true # enable access log or not, default true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The access_log in stream is false by default: https://nginx.org/en/docs/stream/ngx_stream_log_module.html#access_log

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -174,6 +174,11 @@ nginx_config: # config for render the template to generate n
# - TEST_ENV

stream:
enable_access_log: true # enable access log or not, default true
access_log: logs/access_stream.log
access_log_format: "$remote_addr [$time_local] $status $bytes_sent $session_time $upstream_connect_time \"$protocol://$upstream_addr\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use Nginx's basic format in its example?

log_format basic '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time';

See https://nginx.org/en/docs/stream/ngx_stream_log_module.html.

Kong also uses it too: https://github.com/Kong/kong/blob/d65101fe80fd7ac9870a84d34d81bda8bcb461ac/kong/templates/nginx_kong_stream.lua#L3

@bisakhmondal
Copy link
Member Author

Could you add a test in https://github.com/apache/apisix/blob/master/t/cli/test_access_log.sh? Thanks.

Done. Took a while to figure out how to set up mock upstream.

exit 1
fi

make stop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will clean up automatically, so there is no need to add it. See

make stop || true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thanks for sharing the details. Updated.

@spacewander spacewander merged commit 71c256b into apache:master Dec 13, 2021
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.

request help: How to enable logging for the four-layer proxy stream route?
3 participants