From f025751240cd5a78fc1509eba25fd38df17b1916 Mon Sep 17 00:00:00 2001 From: Vilnius Ramanauskas Date: Fri, 17 Jul 2020 12:22:04 +0300 Subject: [PATCH 1/2] Add debug_connection events option --- manifests/config.pp | 1 + manifests/init.pp | 1 + templates/conf.d/nginx.conf.erb | 7 +++++-- types/debugconnection.pp | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 types/debugconnection.pp diff --git a/manifests/config.pp b/manifests/config.pp index 9c04b0182..16a638963 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -56,6 +56,7 @@ $lingering_timeout = $nginx::lingering_timeout $etag = $nginx::etag $events_use = $nginx::events_use + $debug_connections = $nginx::debug_connections $fastcgi_cache_inactive = $nginx::fastcgi_cache_inactive $fastcgi_cache_key = $nginx::fastcgi_cache_key $fastcgi_cache_keys_zone = $nginx::fastcgi_cache_keys_zone diff --git a/manifests/init.pp b/manifests/init.pp index 3836e46d7..3e28d2e2b 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -88,6 +88,7 @@ $lingering_timeout = '5s', Optional[Enum['on', 'off']] $etag = undef, Optional[String] $events_use = undef, + Array[Nginx::DebugConnection] $debug_connections = [], String $fastcgi_cache_inactive = '20m', Optional[String] $fastcgi_cache_key = undef, String $fastcgi_cache_keys_zone = 'd3:100m', diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb index a6605c283..5bcbc7958 100644 --- a/templates/conf.d/nginx.conf.erb +++ b/templates/conf.d/nginx.conf.erb @@ -40,10 +40,13 @@ events { <%- end -%> worker_connections <%= @worker_connections -%>; <%- if @multi_accept == 'on' -%> - multi_accept on; + multi_accept on; <%- end -%> <%- if @events_use -%> - use <%= @events_use %>; + use <%= @events_use %>; + <%- end -%> + <%- @debug_connections.each do |address| -%> + debug_connection <%= address %>; <%- end -%> } diff --git a/types/debugconnection.pp b/types/debugconnection.pp new file mode 100644 index 000000000..67b8388bc --- /dev/null +++ b/types/debugconnection.pp @@ -0,0 +1 @@ +type Nginx::DebugConnection = Variant[Stdlib::Host, Enum['unix:']] From 780e47ca07b61e8188b4d6d922f5fce17a88c4c4 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Sun, 30 Aug 2020 10:36:53 +0100 Subject: [PATCH 2/2] Add tests and docs for `debug_connections` `Stdlib::IP::Address` also added to the type alias so that it accepts IPv6 networks. --- manifests/init.pp | 4 ++++ spec/classes/nginx_spec.rb | 9 +++++++++ spec/type_aliases/debugconnection_spec.rb | 10 ++++++++++ types/debugconnection.pp | 2 +- 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 spec/type_aliases/debugconnection_spec.rb diff --git a/manifests/init.pp b/manifests/init.pp index 3e28d2e2b..c75bd2e69 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -40,6 +40,10 @@ # already installed. If the fact is unavailable, it defaults to '1.6.0'. # You may need to set this manually to get a working and idempotent # configuration. +# +# @param debug_connections +# Configures nginx `debug_connection` lines in the `events` section of the nginx config. +# See http://nginx.org/en/docs/ngx_core_module.html#debug_connection class nginx ( ### START Nginx Configuration ### Variant[Stdlib::Absolutepath, Boolean] $client_body_temp_path = $nginx::params::client_body_temp_path, diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index 02478e1b6..91ecb3bb2 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -1077,6 +1077,15 @@ attr: 'ssl_password_file', value: '/path/to/password_file', match: ' ssl_password_file /path/to/password_file;' + }, + { + title: 'should contain debug_connection directives', + attr: 'debug_connections', + value: %w[127.0.0.1 unix:], + match: [ + ' debug_connection 127.0.0.1;', + ' debug_connection unix:;' + ] } ].each do |param| context "when #{param[:attr]} is #{param[:value]}" do diff --git a/spec/type_aliases/debugconnection_spec.rb b/spec/type_aliases/debugconnection_spec.rb new file mode 100644 index 000000000..d9d4cb4cd --- /dev/null +++ b/spec/type_aliases/debugconnection_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe 'Nginx::DebugConnection' do + it { is_expected.to allow_value('127.0.0.1') } + it { is_expected.to allow_value('localhost') } + it { is_expected.to allow_value('192.0.2.0/24') } + it { is_expected.to allow_value('::1') } + it { is_expected.to allow_value('2001:0db8::/32') } + it { is_expected.to allow_value('unix:') } +end diff --git a/types/debugconnection.pp b/types/debugconnection.pp index 67b8388bc..399fc4bb5 100644 --- a/types/debugconnection.pp +++ b/types/debugconnection.pp @@ -1 +1 @@ -type Nginx::DebugConnection = Variant[Stdlib::Host, Enum['unix:']] +type Nginx::DebugConnection = Variant[Stdlib::Host, Stdlib::IP::Address, Enum['unix:']]