Skip to content

Commit 69176e0

Browse files
authored
Merge pull request #501 from cultuurnet/feature/OPS-1279
Add log_volume_size parameter and log volume declarations to ElasticSearch profile
2 parents 94cc671 + 96642ea commit 69176e0

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

manifests/elasticsearch.pp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Boolean $lvm = false,
99
Optional[String] $volume_group = undef,
1010
Optional[String] $volume_size = undef,
11+
Optional[String] $log_volume_size = undef,
1112
String $initial_heap_size = '512m',
1213
String $maximum_heap_size = '512m',
1314
Boolean $backup = true,
@@ -25,6 +26,7 @@
2526
}
2627

2728
$datadir = '/var/lib/elasticsearch'
29+
$logdir = '/var/log/elasticsearch'
2830

2931
contain ::profiles::java
3032

@@ -56,6 +58,36 @@
5658
require => [Profiles::Lvm::Mount['elasticsearchdata'], File[$datadir]],
5759
before => Class['elasticsearch']
5860
}
61+
62+
if $log_volume_size {
63+
profiles::lvm::mount { 'elasticsearchlogs':
64+
volume_group => $volume_group,
65+
size => $log_volume_size,
66+
mountpoint => '/data/elasticsearchlogs',
67+
fs_type => 'ext4',
68+
owner => 'elasticsearch',
69+
group => 'elasticsearch',
70+
require => [Group['elasticsearch'], User['elasticsearch']],
71+
before => Class['::elasticsearch']
72+
}
73+
74+
file { $logdir:
75+
ensure => 'directory',
76+
owner => 'elasticsearch',
77+
group => 'elasticsearch',
78+
require => [Group['elasticsearch'], User['elasticsearch']],
79+
before => Class['elasticsearch']
80+
}
81+
82+
mount { $logdir:
83+
ensure => 'mounted',
84+
device => '/data/elasticsearchlogs',
85+
fstype => 'none',
86+
options => 'rw,bind',
87+
require => [Profiles::Lvm::Mount['elasticsearchlogs'], File[$logdir]],
88+
before => Class['elasticsearch']
89+
}
90+
}
5991
}
6092

6193
file { $datadir:
@@ -149,6 +181,10 @@
149181
restart_on_change => true,
150182
datadir => $datadir,
151183
manage_datadir => false,
184+
manage_logdir => $log_volume_size ? {
185+
undef => true,
186+
default => false
187+
},
152188
config => $es_config,
153189
plugins => $es_plugins,
154190
init_defaults => {

spec/classes/elasticsearch_spec.rb

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
'major_version' => 5,
1818
'version' => nil,
1919
'lvm' => false,
20+
'volume_group' => nil,
21+
'volume_size' => nil,
22+
'log_volume_size' => nil,
2023
'initial_heap_size' => '512m',
2124
'maximum_heap_size' => '512m',
2225
'backup' => true,
@@ -57,6 +60,7 @@
5760
'restart_on_change' => true,
5861
'datadir' => '/var/lib/elasticsearch',
5962
'manage_datadir' => false,
63+
'manage_logdir' => true,
6064
'init_defaults' => { 'ES_JAVA_OPTS' => '"-Xms512m -Xmx512m"' }
6165
) }
6266

@@ -86,12 +90,13 @@
8690
it { is_expected.not_to contain_class('profiles::elasticsearch::backup') }
8791
end
8892

89-
context "with version => 8.2.1, lvm => true, volume_group => myvg, volume_size => 20G, initial_heap_size => 768m, maximum_heap_size => 1024m, backup_lvm => true, backup_volume_group => mybackupvg, backup_volume_size => 10G, backup_hour => 10 and backup_retention_days =>5" do
93+
context "with version => 8.2.1, lvm => true, volume_group => myvg, volume_size => 20G, log_volume_size => 5G, initial_heap_size => 768m, maximum_heap_size => 1024m, backup_lvm => true, backup_volume_group => mybackupvg, backup_volume_size => 10G, backup_hour => 10 and backup_retention_days =>5" do
9094
let(:params) { {
9195
'version' => '8.2.1',
9296
'lvm' => true,
9397
'volume_group' => 'myvg',
9498
'volume_size' => '20G',
99+
'log_volume_size' => '5G',
95100
'initial_heap_size' => '768m',
96101
'maximum_heap_size' => '1024m',
97102
'backup_lvm' => true,
@@ -128,13 +133,36 @@
128133
'group' => 'elasticsearch'
129134
) }
130135

136+
it { is_expected.to contain_profiles__lvm__mount('elasticsearchlogs').with(
137+
'volume_group' => 'myvg',
138+
'size' => '5G',
139+
'mountpoint' => '/data/elasticsearchlogs',
140+
'fs_type' => 'ext4',
141+
'owner' => 'elasticsearch',
142+
'group' => 'elasticsearch'
143+
) }
144+
145+
it { is_expected.to contain_mount('/var/log/elasticsearch').with(
146+
'ensure' => 'mounted',
147+
'device' => '/data/elasticsearchlogs',
148+
'fstype' => 'none',
149+
'options' => 'rw,bind'
150+
) }
151+
152+
it { is_expected.to contain_file('/var/log/elasticsearch').with(
153+
'ensure' => 'directory',
154+
'owner' => 'elasticsearch',
155+
'group' => 'elasticsearch'
156+
) }
157+
131158
it { is_expected.to contain_class('elasticsearch').with(
132159
'version' => '8.2.1',
133160
'manage_repo' => false,
134161
'api_timeout' => 30,
135162
'restart_on_change' => true,
136163
'datadir' => '/var/lib/elasticsearch',
137164
'manage_datadir' => false,
165+
'manage_logdir' => false,
138166
'init_defaults' => { 'ES_JAVA_OPTS' => '"-Xms768m -Xmx1024m"' }
139167
) }
140168

@@ -154,6 +182,14 @@
154182
it { is_expected.to contain_mount('/var/lib/elasticsearch').that_requires('Profiles::Lvm::Mount[elasticsearchdata]') }
155183
it { is_expected.to contain_mount('/var/lib/elasticsearch').that_requires('File[/var/lib/elasticsearch]') }
156184
it { is_expected.to contain_mount('/var/lib/elasticsearch').that_comes_before('Class[elasticsearch]') }
185+
it { is_expected.to contain_profiles__lvm__mount('elasticsearchlogs').that_requires('Group[elasticsearch]') }
186+
it { is_expected.to contain_profiles__lvm__mount('elasticsearchlogs').that_requires('User[elasticsearch]') }
187+
it { is_expected.to contain_file('/var/log/elasticsearch').that_requires('Group[elasticsearch]') }
188+
it { is_expected.to contain_file('/var/log/elasticsearch').that_requires('User[elasticsearch]') }
189+
it { is_expected.to contain_file('/var/log/elasticsearch').that_comes_before('Class[elasticsearch]') }
190+
it { is_expected.to contain_mount('/var/log/elasticsearch').that_requires('Profiles::Lvm::Mount[elasticsearchlogs]') }
191+
it { is_expected.to contain_mount('/var/log/elasticsearch').that_requires('File[/var/log/elasticsearch]') }
192+
it { is_expected.to contain_mount('/var/log/elasticsearch').that_comes_before('Class[elasticsearch]') }
157193
it { is_expected.to contain_class('elasticsearch').that_requires('Apt::Source[elastic-8.x]') }
158194
end
159195
end
@@ -192,13 +228,17 @@
192228
'options' => 'rw,bind'
193229
) }
194230

231+
it { is_expected.not_to contain_profiles__lvm__mount('elasticsearchlogs') }
232+
it { is_expected.not_to contain_mount('/var/log/elasticsearch') }
233+
195234
it { is_expected.to contain_class('elasticsearch').with(
196235
'version' => '5.2.2',
197236
'manage_repo' => false,
198237
'api_timeout' => 30,
199238
'restart_on_change' => true,
200239
'datadir' => '/var/lib/elasticsearch',
201240
'manage_datadir' => false,
241+
'manage_logdir' => true,
202242
'init_defaults' => { 'ES_JAVA_OPTS' => '"-Xms512m -Xmx512m"' }
203243
) }
204244

0 commit comments

Comments
 (0)