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

Add stream log support #1461

Merged
merged 6 commits into from
Dec 9, 2022

Conversation

ardrigh
Copy link
Contributor

@ardrigh ardrigh commented Jul 30, 2021

Pull Request (PR) description

Following on work from previous PRs to add stream log changes to the module.

Updated changes to fix file conflicts and newer changes in v4.1.0

The configuration in Hiera:

nginx::stream_access_log: '/var/log/nginx/nginx-stream-access.log'
nginx::stream_custom_format_log: 'basic'
nginx::stream_log_format:
  basic: '$remote_addr [$time_local] $protocol $status $bytes_sent $bytes_received $session_time $server_addr:$server_port $upstream_addr'

Adds the following lines to nginx.conf:

+  log_format basic '$remote_addr [$time_local] $protocol $status $bytes_sent $bytes_received $session_time $server_addr:$server_port $upstream_addr';
 
+  access_log /var/log/nginx/nginx-stream-access.log basic;

If stream_custom_format_log is not set, nginx will use the built-in combined log format for the stream access log.

This Pull Request (PR) fixes the following issue

Closes: #1439

@puppet-community-rangefinder
Copy link

nginx::config is a class

Breaking changes to this file MAY impact these 2 modules (near match):

nginx is a class

Breaking changes to this file WILL impact these 15 modules (exact match):
Breaking changes to this file MAY impact these 34 modules (near match):

nginx::params is a class

Breaking changes to this file MAY impact these 1 modules (near match):

This module is declared in 9 of 578 indexed public Puppetfiles.


These results were generated with Rangefinder, a tool that helps predict the downstream impact of breaking changes to elements used in Puppet modules. You can run this on the command line to get a full report.

Exact matches are those that we can positively identify via namespace and the declaring modules' metadata. Non-namespaced items, such as Puppet 3.x functions, will always be reported as near matches only.

@ardrigh ardrigh marked this pull request as ready for review July 30, 2021 01:21
@bastelfreak bastelfreak added the enhancement New feature or request label Jul 30, 2021
@@ -117,6 +119,7 @@
$keepalive_timeout = '65s',
$keepalive_requests = '100',
$log_format = {},
$stream_log_format = {},
Copy link
Member

Choose a reason for hiding this comment

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

Please enforce the datatype here as well. I guess something like this should work:

Suggested change
$stream_log_format = {},
Hash[String[1], String[1]] $stream_log_format = {},

@@ -326,5 +326,19 @@ stream {
<% unless @confd_only -%>
include <%= @conf_dir %>/streams-enabled/*;
<% end -%>

<% if @stream_log_format -%>
Copy link
Member

Choose a reason for hiding this comment

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

can you test if the if statement is required? The variable always exists, by default it's just empty. I think we can directly start with the .sort_by call

Copy link
Member

@ekohl ekohl Jul 30, 2021

Choose a reason for hiding this comment

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

What could make sense is

<% end -%>
<% unless @stream_log_format.empty? -%>

<% @stream_log_format.sort_by{|k,v| k}.each do |key,value| -%> 

With this you can prevent the empty lines in the generated config. Because right now it generates (roughly):

  include .../streams-enabled/*;


  access_log ...

(note it's 2 empty lines instead of 1)

@ardrigh
Copy link
Contributor Author

ardrigh commented Aug 2, 2021

I am working on making updates to fix this PR. I need to check it works with what we have deployed.

I think the tests are failing because they are in the wrong location in the test file. I think the test lines might be better in a context for stream specifically.

Would it work adding a "dynamic module" test similar to geoip module, checking the stream content lines for the access_log and log_format values?

geoip test example:

context 'when dynamic_modules is "[\'ngx_http_geoip_module\']" ' do

@ardrigh ardrigh force-pushed the add_nginx_config_for_stream_log branch from 48f82a8 to 836de1d Compare November 17, 2022 15:00
@ardrigh ardrigh marked this pull request as draft November 20, 2022 11:42
@ardrigh ardrigh force-pushed the add_nginx_config_for_stream_log branch from 836de1d to a2783a0 Compare December 7, 2022 17:26
@ardrigh ardrigh requested review from ekohl and bastelfreak and removed request for ekohl and bastelfreak December 7, 2022 17:35
@ardrigh ardrigh force-pushed the add_nginx_config_for_stream_log branch from a2783a0 to 212f883 Compare December 7, 2022 17:40
@ardrigh ardrigh marked this pull request as ready for review December 7, 2022 17:40
@ardrigh ardrigh force-pushed the add_nginx_config_for_stream_log branch from 5fe5272 to b075ef4 Compare December 7, 2022 18:09
@ardrigh
Copy link
Contributor Author

ardrigh commented Dec 7, 2022

Updated with suggested changes

@ekohl
Copy link
Member

ekohl commented Dec 7, 2022

From a quick look this looks good, but the tests fail. The CentOS 7 tests failing looks unrelated to me, but the unit tests do.

@ardrigh
Copy link
Contributor Author

ardrigh commented Dec 7, 2022

I am working on making updates to fix this PR. I need to check it works with what we have deployed.

I think the tests are failing because they are in the wrong location in the test file. I think the test lines might be better in a context for stream specifically.

Still the same issue with the unit tests. Which isn't surprising since I did a quick copy & paste to get started.

I don't see anything that tests

<% if @stream -%>

And without that being set, it's not expected the lines get written to the config file, and the unit tests correctly fail.

These tests might not cleanly fit within the existing template iterator. I will have another look

@ardrigh ardrigh force-pushed the add_nginx_config_for_stream_log branch from b075ef4 to bb4be27 Compare December 8, 2022 13:23
@ardrigh ardrigh force-pushed the add_nginx_config_for_stream_log branch 2 times, most recently from 2401983 to fd7c84c Compare December 8, 2022 15:33
@ardrigh ardrigh force-pushed the add_nginx_config_for_stream_log branch from fd7c84c to 8837d9b Compare December 8, 2022 15:35
@ardrigh ardrigh requested review from ekohl and bastelfreak and removed request for ekohl and bastelfreak December 8, 2022 16:00
@ardrigh
Copy link
Contributor Author

ardrigh commented Dec 8, 2022

@ekohl I have added a basic set of tests to cover the main use case for the stream access log.

Appreciate if you could give another review

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Thanks!

@ekohl ekohl changed the title Add stream log changes Add stream log support Dec 9, 2022
@ekohl ekohl merged commit b815a57 into voxpupuli:master Dec 9, 2022
@ardrigh ardrigh deleted the add_nginx_config_for_stream_log branch September 5, 2023 15:08
@TheMeier TheMeier added this to the 6.0.0 milestone Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants