Skip to content
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
4 changes: 4 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
$temp_usage = $puppetdb::params::temp_usage,
$certificate_whitelist_file = $puppetdb::params::certificate_whitelist_file,
$certificate_whitelist = $puppetdb::params::certificate_whitelist,
$database_max_pool_size = $puppetdb::params::database_max_pool_size,
$read_database_max_pool_size = $puppetdb::params::read_database_max_pool_size,
) inherits puppetdb::params {

class { '::puppetdb::server':
Expand Down Expand Up @@ -138,6 +140,8 @@
temp_usage => $temp_usage,
certificate_whitelist_file => $certificate_whitelist_file,
certificate_whitelist => $certificate_whitelist,
database_max_pool_size => $database_max_pool_size,
read_database_max_pool_size => $read_database_max_pool_size,
}

if ($database == 'postgres') {
Expand Down
27 changes: 19 additions & 8 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
$postgres_version = '9.4'

# The remaining database settings are not used for an embedded database
$database_host = 'localhost'
$database_port = '5432'
$database_name = 'puppetdb'
$database_username = 'puppetdb'
$database_password = 'puppetdb'
$database_ssl = undef
$jdbc_ssl_properties = ''
$database_validate = true
$database_host = 'localhost'
$database_port = '5432'
$database_name = 'puppetdb'
$database_username = 'puppetdb'
$database_password = 'puppetdb'
$database_ssl = undef
$jdbc_ssl_properties = ''
$database_validate = true
$database_max_pool_size = undef

# These settings manage the various auto-deactivation and auto-purge settings
$node_ttl = '0s'
Expand Down Expand Up @@ -57,6 +58,7 @@
$read_conn_max_age = '60'
$read_conn_keep_alive = '45'
$read_conn_lifetime = '0'
$read_database_max_pool_size = undef

$manage_firewall = true
$java_args = {}
Expand Down Expand Up @@ -164,4 +166,13 @@
$certificate_whitelist = [ ]
# change to this to only allow access by the puppet master by default:
#$certificate_whitelist = [ $::servername ]

# Get the parameter name for the database connection pool tuning
if $puppetdb_version in ['latest','present'] or versioncmp($puppetdb_version, '4.0.0') >= 0 {
$database_max_pool_size_setting_name = 'maximum-pool-size'
} elsif versioncmp($puppetdb_version, '2.8.0') >= 0 {
$database_max_pool_size_setting_name = 'partition-conn-max'
} else {
$database_max_pool_size_setting_name = undef
}
}
38 changes: 21 additions & 17 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
$temp_usage = $puppetdb::params::temp_usage,
$certificate_whitelist_file = $puppetdb::params::certificate_whitelist_file,
$certificate_whitelist = $puppetdb::params::certificate_whitelist,
$database_max_pool_size = $puppetdb::params::database_max_pool_size,
$read_database_max_pool_size = $puppetdb::params::read_database_max_pool_size,
) inherits puppetdb::params {
# deprecation warnings
if $database_ssl != undef {
Expand Down Expand Up @@ -160,6 +162,7 @@
database_password => $database_password,
database_name => $database_name,
database_ssl => $database_ssl,
database_max_pool_size => $database_max_pool_size,
jdbc_ssl_properties => $jdbc_ssl_properties,
database_validate => $database_validate,
database_embedded_path => $database_embedded_path,
Expand All @@ -178,23 +181,24 @@
}

class { 'puppetdb::server::read_database':
database => $read_database,
database_host => $read_database_host,
database_port => $read_database_port,
database_username => $read_database_username,
database_password => $read_database_password,
database_name => $read_database_name,
database_ssl => $read_database_ssl,
jdbc_ssl_properties => $read_database_jdbc_ssl_properties,
database_validate => $read_database_validate,
log_slow_statements => $read_log_slow_statements,
conn_max_age => $read_conn_max_age,
conn_keep_alive => $read_conn_keep_alive,
conn_lifetime => $read_conn_lifetime,
confdir => $confdir,
puppetdb_user => $puppetdb_user,
puppetdb_group => $puppetdb_group,
notify => Service[$puppetdb_service],
database => $read_database,
database_host => $read_database_host,
database_port => $read_database_port,
database_username => $read_database_username,
database_password => $read_database_password,
database_name => $read_database_name,
database_ssl => $read_database_ssl,
jdbc_ssl_properties => $read_database_jdbc_ssl_properties,
database_validate => $read_database_validate,
log_slow_statements => $read_log_slow_statements,
conn_max_age => $read_conn_max_age,
conn_keep_alive => $read_conn_keep_alive,
conn_lifetime => $read_conn_lifetime,
confdir => $confdir,
puppetdb_user => $puppetdb_user,
puppetdb_group => $puppetdb_group,
notify => Service[$puppetdb_service],
database_max_pool_size => $read_database_max_pool_size,
}

if str2bool($ssl_set_cert_paths) == true
Expand Down
15 changes: 15 additions & 0 deletions manifests/server/database.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
$confdir = $puppetdb::params::confdir,
$puppetdb_user = $puppetdb::params::puppetdb_user,
$puppetdb_group = $puppetdb::params::puppetdb_group,
$database_max_pool_size = $puppetdb::params::database_max_pool_size,
) inherits puppetdb::params {

if str2bool($database_validate) {
Expand Down Expand Up @@ -159,4 +160,18 @@
setting => 'conn-lifetime',
value => $conn_lifetime,
}

if $puppetdb::params::database_max_pool_size_setting_name != undef {
if $database_max_pool_size == 'absent' {
ini_setting { 'puppetdb_database_max_pool_size':
ensure => absent,
setting => $puppetdb::params::database_max_pool_size_setting_name,
}
} elsif $database_max_pool_size != undef {
ini_setting { 'puppetdb_database_max_pool_size':
setting => $puppetdb::params::database_max_pool_size_setting_name,
value => $database_max_pool_size,
}
}
}
}
47 changes: 31 additions & 16 deletions manifests/server/read_database.pp
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# PRIVATE CLASS - do not use directly
class puppetdb::server::read_database (
$database = $puppetdb::params::read_database,
$database_host = $puppetdb::params::read_database_host,
$database_port = $puppetdb::params::read_database_port,
$database_username = $puppetdb::params::read_database_username,
$database_password = $puppetdb::params::read_database_password,
$database_name = $puppetdb::params::read_database_name,
$database_ssl = $puppetdb::params::read_database_ssl,
$jdbc_ssl_properties = $puppetdb::params::read_database_jdbc_ssl_properties,
$database_validate = $puppetdb::params::read_database_validate,
$log_slow_statements = $puppetdb::params::read_log_slow_statements,
$conn_max_age = $puppetdb::params::read_conn_max_age,
$conn_keep_alive = $puppetdb::params::read_conn_keep_alive,
$conn_lifetime = $puppetdb::params::read_conn_lifetime,
$confdir = $puppetdb::params::confdir,
$puppetdb_user = $puppetdb::params::puppetdb_user,
$puppetdb_group = $puppetdb::params::puppetdb_group,
$database = $puppetdb::params::read_database,
$database_host = $puppetdb::params::read_database_host,
$database_port = $puppetdb::params::read_database_port,
$database_username = $puppetdb::params::read_database_username,
$database_password = $puppetdb::params::read_database_password,
$database_name = $puppetdb::params::read_database_name,
$database_ssl = $puppetdb::params::read_database_ssl,
$jdbc_ssl_properties = $puppetdb::params::read_database_jdbc_ssl_properties,
$database_validate = $puppetdb::params::read_database_validate,
$log_slow_statements = $puppetdb::params::read_log_slow_statements,
$conn_max_age = $puppetdb::params::read_conn_max_age,
$conn_keep_alive = $puppetdb::params::read_conn_keep_alive,
$conn_lifetime = $puppetdb::params::read_conn_lifetime,
$confdir = $puppetdb::params::confdir,
$puppetdb_user = $puppetdb::params::puppetdb_user,
$puppetdb_group = $puppetdb::params::puppetdb_group,
$database_max_pool_size = $puppetdb::params::read_database_max_pool_size,
) inherits puppetdb::params {

# Only add the read database configuration if database host is defined.
Expand Down Expand Up @@ -129,6 +130,20 @@
setting => 'conn-lifetime',
value => $conn_lifetime,
}

if $puppetdb::params::database_max_pool_size_setting_name != undef {
if $database_max_pool_size == 'absent' {
ini_setting { 'puppetdb_read_database_max_pool_size':
ensure => absent,
setting => $puppetdb::params::database_max_pool_size_setting_name,
}
} elsif $database_max_pool_size != undef {
ini_setting { 'puppetdb_read_database_max_pool_size':
setting => $puppetdb::params::database_max_pool_size_setting_name,
value => $database_max_pool_size,
}
}
}
} else {
file { "${confdir}/read_database.ini":
ensure => absent,
Expand Down
92 changes: 92 additions & 0 deletions spec/unit/classes/server/database_ini_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
'setting' => 'conn-lifetime',
'value' => '0'
)}
it { should_not contain_ini_setting('puppetdb_database_max_pool_size') }
end

describe 'when using a legacy PuppetDB version' do
Expand Down Expand Up @@ -233,6 +234,7 @@
'setting' => 'conn-lifetime',
'value' => '0'
)}
it { should_not contain_ini_setting('puppetdb_database_max_pool_size') }
end

describe 'when overriding database_path for embedded' do
Expand All @@ -251,5 +253,95 @@
'value' => 'file:/tmp/foo;hsqldb.tx=mvcc;sql.syntax_pgs=true'
)}
end

describe 'when setting max pool size' do
context 'on current PuppetDB' do
describe 'to a numeric value' do
let(:params) do
{
'database_max_pool_size' => 12345
}
end
it { should contain_ini_setting('puppetdb_database_max_pool_size').
with(
'ensure' => 'present',
'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
'section' => 'database',
'setting' => 'maximum-pool-size',
'value' => '12345'
)}
end

describe 'to absent' do
let(:params) do
{
'database_max_pool_size' => 'absent'
}
end
it { should contain_ini_setting('puppetdb_database_max_pool_size').
with(
'ensure' => 'absent',
'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
'section' => 'database',
'setting' => 'maximum-pool-size'
)}
end
end

context 'on PuppetDB 3.2' do
let (:pre_condition) { 'class { "puppetdb::globals": version => "3.2.0", }' }
describe 'to a numeric value' do
let(:params) do
{
'database_max_pool_size' => 12345
}
end
it { should contain_ini_setting('puppetdb_database_max_pool_size').
with(
'ensure' => 'present',
'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
'section' => 'database',
'setting' => 'partition-conn-max',
'value' => '12345'
)}
end

describe 'to absent' do
let(:params) do
{
'database_max_pool_size' => 'absent'
}
end
it { should contain_ini_setting('puppetdb_database_max_pool_size').
with(
'ensure' => 'absent',
'path' => '/etc/puppetlabs/puppetdb/conf.d/database.ini',
'section' => 'database',
'setting' => 'partition-conn-max'
)}
end
end

context 'on a legacy PuppetDB version' do
let (:pre_condition) { 'class { "puppetdb::globals": version => "2.2.0", }' }
describe 'to a numeric value' do
let(:params) do
{
'database_max_pool_size' => 12345
}
end
it { should_not contain_ini_setting('puppetdb_database_max_pool_size') }
end

describe 'to absent' do
let(:params) do
{
'database_max_pool_size' => 'absent'
}
end
it { should_not contain_ini_setting('puppetdb_database_max_pool_size') }
end
end
end
end
end