3 changes: 2 additions & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
fixtures:
repositories:
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib"
postgresql: "git://github.com/puppetlabs/puppetlabs-postgresql"
postgresql: "git://github.com/puppetlabs/puppetlabs-postgresql"
cron_core: "git://github.com/puppetlabs/puppetlabs-cron_core"
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.rb eol=lf
*.erb eol=lf
*.pp eol=lf
*.sh eol=lf
*.epp eol=lf
13 changes: 13 additions & 0 deletions .pdkignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,16 @@
/convert_report.txt
/update_report.txt
.DS_Store
/appveyor.yml
/.fixtures.yml
/Gemfile
/.gitattributes
/.gitignore
/.gitlab-ci.yml
/.pdkignore
/Rakefile
/.rspec
/.rubocop.yml
/.travis.yml
/.yardopts
/spec/
3 changes: 3 additions & 0 deletions .puppet-lint.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--relative
--no-2sp_soft_tabs-check
--no-arrow_alignment-check
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ AllCops:
Metrics/LineLength:
Description: People have wide screens, use them.
Max: 200
GetText/DecorateString:
Description: We don't want to decorate test output.
Exclude:
- spec/*
RSpec/BeforeAfterAll:
Description: Beware of using after(:all) as it may cause state to leak between tests.
A necessary evil in acceptance testing.
Expand Down Expand Up @@ -82,6 +86,8 @@ Style/StringMethods:
Enabled: true
Layout/EndOfLine:
Enabled: false
Layout/IndentHeredoc:
Enabled: false
Metrics/AbcSize:
Enabled: false
Metrics/BlockLength:
Expand Down
15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
---
sudo: false
dist: trusty
language: ruby
cache: bundler
before_install:
- if [ $BUNDLER_VERSION ]; then
gem install -v $BUNDLER_VERSION bundler --no-rdoc --no-ri;
fi
- bundle -v
- rm -f Gemfile.lock
- gem update --system
- gem update --system $RUBYGEMS_VERSION
- gem --version
- bundle -v
script:
- 'bundle exec rake $CHECK'
bundler_args: --without system_tests
rvm:
- 2.4.1
- 2.5.1
env:
global:
- BEAKER_PUPPET_COLLECTION=puppet5 PUPPET_GEM_VERSION="~> 5.0"
- BEAKER_PUPPET_COLLECTION=puppet6 PUPPET_GEM_VERSION="~> 6.0"
matrix:
fast_finish: true
include:
Expand All @@ -25,7 +27,10 @@ matrix:
-
env: CHECK=parallel_spec
-
env: PUPPET_GEM_VERSION="~> 4.0" CHECK=parallel_spec
env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec
rvm: 2.4.4
-
env: PUPPET_GEM_VERSION="~> 4.0" CHECK=parallel_spec RUBYGEMS_VERSION=2.7.8 BUNDLER_VERSION=1.17.3
rvm: 2.1.9
branches:
only:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## Minor Release 0.15.0

- Make pg_repack the default way to perform maintenance [#25](https://github.com/npwalker/pe_databases/pull/25)
- Start maintaining the reports table which we could not afford to perform a VACUUM FULL on
- Rename typoed `pe_databases::maintenance::disable_maintenace` parameter to `pe_databases::maintenance::disable_maintenance`

## Z Release 0.14.2
- Allow not managing table settings [#21](https://github.com/npwalker/pe_databases/pull/21)

## Z Release 0.14.1

- Set permissions on pe_databases directories [#18](https://github.com/npwalker/pe_databases/pull/18)
Expand Down
25 changes: 9 additions & 16 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

def location_for(place_or_version, fake_version = nil)
if place_or_version =~ %r{\A(git[:@][^#]*)#(.*)}
[fake_version, { git: Regexp.last_match(1), branch: Regexp.last_match(2), require: false }].compact
elsif place_or_version =~ %r{\Afile:\/\/(.*)}
['>= 0', { path: File.expand_path(Regexp.last_match(1)), require: false }]
else
[place_or_version, { require: false }]
end
end
git_url_regex = %r{\A(?<url>(https?|git)[:@][^#]*)(#(?<branch>.*))?}
file_url_regex = %r{\Afile:\/\/(?<path>.*)}

def gem_type(place_or_version)
if place_or_version =~ %r{\Agit[:@]}
:git
elsif !place_or_version.nil? && place_or_version.start_with?('file:')
:file
if place_or_version && (git_url = place_or_version.match(git_url_regex))
[fake_version, { git: git_url[:url], branch: git_url[:branch], require: false }].compact
elsif place_or_version && (file_url = place_or_version.match(file_url_regex))
['>= 0', { path: File.expand_path(file_url[:path]), require: false }]
else
:gem
[place_or_version, { require: false }]
end
end

Expand All @@ -28,15 +21,15 @@ group :development do
gem "fast_gettext", require: false if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0')
gem "json_pure", '<= 2.0.1', require: false if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
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::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.4.4')
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 "puppet-module-posix-default-r#{minor_version}", require: false, platforms: [:ruby]
gem "puppet-module-posix-dev-r#{minor_version}", require: false, platforms: [:ruby]
gem "puppet-module-win-default-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "puppet-module-win-dev-r#{minor_version}", require: false, platforms: [:mswin, :mingw, :x64_mingw]
end

puppet_version = ENV['PUPPET_GEM_VERSION']
puppet_type = gem_type(puppet_version)
facter_version = ENV['FACTER_GEM_VERSION']
hiera_version = ENV['HIERA_GEM_VERSION']

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ By default you get the following:

In order to use this module, you will classify the node running pe-postgresql with the `pe_databases` class. This is the MoM in a monolithic installation or the PuppetDB node in a Split/LEI install.

To classify via the PE console, you will create a new node group called 'PE Database' and pin the node running pe-postgresql to the group. It is not recommended to classify using a pre-existing node group in the PE console.
To classify via the PE console, you will create a new node group called "PE Database Maintenance". Then pin the node running pe-postgresql to this group. It is not recommended to classify using a pre-existing node group in the PE console.

## Items you may want to configure

Expand Down
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-syntax/tasks/puppet-syntax'
require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any?
require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any?
require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any?

def changelog_user
return unless Rake.application.top_level_tasks.include? "changelog"
returnVal = nil || JSON.load(File.read('metadata.json'))['author']
raise "unable to find the changelog_user in .sync.yml, or the author in metadata.json" if returnVal.nil?
puts "GitHubChangelogGenerator user:#{returnVal}"
returnVal
end

def changelog_project
return unless Rake.application.top_level_tasks.include? "changelog"
returnVal = nil || JSON.load(File.read('metadata.json'))['name']
raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil?
puts "GitHubChangelogGenerator project:#{returnVal}"
returnVal
end

def changelog_future_release
return unless Rake.application.top_level_tasks.include? "changelog"
returnVal = JSON.load(File.read('metadata.json'))['version']
raise "unable to find the future_release (version) in metadata.json" if returnVal.nil?
puts "GitHubChangelogGenerator future_release:#{returnVal}"
Expand All @@ -30,7 +34,7 @@ PuppetLint.configuration.send('disable_arrow_alignment')

if Bundler.rubygems.find_name('github_changelog_generator').any?
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if ENV['CHANGELOG_GITHUB_TOKEN'].nil?
raise "Set CHANGELOG_GITHUB_TOKEN environment variable eg 'export CHANGELOG_GITHUB_TOKEN=valid_token_here'" if Rake.application.top_level_tasks.include? "changelog" and ENV['CHANGELOG_GITHUB_TOKEN'].nil?
config.user = "#{changelog_user}"
config.project = "#{changelog_project}"
config.future_release = "#{changelog_future_release}"
Expand Down
82 changes: 14 additions & 68 deletions manifests/maintenance.pp
Original file line number Diff line number Diff line change
@@ -1,79 +1,25 @@
class pe_databases::maintenance (
Boolean $disable_maintenace = false,
Optional[Integer] $maint_cron_weekday = undef, #DEPRECATED
Optional[Integer] $maint_cron_hour = undef, #DEPRECATED
Optional[Integer] $maint_cron_minute = undef, #DEPRECATED
Boolean $disable_maintenance = false,
String $logging_directory = '/var/log/puppetlabs/pe_databases_cron',
String $script_directory = $pe_databases::scripts_dir,
){

$ensure_cron = $disable_maintenace ? {
true => absent,
default => present
#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
if ( versioncmp( '2018.1.7', $facts['pe_server_version']) <= 0 and versioncmp($facts['pe_server_version'], '2019.0.0') < 0 ) {
include pe_databases::maintenance::pg_repack
class { 'pe_databases::maintenance::vacuum_full':
disable_maintenance => true,
}
} elsif ( versioncmp( '2019.0.2', $facts['pe_server_version']) <= 0 ) {
include pe_databases::maintenance::pg_repack
class { 'pe_databases::maintenance::vacuum_full':
disable_maintenance => true,
}
} else {
include pe_databases::maintenance::vacuum_full
}

file { $logging_directory :
ensure => directory,
}

$vacuum_script_path = "${script_directory}/vacuum_full_tables.sh"

file { $vacuum_script_path:
ensure => file,
source => 'puppet:///modules/pe_databases/vacuum_full_tables.sh',
owner => 'pe-postgres',
group => 'pe-postgres',
mode => '0744',
}

cron { 'VACUUM FULL facts tables' :
ensure => $ensure_cron,
user => 'root',
weekday => [2,6],
hour => 4,
minute => 30,
command => "${vacuum_script_path} facts",
require => File[$logging_directory, $script_directory],
}

cron { 'VACUUM FULL catalogs tables' :
ensure => $ensure_cron,
user => 'root',
weekday => [0,4],
hour => 4,
minute => 30,
command => "${vacuum_script_path} catalogs",
require => File[$logging_directory, $script_directory],
}

cron { 'VACUUM FULL other tables' :
ensure => $ensure_cron,
user => 'root',
monthday => 20,
hour => 5,
minute => 30,
command => "${vacuum_script_path} other",
require => File[$logging_directory, $script_directory],
}

#Remove old versions of maintenance cron jobs
cron { 'Maintain PE databases' :
ensure => absent,
user => 'root',
weekday => $maint_cron_weekday,
hour => $maint_cron_hour,
minute => $maint_cron_minute,
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",
require => File[$logging_directory, $script_directory],
}

if empty($maint_cron_weekday) == false {
warning('pe_databases::maintenance::maint_cron_weekday is deprecated and will be removed in a future release')
}
if empty($maint_cron_hour) == false {
warning('pe_databases::maintenance::maint_cron_hour is deprecated and will be removed in a future release')
}
if empty($maint_cron_minute) == false {
warning('pe_databases::maintenance::maint_cron_minute is deprecated and will be removed in a future release')
}
}
59 changes: 59 additions & 0 deletions manifests/maintenance/pg_repack.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# A description of what this class does
#
# @summary A short summary of the purpose of this class
#
# @example
# include pe_databases::maintenance::pg_repack
class pe_databases::maintenance::pg_repack (
Boolean $disable_maintenance = $pe_databases::maintenance::disable_maintenance,
String $logging_directory = $pe_databases::maintenance::logging_directory,
) {

$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'
$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"'
$logging = "> ${logging_directory}/output.log 2>&1"

Cron {
ensure => $ensure_cron,
user => 'root',
require => File[$logging_directory],
}

cron { 'pg_repack facts tables' :
weekday => [2,6],
hour => 4,
minute => 30,
command => "${repack} ${facts_tables} ${logging}",
}

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

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

cron { 'pg_repack reports tables' :
ensure => $ensure_cron,
user => 'root',
monthday => 10,
hour => 5,
minute => 30,
command => "${repack} ${reports_tables} ${logging}",
}
}
Loading