Skip to content

Add resource events to pg repack #28

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

Merged
merged 4 commits into from
Oct 30, 2019
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 .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ Rakefile:
- '2sp_soft_tabs'
- 'arrow_alignment'

.travis.yml:
includes:
- env: PUPPET_GEM_VERSION="= 4.6.1" CHECK=parallel_spec
rvm: 2.1.9
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ matrix:
-
env: DEPLOY_TO_FORGE=yes
stage: deploy
-
env: PUPPET_GEM_VERSION="= 4.6.1" CHECK=parallel_spec
rvm: 2.1.9
branches:
only:
- master
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ group :development do
gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9')
gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "puppet-module-posix-default-r#{minor_version}", '~> 0.3', require: false, platforms: [:ruby]
gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.3', require: false, platforms: [:ruby]
gem "puppet-module-win-default-r#{minor_version}", '~> 0.3', require: false, platforms: [:mswin, :mingw, :x64_mingw]
Expand Down
13 changes: 11 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ end

def changelog_project
return unless Rake.application.top_level_tasks.include? "changelog"
returnVal = nil || JSON.load(File.read('metadata.json'))['source'].match(%r{.*/([^/]*)})[1]
raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil?

returnVal = nil
returnVal ||= begin
metadata_source = JSON.load(File.read('metadata.json'))['source']
metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z})

metadata_source_match && metadata_source_match[1]
end

raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil?

puts "GitHubChangelogGenerator project:#{returnVal}"
returnVal
end
Expand Down
23 changes: 17 additions & 6 deletions manifests/maintenance/pg_repack.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,29 @@
class pe_databases::maintenance::pg_repack (
Boolean $disable_maintenance = $pe_databases::maintenance::disable_maintenance,
String $logging_directory = $pe_databases::maintenance::logging_directory,
Integer $jobs = $facts['processors']['count']/4
) {

$ensure_cron = $disable_maintenance ? {
true => absent,
default => present
}

$repack = 'su - pe-postgres -s /bin/bash -c "/opt/puppetlabs/server/apps/postgresql/bin/pg_repack -d pe-puppetdb'
#PE 2019.1 starting shipping versioned pe-postgres packages where all paths are versioned
#So prior to 2019.1 use a non-versioned path and after use a versioned path
$postgresql_version = $facts['pe_postgresql_info']['installed_server_version']
$repack_executable = versioncmp('2019.1.0', $facts['pe_server_version']) ? {
1 => '/opt/puppetlabs/server/apps/postgresql/bin/pg_repack',
default => "/opt/puppetlabs/server/apps/postgresql/${$postgresql_version}/bin/pg_repack" }

$repack = "su - pe-postgres -s /bin/bash -c \"${repack_executable} -d pe-puppetdb"
$repack_jobs = "--jobs ${jobs}"
$facts_tables = '-t factsets -t fact_paths"'
$catalogs_tables = '-t catalogs -t catalog_resources -t edges -t certnames"'
$other_tables = '-t producers -t resource_params -t resource_params_cache"'
$reports_tables = '-t reports"'
$reports_tables = versioncmp('2019.1.0', $facts['pe_server_version']) ? {
1 => '-t reports"',
default => '-t reports -t resource_events"' }
$logging = "> ${logging_directory}/output.log 2>&1"

Cron {
Expand All @@ -31,21 +42,21 @@
weekday => [2,6],
hour => 4,
minute => 30,
command => "${repack} ${facts_tables} ${logging}",
command => "${repack} ${repack_jobs} ${facts_tables} ${logging}",
}

cron { 'pg_repack catalogs tables' :
weekday => [0,4],
hour => 4,
minute => 30,
command => "${repack} ${catalogs_tables} ${logging}",
command => "${repack} ${repack_jobs} ${catalogs_tables} ${logging}",
}

cron { 'pg_repack other tables' :
monthday => 20,
hour => 5,
minute => 30,
command => "${repack} ${other_tables} ${logging}",
command => "${repack} ${repack_jobs} ${other_tables} ${logging}",
}

cron { 'pg_repack reports tables' :
Expand All @@ -54,6 +65,6 @@
monthday => 10,
hour => 5,
minute => 30,
command => "${repack} ${reports_tables} ${logging}",
command => "${repack} ${repack_jobs} ${reports_tables} ${logging}",
}
}
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"version_requirement": ">= 4.0"
}
],
"pdk-version": "1.11.1 (heads/master-0-g4f00e4a)",
"pdk-version": "1.14.0.pre (heads/master-0-g9158517)",
"template-url": "https://github.com/npwalker/pdk-templates#add_circleci_and_azure_pipelines_support",
"template-ref": "remotes/origin/add_circleci_and_azure_pipelines_support-0-gd24cef7"
"template-ref": "remotes/origin/add_circleci_and_azure_pipelines_support-0-gdc89556"
}
44 changes: 44 additions & 0 deletions spec/classes/maintenance/pg_repack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,50 @@
let(:facts) { os_facts }

it { is_expected.to compile }
context 'on PE 2019.1.0' do
before :each do
facts['pe_server_version'] = '2019.1.0'
facts['pe_postgresql_info']['installed_server_version'] = 9.6
end
it {
is_expected.to contain_cron('pg_repack reports tables')
.with_command('su - pe-postgres -s /bin/bash -c "/opt/puppetlabs/server/apps/postgresql/9.6/bin/pg_repack'\
' -d pe-puppetdb --jobs 2 -t reports -t resource_events" > /var/log/puppetlabs/pe_databases_cron/output.log 2>&1')
}
end
context 'on > PE 2019.1.0' do
before :each do
facts['pe_server_version'] = '2019.2.0'
facts['pe_postgresql_info']['installed_server_version'] = 9.6
end
it {
is_expected.to contain_cron('pg_repack reports tables')
.with_command('su - pe-postgres -s /bin/bash -c "/opt/puppetlabs/server/apps/postgresql/9.6/bin/pg_repack'\
' -d pe-puppetdb --jobs 2 -t reports -t resource_events" > /var/log/puppetlabs/pe_databases_cron/output.log 2>&1')
}
end
context 'on < PE 2019.1.0' do
before :each do
facts['pe_server_version'] = '2019.0.0'
facts['pe_postgresql_info']['installed_server_version'] = 9.6
end
it {
is_expected.to contain_cron('pg_repack reports tables')
.with_command('su - pe-postgres -s /bin/bash -c "/opt/puppetlabs/server/apps/postgresql/bin/pg_repack'\
' -d pe-puppetdb --jobs 2 -t reports" > /var/log/puppetlabs/pe_databases_cron/output.log 2>&1')
}
end
context 'on > PE 2019.1.0 with postgresql 11' do
before :each do
facts['pe_server_version'] = '2019.2.0'
facts['pe_postgresql_info']['installed_server_version'] = 11
end
it {
is_expected.to contain_cron('pg_repack reports tables')
.with_command('su - pe-postgres -s /bin/bash -c "/opt/puppetlabs/server/apps/postgresql/11/bin/pg_repack'\
' -d pe-puppetdb --jobs 2 -t reports -t resource_events" > /var/log/puppetlabs/pe_databases_cron/output.log 2>&1')
}
end
end
end
end
2 changes: 2 additions & 0 deletions spec/default_facts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ memory:
total_bytes: 17179869184
processors:
count: 8
pe_postgresql_info:
installed_server_version: 9.6