Skip to content

Commit b67fe80

Browse files
committed
(maint) correct pdk validate warnings, update versions
Correct puppet lint warnings. Correct metadata.json warnings. Remove code supporting unsupported versions of PE.
1 parent 88ef7f0 commit b67fe80

File tree

10 files changed

+139
-113
lines changed

10 files changed

+139
-113
lines changed

manifests/backup.pp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
# Backup PostgreSQL
2+
#
3+
# @summary Backup PostgreSQL
4+
15
class pe_databases::backup (
2-
Array[Hash] $databases_and_backup_schedule = [
6+
Array[Hash] $databases_and_backup_schedule =
7+
[
38
{
4-
'databases' => ['pe-activity', 'pe-classifier', 'pe-postgres', 'pe-rbac', 'pe-orchestrator'],
9+
'databases' =>
10+
[
11+
'pe-activity',
12+
'pe-classifier',
13+
'pe-orchestrator',
14+
'pe-postgres',
15+
'pe-rbac',
16+
],
517
'schedule' =>
618
{
719
'minute' => '30',
@@ -41,7 +53,6 @@
4153
}
4254

4355
$databases_and_backup_schedule.each | Hash $dbs_and_schedule | {
44-
4556
$databases_to_backup = $dbs_and_schedule['databases']
4657
$db_string = join($databases_to_backup, ' ')
4758

manifests/init.pp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Tuning, maintenance, and backups for PE PostgreSQL.
2+
#
3+
# @summary Tuning, maintenance, and backups for PE PostgreSQL.
4+
15
class pe_databases (
26
Boolean $manage_database_backups = true,
37
Boolean $manage_database_maintenance = true,
@@ -7,11 +11,7 @@
711
String $scripts_dir = "${install_dir}/scripts"
812
) {
913

10-
if ( versioncmp('2017.3.0', $facts['pe_server_version']) <= 0 ) {
11-
$psql_version = '9.6'
12-
} else {
13-
$psql_version = '9.4'
14-
}
14+
$psql_version = $facts['pe_postgresql_info']['installed_server_version']
1515

1616
file { [$install_dir, $scripts_dir] :
1717
ensure => directory,
@@ -22,17 +22,19 @@
2222
include pe_databases::maintenance
2323
}
2424

25-
if $manage_postgresql_settings and ( versioncmp('2018.1.0', $facts['pe_server_version']) > 0 ) {
25+
# Do not manage postgresql_settings in 2018.1.0 or newer.
26+
if $manage_postgresql_settings and (versioncmp('2018.1.0', $facts['pe_server_version']) > 0) {
2627
include pe_databases::postgresql_settings
27-
2828
class { 'pe_databases::postgresql_settings::table_settings' :
29-
manage_fact_values_autovacuum_cost_delay => $pe_databases::postgresql_settings::manage_fact_values_autovacuum_cost_delay,
3029
manage_reports_autovacuum_cost_delay => $pe_databases::postgresql_settings::manage_reports_autovacuum_cost_delay,
3130
factsets_autovacuum_vacuum_scale_factor => $pe_databases::postgresql_settings::factsets_autovacuum_vacuum_scale_factor,
3231
reports_autovacuum_vacuum_scale_factor => $pe_databases::postgresql_settings::reports_autovacuum_vacuum_scale_factor,
3332
require => Class['pe_databases::postgresql_settings'],
3433
}
35-
} elsif $manage_table_settings { #do not manage postgreql_settings in 2018.1.0
34+
} elsif $manage_table_settings {
35+
# This is to provide for situations, like PE XL,
36+
# where the pe-puppetdb database does not exist on the PostgreSQL system being tuned.
37+
# In PE XL, the Master and Replica run PostgreSQL for all databases *except* for pe-puppetdb.
3638
include pe_databases::postgresql_settings::table_settings
3739
}
3840

manifests/maintenance.pp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
# Maintenance for PostgreSQL
2+
#
3+
# @summary Maintenance for PostgreSQL
4+
15
class pe_databases::maintenance (
26
Boolean $disable_maintenance = false,
3-
String $logging_directory = '/var/log/puppetlabs/pe_databases_cron',
4-
String $script_directory = $pe_databases::scripts_dir,
7+
String $logging_directory = '/var/log/puppetlabs/pe_databases_cron',
8+
String $script_directory = $pe_databases::scripts_dir,
59
){
610

7-
#If the PE Version includes pg_repack (2018.1.7 and 2019.0.2) then use pg_repack and remove the old script and cron jobs
8-
if ( versioncmp( '2018.1.7', $facts['pe_server_version']) <= 0 and versioncmp($facts['pe_server_version'], '2019.0.0') < 0 ) {
11+
# If this version of PE includes pg_repack (2018.1.7 and 2019.0.2 and newer),
12+
# then use pg_repack and remove the old script and cron jobs.
13+
14+
if (versioncmp( '2018.1.7', $facts['pe_server_version']) <= 0 and versioncmp($facts['pe_server_version'], '2019.0.0') < 0 ) {
915
include pe_databases::maintenance::pg_repack
1016
class { 'pe_databases::maintenance::vacuum_full':
1117
disable_maintenance => true,

manifests/maintenance/pg_repack.pp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
# A description of what this class does
1+
# Maintenance pg_repack
22
#
3-
# @summary A short summary of the purpose of this class
4-
#
5-
# @example
6-
# include pe_databases::maintenance::pg_repack
3+
# @summary Maintenance pg_repack
4+
75
class pe_databases::maintenance::pg_repack (
86
Boolean $disable_maintenance = $pe_databases::maintenance::disable_maintenance,
97
String $logging_directory = $pe_databases::maintenance::logging_directory,
10-
Integer $jobs = $facts['processors']['count']/4
8+
Integer $jobs = $facts['processors']['count'] / 4
119
) {
1210

1311
$ensure_cron = $disable_maintenance ? {
1412
true => absent,
1513
default => present
1614
}
1715

18-
#PE 2019.1 starting shipping versioned pe-postgres packages where all paths are versioned
19-
#So prior to 2019.1 use a non-versioned path and after use a versioned path
16+
# PE 2019.1 starting shipping versioned pe-postgres packages where all paths are versioned.
17+
# So, prior to 2019.1 use a non-versioned path, and after use a versioned path.
18+
2019
$postgresql_version = $facts['pe_postgresql_info']['installed_server_version']
2120
$repack_executable = versioncmp('2019.1.0', $facts['pe_server_version']) ? {
22-
1 => '/opt/puppetlabs/server/apps/postgresql/bin/pg_repack',
23-
default => "/opt/puppetlabs/server/apps/postgresql/${$postgresql_version}/bin/pg_repack" }
21+
1 => '/opt/puppetlabs/server/apps/postgresql/bin/pg_repack',
22+
default => "/opt/puppetlabs/server/apps/postgresql/${$postgresql_version}/bin/pg_repack" }
2423

2524
$repack = "su - pe-postgres -s /bin/bash -c \"${repack_executable} -d pe-puppetdb"
2625
$repack_jobs = "--jobs ${jobs}"
26+
2727
$facts_tables = '-t factsets -t fact_paths"'
2828
$catalogs_tables = '-t catalogs -t catalog_resources -t edges -t certnames"'
2929
$other_tables = '-t producers -t resource_params -t resource_params_cache"'
@@ -60,8 +60,6 @@
6060
}
6161

6262
cron { 'pg_repack reports tables' :
63-
ensure => $ensure_cron,
64-
user => 'root',
6563
monthday => 10,
6664
hour => 5,
6765
minute => 30,

manifests/maintenance/vacuum_full.pp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# A description of what this class does
1+
# Maintenance VACUUM FULL
22
#
3-
# @summary A short summary of the purpose of this class
4-
#
5-
# @example
6-
# include pe_databases::maintenance::vacuum_full
3+
# @summary Maintenance VACUUM FULL
4+
75
class pe_databases::maintenance::vacuum_full (
86
Boolean $disable_maintenance = $pe_databases::maintenance::disable_maintenance,
97
String $logging_directory = $pe_databases::maintenance::logging_directory,
@@ -30,41 +28,41 @@
3028
mode => '0744',
3129
}
3230

33-
cron { 'VACUUM FULL facts tables' :
31+
Cron {
3432
ensure => $ensure_cron,
3533
user => 'root',
34+
require => File[$logging_directory, $script_directory],
35+
}
36+
37+
cron { 'VACUUM FULL facts tables' :
3638
weekday => [2,6],
3739
hour => 4,
3840
minute => 30,
3941
command => "${vacuum_script_path} facts",
40-
require => File[$logging_directory, $script_directory],
4142
}
4243

4344
cron { 'VACUUM FULL catalogs tables' :
44-
ensure => $ensure_cron,
45-
user => 'root',
4645
weekday => [0,4],
4746
hour => 4,
4847
minute => 30,
4948
command => "${vacuum_script_path} catalogs",
50-
require => File[$logging_directory, $script_directory],
5149
}
5250

5351
cron { 'VACUUM FULL other tables' :
54-
ensure => $ensure_cron,
55-
user => 'root',
5652
monthday => 20,
5753
hour => 5,
5854
minute => 30,
5955
command => "${vacuum_script_path} other",
60-
require => File[$logging_directory, $script_directory],
6156
}
6257

63-
#Remove old versions of maintenance cron jobs
58+
# LEGACY CLEANUP
59+
60+
# lint:ignore:140chars
6461
cron { 'Maintain PE databases' :
6562
ensure => absent,
6663
user => 'root',
6764
command => "su - pe-postgres -s /bin/bash -c '/opt/puppetlabs/server/bin/reindexdb --all; /opt/puppetlabs/server/bin/vacuumdb --analyze --verbose --all' > ${logging_directory}/output.log 2> ${logging_directory}/output_error.log",
6865
require => File[$logging_directory, $script_directory],
6966
}
67+
# lint:endignore
7068
}

manifests/postgresql_settings.pp

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1+
# Tune PostgreSQL
2+
#
3+
# @summary Tune PostgreSQL
4+
15
class pe_databases::postgresql_settings (
2-
#lint:ignore:2sp_soft_tabs
3-
Float[0,1] $autovacuum_vacuum_scale_factor = 0.08,
4-
Float[0,1] $autovacuum_analyze_scale_factor = 0.04,
5-
Integer $autovacuum_max_workers = max( 3, min( 8, $facts['processors']['count'] / 3)),
6-
Integer $log_autovacuum_min_duration = -1,
7-
Integer $log_temp_files = -1,
8-
String $work_mem = '8MB',
9-
Integer $max_connections = 1000,
10-
Hash $arbitrary_postgresql_conf_settings = {},
11-
Float[0,1] $checkpoint_completion_target = 0.9,
12-
Integer $checkpoint_segments = 128,
13-
Boolean $manage_postgresql_service = true,
14-
Boolean $all_in_one_pe_install = true,
15-
Boolean $manage_fact_values_autovacuum_cost_delay = true,
6+
# lint:ignore:140chars
7+
Float[0,1] $autovacuum_vacuum_scale_factor = 0.08,
8+
Float[0,1] $autovacuum_analyze_scale_factor = 0.04,
9+
Integer $autovacuum_max_workers = max(3, min(8, $facts['processors']['count'] / 3)),
10+
Integer $log_autovacuum_min_duration = -1,
11+
Integer $log_temp_files = -1,
12+
String $work_mem = '8MB',
13+
Integer $max_connections = 1000,
14+
Hash $arbitrary_postgresql_conf_settings = {},
15+
Float[0,1] $checkpoint_completion_target = 0.9,
16+
Integer $checkpoint_segments = 128,
17+
Boolean $manage_postgresql_service = true,
18+
Boolean $all_in_one_pe_install = true,
19+
Boolean $manage_reports_autovacuum_cost_delay = true,
1620
Optional[Float[0,1]] $factsets_autovacuum_vacuum_scale_factor = 0.80,
1721
Optional[Float[0,1]] $reports_autovacuum_vacuum_scale_factor = 0.01,
18-
Boolean $manage_reports_autovacuum_cost_delay = true,
19-
String $maintenance_work_mem = $all_in_one_pe_install ? {
20-
false => "${facts['memory']['system']['total_bytes'] / 1024 / 1024 / 3}MB",
21-
true => "${facts['memory']['system']['total_bytes'] / 1024 / 1024 / 8}MB",
22-
},
23-
String $autovacuum_work_mem = $all_in_one_pe_install ? {
24-
false => "${facts['memory']['system']['total_bytes'] / 1024 / 1024 / 3/ $autovacuum_max_workers}MB",
25-
true => "${facts['memory']['system']['total_bytes'] / 1024 / 1024 / 8/ $autovacuum_max_workers}MB",
26-
},
27-
String $psql_version = $pe_databases::psql_version,
28-
#lint:endignore
22+
String $maintenance_work_mem = $all_in_one_pe_install ? {
23+
false => "${facts['memory']['system']['total_bytes'] / 1024 / 1024 / 3}MB",
24+
true => "${facts['memory']['system']['total_bytes'] / 1024 / 1024 / 8}MB",
25+
},
26+
String $autovacuum_work_mem = $all_in_one_pe_install ? {
27+
false => "${facts['memory']['system']['total_bytes'] / 1024 / 1024 / 3 / $autovacuum_max_workers}MB",
28+
true => "${facts['memory']['system']['total_bytes'] / 1024 / 1024 / 8 / $autovacuum_max_workers}MB",
29+
},
30+
String $psql_version = $pe_databases::psql_version,
31+
# lint:endignore
2932
) {
3033

3134
$postgresql_service_resource_name = 'postgresqld'
@@ -34,7 +37,7 @@
3437
true => Service[$postgresql_service_resource_name],
3538
default => undef,
3639
}
37-
$notify_console_services = $all_in_one_pe_install ? {
40+
$notify_console_services = $all_in_one_pe_install ? {
3841
true => Service['pe-console-services'],
3942
default => undef,
4043
}
@@ -48,9 +51,10 @@
4851
}
4952
}
5053

51-
#The value attribute of postgresql_conf requires a string despite validating a float above
52-
#https://tickets.puppetlabs.com/browse/MODULES-2960
53-
#http://www.postgresql.org/docs/9.4/static/runtime-config-autovacuum.html
54+
# The value attribute of postgresql_conf requires a string despite validating a float above.
55+
# https://tickets.puppetlabs.com/browse/MODULES-2960
56+
# http://www.postgresql.org/docs/9.4/static/runtime-config-autovacuum.html
57+
5458
Postgresql_conf {
5559
ensure => present,
5660
target => "/opt/puppetlabs/server/data/postgresql/${psql_version}/data/postgresql.conf",

manifests/postgresql_settings/table_settings.pp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1+
# Tune PostgreSQL table settings
2+
#
3+
# @summary Tune PostgreSQL table settings
4+
15
class pe_databases::postgresql_settings::table_settings (
2-
Boolean $manage_fact_values_autovacuum_cost_delay = lookup('pe_databases::postgresql_settings::manage_fact_values_autovacuum_cost_delay',
3-
{'default_value' => true}),
4-
Boolean $manage_reports_autovacuum_cost_delay = lookup('pe_databases::postgresql_settings::manage_reports_autovacuum_cost_delay',
5-
{'default_value' => true}),
6-
Optional[Float[0,1]] $factsets_autovacuum_vacuum_scale_factor = lookup('pe_databases::postgresql_settings::factsets_autovacuum_vacuum_scale_factor',
7-
{'default_value' => 0.80}),
8-
Optional[Float[0,1]] $reports_autovacuum_vacuum_scale_factor = lookup('pe_databases::postgresql_settings::reports_autovacuum_vacuum_scale_factor',
9-
{'default_value' => 0.01}),
10-
Optional[Float[0,1]] $catalogs_autovacuum_vacuum_scale_factor = 0.75,
6+
# lint:ignore:140chars
7+
Boolean $manage_reports_autovacuum_cost_delay = lookup('pe_databases::postgresql_settings::manage_reports_autovacuum_cost_delay',
8+
{'default_value' => true}),
9+
Optional[Float[0,1]] $factsets_autovacuum_vacuum_scale_factor = lookup('pe_databases::postgresql_settings::factsets_autovacuum_vacuum_scale_factor',
10+
{'default_value' => 0.80}),
11+
Optional[Float[0,1]] $reports_autovacuum_vacuum_scale_factor = lookup('pe_databases::postgresql_settings::reports_autovacuum_vacuum_scale_factor',
12+
{'default_value' => 0.01}),
13+
Optional[Float[0,1]] $catalogs_autovacuum_vacuum_scale_factor = 0.75,
1114
Optional[Float[0,1]] $certnames_autovacuum_vacuum_scale_factor = 0.75,
15+
# lint:endignore
1216
) {
1317

14-
if ( versioncmp('2017.2.0', $facts['pe_server_version']) > 0 or
15-
( versioncmp('2017.3.0', $facts['pe_server_version']) <= 0 and
16-
versioncmp('2018.1.0', $facts['pe_server_version']) > 0)
17-
and $manage_fact_values_autovacuum_cost_delay ) {
18-
pe_databases::set_puppetdb_table_autovacuum_cost_delay_zero { 'fact_values' : }
18+
if $manage_reports_autovacuum_cost_delay {
19+
pe_databases::set_puppetdb_table_autovacuum_cost_delay_zero { 'reports' : }
1920
}
2021

2122
if !empty($factsets_autovacuum_vacuum_scale_factor) {
@@ -53,8 +54,4 @@
5354
table_attribute_value => sprintf('%#.2f', $certnames_autovacuum_vacuum_scale_factor),
5455
}
5556
}
56-
57-
if $manage_reports_autovacuum_cost_delay {
58-
pe_databases::set_puppetdb_table_autovacuum_cost_delay_zero { 'reports' : }
59-
}
6057
}

manifests/set_puppetdb_table_autovacuum_cost_delay_zero.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Defined type for PostgreSQL autovacuum_cost_delay
2+
#
3+
# @summary Defined type for PostgreSQL autovacuum_cost_delay
4+
15
define pe_databases::set_puppetdb_table_autovacuum_cost_delay_zero (
26
String $table_name = $title,
37
) {

manifests/set_table_attribute.pp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
# Defined type for PostgreSQL table attributes
2+
#
3+
# @summary Defined type for PostgreSQL table attributes
4+
15
define pe_databases::set_table_attribute (
26
String $db,
37
String $table_name,
48
String $table_attribute,
59
String $table_attribute_value,
610
) {
711

12+
# lint:ignore:140chars
813
postgresql_psql { "Set ${table_attribute}=${table_attribute_value} for ${table_name}" :
9-
command => "ALTER TABLE ${table_name} SET ( ${table_attribute} = ${table_attribute_value} )",
10-
unless => "SELECT reloptions FROM pg_class WHERE relname = '${table_name}' AND CAST(reloptions as text) LIKE '%${table_attribute}=${table_attribute_value}%'",
11-
db => $db,
12-
psql_user => 'pe-postgres',
13-
psql_group => 'pe-postgres',
14-
psql_path => '/opt/puppetlabs/server/bin/psql',
15-
}
14+
command => "ALTER TABLE ${table_name} SET ( ${table_attribute} = ${table_attribute_value} )",
15+
unless => "SELECT reloptions FROM pg_class WHERE relname = '${table_name}' AND CAST(reloptions as text) LIKE '%${table_attribute}=${table_attribute_value}%'",
16+
db => $db,
17+
psql_user => 'pe-postgres',
18+
psql_group => 'pe-postgres',
19+
psql_path => '/opt/puppetlabs/server/bin/psql',
20+
}
21+
# lint:endignore
1622
}

0 commit comments

Comments
 (0)