Skip to content

Commit cb76627

Browse files
committed
(SUP-3972) Add activity tables to repack
This commit adds a new service and timer to repack tables in the pe-activity database. It also moves a few parameters to module data.
1 parent f1f19d5 commit cb76627

File tree

7 files changed

+87
-24
lines changed

7 files changed

+87
-24
lines changed

data/common.yaml

Lines changed: 24 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
# @param reports_tables_repack_timer [String] Deprecated Parameter will be removed in future releases
1515
# @param resource_events_tables_repack_timer [String] Deprecated Parameter will be removed in future releases
1616
class pe_databases (
17+
# Provided by module data
18+
String[1] $facts_tables_repack_timer,
19+
String[1] $catalogs_tables_repack_timer,
20+
String[1] $other_tables_repack_timer,
21+
String[1] $activity_tables_repack_timer,
1722
Boolean $manage_database_maintenance = true,
1823
Boolean $disable_maintenance = false,
1924
Optional[Boolean] $manage_postgresql_settings = undef,
2025
Optional[Boolean] $manage_table_settings = undef,
2126
String[1] $install_dir = '/opt/puppetlabs/pe_databases',
2227
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',
2628
Optional[String] $reports_tables_repack_timer = undef,
2729
Optional[String] $resource_events_tables_repack_timer = undef,
2830
) {

manifests/pg_repack.pp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Maintenance pg_repack
22
#
33
# @summary
4-
# Provides systemd timers to pg_repack tables in the pe-puppetdb database
4+
# Provides systemd timers to pg_repack tables in a given database
55
#
66
# @param disable_maintenance [Boolean] true or false (Default: false)
77
# Disable or enable maintenance mode
@@ -12,12 +12,18 @@
1212
# @param reports_tables_repack_timer [String] Deprecated Parameter will be removed in future releases
1313
# @param resource_events_tables_repack_timer [String] Deprecated Parameter will be removed in future releases
1414
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,
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+
String[1] $activity_tables_repack_timer = $pe_databases::activity_tables_repack_timer,
21+
# Provided by module data
22+
Array $fact_tables,
23+
Array $catalog_tables,
24+
Array $other_tables,
25+
Array $activity_tables,
26+
Optional[String] $reports_tables_repack_timer = undef,
2127
Optional[String] $resource_events_tables_repack_timer = undef,
2228
) {
2329
puppet_enterprise::deprecated_parameter { 'pe_databases::pg_repack::reports_tables_repack_timer': }
@@ -26,28 +32,34 @@
2632
$postgresql_version = $facts['pe_postgresql_info']['installed_server_version']
2733
$repack_executable = "/opt/puppetlabs/server/apps/postgresql/${postgresql_version}/bin/pg_repack"
2834

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'
35+
$repack_cmd = "${repack_executable} --jobs ${jobs}"
3436

3537
pe_databases::collect { 'facts':
3638
disable_maintenance => $disable_maintenance,
37-
command => "${repack_cmd} ${fact_tables}",
39+
command => "${repack_cmd} -d pe-puppetdb",
3840
on_cal => $facts_tables_repack_timer,
41+
tables => $fact_tables,
3942
}
4043

4144
pe_databases::collect { 'catalogs':
4245
disable_maintenance => $disable_maintenance,
43-
command => "${repack_cmd} ${catalog_tables}",
46+
command => "${repack_cmd} -d pe-puppetdb",
4447
on_cal => $catalogs_tables_repack_timer,
48+
tables => $catalog_tables,
4549
}
4650

4751
pe_databases::collect { 'other':
4852
disable_maintenance => $disable_maintenance,
49-
command => "${repack_cmd} ${other_tables}",
53+
command => "${repack_cmd} -d pe-puppetdb",
5054
on_cal => $other_tables_repack_timer,
55+
tables => $other_tables,
56+
}
57+
58+
pe_databases::collect { 'activity':
59+
disable_maintenance => $disable_maintenance,
60+
command => "${repack_cmd} -d pe-activity",
61+
on_cal => $activity_tables_repack_timer,
62+
tables => $activity_tables,
5163
}
5264

5365
# Ensure legacy vaccum and pg_repack crons are purged.

spec/classes/pg_repack_spec.rb

Lines changed: 12 additions & 4 deletions
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

Lines changed: 3 additions & 1 deletion
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)