Skip to content

Commit 6bc89cc

Browse files
authored
Merge pull request #123 from m0dular/SUP-3972-activity_tables
(SUP-3972) Add activity tables to repack
2 parents f1f19d5 + cb7fc90 commit 6bc89cc

File tree

7 files changed

+95
-27
lines changed

7 files changed

+95
-27
lines changed

data/common.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
pe_databases::facts_tables_repack_timer:
2+
'Tue,Sat *-*-* 04:30:00'
3+
pe_databases::catalogs_tables_repack_timer:
4+
'Sun,Thu *-*-* 04:30:00'
5+
pe_databases::other_tables_repack_timer:
6+
'*-*-20 05:30:00'
7+
pe_databases::activity_tables_repack_timer:
8+
'Wed,Fri *-*-* 04:30:00'
9+
pe_databases::pg_repack::fact_tables:
10+
- factsets
11+
- fact_paths
12+
pe_databases::pg_repack::catalog_tables:
13+
- catalogs
14+
- catalog_resources
15+
- catalog_inputs
16+
- edges
17+
- certnames
18+
pe_databases::pg_repack::other_tables:
19+
- producers
20+
- resource_params
21+
- resource_params_cache
22+
pe_databases::pg_repack::activity_tables:
23+
- events
24+
- event_commits

hiera.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
version: 5
3+
4+
defaults: # Used for any hierarchy level that omits these keys.
5+
datadir: data # This path is relative to hiera.yaml's directory.
6+
data_hash: yaml_data # Use the built-in YAML backend.
7+
8+
hierarchy:
9+
- name: 'common'
10+
path: 'common.yaml'

manifests/collect.pp

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
# @param command [String] defined in pg_repack.pp
44
# @param disable_maintenance [Boolean] to disable maintenance mode (Default: false)
55
# @param on_cal [String] values can be found in pg_repack.pp
6-
#
6+
# @param tables [Array] Array of tables to repack
77
define pe_databases::collect (
88
String $database_type = $title,
99
String $command = undef,
1010
Boolean $disable_maintenance = false,
1111
String $on_cal = undef,
12+
Array $tables = undef,
1213
) {
1314
Service {
1415
notify => Exec['pe_databases_daemon_reload'],
@@ -27,9 +28,13 @@
2728
default => present
2829
}
2930

31+
$tables_command = $tables.map |$table| { "-t ${table}" }.join(' ')
32+
33+
$repack_command = "${command} ${tables_command}"
34+
3035
file { "/etc/systemd/system/pe_databases-${database_type}.service":
3136
ensure => $ensure_file,
32-
content => epp('pe_databases/service.epp', { 'tables' => $database_type, 'command' => $command }),
37+
content => epp('pe_databases/service.epp', { 'tables' => $database_type, 'command' => $repack_command }),
3338
}
3439
file { "/etc/systemd/system/pe_databases-${database_type}.timer":
3540
ensure => $ensure_file,

manifests/init.pp

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@
99
# @param facts_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'facts' tables
1010
# @param catalogs_tables_repack_timer [String]The Systemd timer for the pg_repack job affecting the 'catalog' tables
1111
# @param other_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'other' tables
12+
# @param activity_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'activity' tables
1213
# @param manage_postgresql_settings [Boolean] Deprecated Parameter will be removed in future releases
1314
# @param manage_table_settings [Boolean] Deprecated Parameter will be removed in future releases
1415
# @param reports_tables_repack_timer [String] Deprecated Parameter will be removed in future releases
1516
# @param resource_events_tables_repack_timer [String] Deprecated Parameter will be removed in future releases
1617
class pe_databases (
18+
# Provided by module data
19+
String[1] $facts_tables_repack_timer,
20+
String[1] $catalogs_tables_repack_timer,
21+
String[1] $other_tables_repack_timer,
22+
String[1] $activity_tables_repack_timer,
1723
Boolean $manage_database_maintenance = true,
1824
Boolean $disable_maintenance = false,
1925
Optional[Boolean] $manage_postgresql_settings = undef,
2026
Optional[Boolean] $manage_table_settings = undef,
2127
String[1] $install_dir = '/opt/puppetlabs/pe_databases',
2228
String[1] $scripts_dir = "${install_dir}/scripts",
23-
String[1] $facts_tables_repack_timer = 'Tue,Sat *-*-* 04:30:00',
24-
String[1] $catalogs_tables_repack_timer = 'Sun,Thu *-*-* 04:30:00',
25-
String[1] $other_tables_repack_timer = '*-*-20 05:30:00',
2629
Optional[String] $reports_tables_repack_timer = undef,
2730
Optional[String] $resource_events_tables_repack_timer = undef,
2831
) {

manifests/pg_repack.pp

+33-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
# Maintenance pg_repack
22
#
3-
# @summary
4-
# Provides systemd timers to pg_repack tables in the pe-puppetdb database
5-
#
3+
# @summary
4+
# Provides systemd timers to pg_repack tables in a given database
5+
# @param fact_tables [Array] Array of 'fact' tables to repack
6+
# @param catalog_tables [Array] Array of 'catalog' tables to repack
7+
# @param other_tables [Array] Array of 'other' tables to repack
8+
# @param activity_tables [Array] Array of 'activity' tables to repack
69
# @param disable_maintenance [Boolean] true or false (Default: false)
710
# Disable or enable maintenance mode
811
# @param jobs [Integer] How many jobs to run in parallel
912
# @param facts_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'facts' tables
1013
# @param catalogs_tables_repack_timer [String]The Systemd timer for the pg_repack job affecting the 'catalog' tables
1114
# @param other_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'other' tables
15+
# @param activity_tables_repack_timer [String] The Systemd timer for the pg_repack job affecting the 'activity' tables
1216
# @param reports_tables_repack_timer [String] Deprecated Parameter will be removed in future releases
1317
# @param resource_events_tables_repack_timer [String] Deprecated Parameter will be removed in future releases
1418
class pe_databases::pg_repack (
15-
Boolean $disable_maintenance = false,
16-
Integer $jobs = $facts['processors']['count'] / 4,
17-
String[1] $facts_tables_repack_timer = $pe_databases::facts_tables_repack_timer,
18-
String[1] $catalogs_tables_repack_timer = $pe_databases::catalogs_tables_repack_timer,
19-
String[1] $other_tables_repack_timer = $pe_databases::other_tables_repack_timer,
20-
Optional[String] $reports_tables_repack_timer = undef,
19+
# Provided by module data
20+
Array $fact_tables,
21+
Array $catalog_tables,
22+
Array $other_tables,
23+
Array $activity_tables,
24+
Boolean $disable_maintenance = false,
25+
Integer $jobs = $facts['processors']['count'] / 4,
26+
String[1] $facts_tables_repack_timer = $pe_databases::facts_tables_repack_timer,
27+
String[1] $catalogs_tables_repack_timer = $pe_databases::catalogs_tables_repack_timer,
28+
String[1] $other_tables_repack_timer = $pe_databases::other_tables_repack_timer,
29+
String[1] $activity_tables_repack_timer = $pe_databases::activity_tables_repack_timer,
30+
Optional[String] $reports_tables_repack_timer = undef,
2131
Optional[String] $resource_events_tables_repack_timer = undef,
2232
) {
2333
puppet_enterprise::deprecated_parameter { 'pe_databases::pg_repack::reports_tables_repack_timer': }
@@ -26,28 +36,34 @@
2636
$postgresql_version = $facts['pe_postgresql_info']['installed_server_version']
2737
$repack_executable = "/opt/puppetlabs/server/apps/postgresql/${postgresql_version}/bin/pg_repack"
2838

29-
$repack_cmd = "${repack_executable} -d pe-puppetdb --jobs ${jobs}"
30-
31-
$fact_tables = '-t factsets -t fact_paths'
32-
$catalog_tables = '-t catalogs -t catalog_resources -t catalog_inputs -t edges -t certnames'
33-
$other_tables = '-t producers -t resource_params -t resource_params_cache'
39+
$repack_cmd = "${repack_executable} --jobs ${jobs}"
3440

3541
pe_databases::collect { 'facts':
3642
disable_maintenance => $disable_maintenance,
37-
command => "${repack_cmd} ${fact_tables}",
43+
command => "${repack_cmd} -d pe-puppetdb",
3844
on_cal => $facts_tables_repack_timer,
45+
tables => $fact_tables,
3946
}
4047

4148
pe_databases::collect { 'catalogs':
4249
disable_maintenance => $disable_maintenance,
43-
command => "${repack_cmd} ${catalog_tables}",
50+
command => "${repack_cmd} -d pe-puppetdb",
4451
on_cal => $catalogs_tables_repack_timer,
52+
tables => $catalog_tables,
4553
}
4654

4755
pe_databases::collect { 'other':
4856
disable_maintenance => $disable_maintenance,
49-
command => "${repack_cmd} ${other_tables}",
57+
command => "${repack_cmd} -d pe-puppetdb",
5058
on_cal => $other_tables_repack_timer,
59+
tables => $other_tables,
60+
}
61+
62+
pe_databases::collect { 'activity':
63+
disable_maintenance => $disable_maintenance,
64+
command => "${repack_cmd} -d pe-activity",
65+
on_cal => $activity_tables_repack_timer,
66+
tables => $activity_tables,
5167
}
5268

5369
# Ensure legacy vaccum and pg_repack crons are purged.

spec/classes/pg_repack_spec.rb

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,28 @@
22

33
describe 'pe_databases::pg_repack' do
44
let(:facts) { { processors: { count: 4 } } }
5-
let(:repack_cmd) { '/opt/puppetlabs/server/apps/postgresql/11/bin/pg_repack -d pe-puppetdb --jobs 1' }
5+
let(:repack_cmd) { '/opt/puppetlabs/server/apps/postgresql/11/bin/pg_repack --jobs 1' }
66
let(:tables_hash) do
77
{
88
facts: {
99
tables: '-t factsets -t fact_paths',
10-
schedule: 'Tue,Sat \*-\*-\* 04:30:00'
10+
schedule: 'Tue,Sat \*-\*-\* 04:30:00',
11+
database: '-d pe-puppetdb',
1112
},
1213
catalogs: {
1314
tables: '-t catalogs -t catalog_resources -t catalog_inputs -t edges -t certnames',
1415
schedule: 'Sun,Thu \*-\*-\* 04:30:00',
16+
database: '-d pe-puppetdb',
1517
},
1618
other: {
1719
tables: '-t producers -t resource_params -t resource_params_cache',
1820
schedule: '\*-\*-20 05:30:00',
21+
database: '-d pe-puppetdb',
22+
},
23+
activity: {
24+
tables: '-t events -t event_commits',
25+
schedule: 'Wed,Fri \*-\*-\* 04:30:00',
26+
database: '-d pe-activity',
1927
}
2028
}
2129
end
@@ -48,7 +56,7 @@
4856
tables_hash.each do |name, val|
4957
is_expected.to contain_pe_databases__collect(name).with(
5058
disable_maintenance: false,
51-
command: "#{repack_cmd} #{val[:tables]}",
59+
command: "#{repack_cmd} #{val[:database]}",
5260
# Strip the backslash character because this is not a regex
5361
on_cal: (val[:schedule]).to_s.tr('\\', ''),
5462
)
@@ -58,7 +66,7 @@
5866

5967
is_expected.to contain_file("/etc/systemd/system/pe_databases-#{name}.timer").with_content(%r{OnCalendar=#{val[:schedule]}})
6068
is_expected.to contain_file("/etc/systemd/system/pe_databases-#{name}.service").with_content(
61-
%r{ExecStart=#{repack_cmd} #{val[:tables]}},
69+
%r{ExecStart=#{repack_cmd} #{val[:database]} #{val[:tables]}},
6270
)
6371

6472
[

spec/defines/collect_spec.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
{
1414
command: 'foo',
1515
on_cal: 'bar',
16+
tables: ['baz'],
1617
}
1718
end
1819

@@ -22,7 +23,7 @@
2223

2324
is_expected.to contain_file('/etc/systemd/system/pe_databases-test.timer').with_content(%r{bar})
2425
is_expected.to contain_file('/etc/systemd/system/pe_databases-test.service').with_content(
25-
%r{ExecStart=foo},
26+
%r{ExecStart=foo.*-t baz},
2627
)
2728

2829
is_expected.to contain_service('pe_databases-test.service').that_notifies(
@@ -47,6 +48,7 @@
4748
disable_maintenance: true,
4849
command: 'foo',
4950
on_cal: 'bar',
51+
tables: ['baz'],
5052
}
5153
end
5254

0 commit comments

Comments
 (0)