Skip to content

Commit

Permalink
Merge pull request #126 from Aaronoftheages/SUP-4666_pg_repack_enable…
Browse files Browse the repository at this point in the history
…_debug_mode

(SUP-4666) Pe_databases: pg_repack enable debug mode
  • Loading branch information
MartyEwings authored Jan 31, 2024
2 parents 7d95c01 + 4a40130 commit a3a5d9b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 18 deletions.
26 changes: 26 additions & 0 deletions data/rspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pe_databases::facts_tables_repack_timer:
'Tue,Sat *-*-* 04:30:00'
pe_databases::catalogs_tables_repack_timer:
'Sun,Thu *-*-* 04:30:00'
pe_databases::other_tables_repack_timer:
'*-*-20 05:30:00'
pe_databases::activity_tables_repack_timer:
'Wed,Fri *-*-* 04:30:00'
pe_databases::pg_repack::fact_tables:
- factsets
- fact_paths
pe_databases::pg_repack::catalog_tables:
- catalogs
- catalog_resources
- catalog_inputs
- edges
- certnames
pe_databases::pg_repack::other_tables:
- producers
- resource_params
- resource_params_cache
pe_databases::pg_repack::activity_tables:
- events
- event_commits
pe_databases::pg_repack::repack_log_level: 'INFO'
pe_databases::pg_repack::enable_echo: false
10 changes: 10 additions & 0 deletions hiera-rspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
version: 5

defaults: # Used for any hierarchy level that omits these keys.
datadir: data # This path is relative to hiera.yaml's directory.
data_hash: yaml_data # Use the built-in YAML backend.

hierarchy:
- name: 'rspec'
path: 'rspec.yaml'
11 changes: 10 additions & 1 deletion manifests/pg_repack.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
# @param activity_tables [Array] Array of 'activity' tables to repack
# @param disable_maintenance [Boolean] true or false (Default: false)
# Disable or enable maintenance mode
# @param repack_log_level [Enum] Desired output level of logs
# @param enable_echo [Boolean] true or false (Default: true)
# Enabling echo output in logs
# @param jobs [Integer] How many jobs to run in parallel
# @param facts_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'facts' tables
# @param catalogs_tables_repack_timer [String]The Systemd timer for the pg_repack job affecting the 'catalog' tables
Expand All @@ -22,6 +25,8 @@
Array $other_tables,
Array $activity_tables,
Boolean $disable_maintenance = false,
Enum['INFO','NOTICE','WARNING','ERROR','LOG','FATAL','PANIC','DEBUG'] $repack_log_level='DEBUG',
Boolean $enable_echo = true,
Integer $jobs = $facts['processors']['count'] / 4,
String[1] $facts_tables_repack_timer = $pe_databases::facts_tables_repack_timer,
String[1] $catalogs_tables_repack_timer = $pe_databases::catalogs_tables_repack_timer,
Expand All @@ -36,7 +41,11 @@
$postgresql_version = $facts['pe_postgresql_info']['installed_server_version']
$repack_executable = "/opt/puppetlabs/server/apps/postgresql/${postgresql_version}/bin/pg_repack"

$repack_cmd = "${repack_executable} --jobs ${jobs}"
if $enable_echo {
$repack_cmd = "${repack_executable} --jobs ${jobs} --elevel ${repack_log_level} --echo"
} else {
$repack_cmd = "${repack_executable} --jobs ${jobs} --elevel ${repack_log_level}"
}

pe_databases::collect { 'facts':
disable_maintenance => $disable_maintenance,
Expand Down
43 changes: 26 additions & 17 deletions spec/classes/pg_repack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,28 @@
}
}
end
let(:pre_condition) do
<<-PRE_COND
define puppet_enterprise::deprecated_parameter() {}
include pe_databases
PRE_COND
end

on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:pre_condition) do
<<-PRE_COND
define puppet_enterprise::deprecated_parameter() {}
include pe_databases
PRE_COND
end
let(:facts) { os_facts }

it { is_expected.to compile }
end
end

context 'with default parameters' do
let(:pre_condition) do
<<-PRE_COND
define puppet_enterprise::deprecated_parameter() {}
include pe_databases
PRE_COND
end

it {
tables_hash.each do |name, val|
is_expected.to contain_pe_databases__collect(name).with(
disable_maintenance: false,
command: "#{repack_cmd} #{val[:database]}",
command: "#{repack_cmd} --elevel DEBUG --echo #{val[:database]}",
# Strip the backslash character because this is not a regex
on_cal: (val[:schedule]).to_s.tr('\\', ''),
)
Expand All @@ -66,7 +58,7 @@

is_expected.to contain_file("/etc/systemd/system/pe_databases-#{name}.timer").with_content(%r{OnCalendar=#{val[:schedule]}})
is_expected.to contain_file("/etc/systemd/system/pe_databases-#{name}.service").with_content(
%r{ExecStart=#{repack_cmd} #{val[:database]} #{val[:tables]}},
%r{ExecStart=#{repack_cmd} --elevel DEBUG --echo #{val[:database]} #{val[:tables]}},
)

[
Expand Down Expand Up @@ -103,4 +95,21 @@ class {'pe_databases': facts_tables_repack_timer => 'Tue *-*-* 04:20:00'}
)
}
end

context 'when customizing log parameters' do
# Load the rspec hieradata. This data sets repack_log_level: 'INFO' and enable_echo: false
let(:hiera_config) { 'hiera-rspec.yaml' }

it {
# The command should have --elevel INFO and not contain --echo according to the hieradata
is_expected.to contain_pe_databases__collect('facts').with(
command: "#{repack_cmd} --elevel INFO #{tables_hash[:facts][:database]}",
)

# The service file should have --elevel INFO and not contain --echo according to the hieradata
is_expected.to contain_file('/etc/systemd/system/pe_databases-facts.service').with_content(
%r{ExecStart=#{repack_cmd} --elevel INFO #{tables_hash[:facts][:database]} #{tables_hash[:facts][:tables]}},
)
}
end
end

0 comments on commit a3a5d9b

Please sign in to comment.