Skip to content

Commit 6cba25e

Browse files
authored
Merge pull request #363 from voxpupuli/custom_log4j
feat: add option to allow for custom log4j configuration
2 parents 501ef08 + a24a5f3 commit 6cba25e

File tree

5 files changed

+46
-13
lines changed

5 files changed

+46
-13
lines changed

.puppet-lint.rc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
--fail-on-warnings
22
--no-parameter_documentation-check
3-
--no-parameter_types-check

REFERENCE.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,11 @@ The following parameters are available in the `kafka::broker` class:
333333
* [`heap_opts`](#-kafka--broker--heap_opts)
334334
* [`jmx_opts`](#-kafka--broker--jmx_opts)
335335
* [`log4j_opts`](#-kafka--broker--log4j_opts)
336-
* [`opts`](#-kafka--broker--opts)
337336
* [`manage_log4j`](#-kafka--broker--manage_log4j)
337+
* [`log4j_content`](#-kafka--broker--log4j_content)
338338
* [`log_file_size`](#-kafka--broker--log_file_size)
339339
* [`log_file_count`](#-kafka--broker--log_file_count)
340+
* [`opts`](#-kafka--broker--opts)
340341

341342
##### <a name="-kafka--broker--kafka_version"></a>`kafka_version`
342343

@@ -610,38 +611,47 @@ Set the Log4j options.
610611

611612
Default value: `$kafka::params::broker_log4j_opts`
612613

613-
##### <a name="-kafka--broker--opts"></a>`opts`
614-
615-
Data type: `String[0]`
614+
##### <a name="-kafka--broker--manage_log4j"></a>`manage_log4j`
616615

617-
Set the Kafka options.
616+
Data type: `Boolean`
618617

619-
Default value: `$kafka::params::broker_opts`
618+
Enable or disable the management of the log4j configuration file.
620619

621-
##### <a name="-kafka--broker--manage_log4j"></a>`manage_log4j`
620+
Default value: `$kafka::params::manage_log4j`
622621

623-
Data type: `Boolean`
622+
##### <a name="-kafka--broker--log4j_content"></a>`log4j_content`
624623

624+
Data type: `Optional[String[1]]`
625625

626+
Provide custom content for the log4j configuration file if manage_log4j is enabled,
627+
instead of using the content provided in this module.
626628

627-
Default value: `$kafka::params::manage_log4j`
629+
Default value: `undef`
628630

629631
##### <a name="-kafka--broker--log_file_size"></a>`log_file_size`
630632

631633
Data type: `Pattern[/[1-9][0-9]*[KMG]B/]`
632634

633-
635+
Set the max size of the Kafka log files before they are rolled.
634636

635637
Default value: `$kafka::params::log_file_size`
636638

637639
##### <a name="-kafka--broker--log_file_count"></a>`log_file_count`
638640

639641
Data type: `Integer[1, 50]`
640642

641-
643+
Set the number of Kafka log files to keep.
642644

643645
Default value: `$kafka::params::log_file_count`
644646

647+
##### <a name="-kafka--broker--opts"></a>`opts`
648+
649+
Data type: `String[0]`
650+
651+
Set the Kafka options.
652+
653+
Default value: `$kafka::params::broker_opts`
654+
645655
### <a name="kafka--consumer"></a>`kafka::consumer`
646656

647657
This class handles the Kafka (consumer).

manifests/broker.pp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@
111111
# @param log4j_opts
112112
# Set the Log4j options.
113113
#
114+
# @param manage_log4j
115+
# Enable or disable the management of the log4j configuration file.
116+
#
117+
# @param log4j_content
118+
# Provide custom content for the log4j configuration file if manage_log4j is enabled,
119+
# instead of using the content provided in this module.
120+
# @param log_file_size
121+
# Set the max size of the Kafka log files before they are rolled.
122+
#
123+
# @param log_file_count
124+
# Set the number of Kafka log files to keep.
125+
#
114126
# @param opts
115127
# Set the Kafka options.
116128
#
@@ -151,6 +163,7 @@
151163
String[1] $log4j_opts = $kafka::params::broker_log4j_opts,
152164
String[0] $opts = $kafka::params::broker_opts,
153165
Boolean $manage_log4j = $kafka::params::manage_log4j,
166+
Optional[String[1]] $log4j_content = undef,
154167
Pattern[/[1-9][0-9]*[KMG]B/] $log_file_size = $kafka::params::log_file_size,
155168
Integer[1, 50] $log_file_count = $kafka::params::log_file_count
156169
) inherits kafka::params {

manifests/broker/config.pp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
String[1] $group_name = $kafka::broker::group_name,
1414
Stdlib::Filemode $config_mode = $kafka::broker::config_mode,
1515
Boolean $manage_log4j = $kafka::broker::manage_log4j,
16+
Optional[String[1]] $log4j_content = $kafka::broker::log4j_content,
1617
Pattern[/[1-9][0-9]*[KMG]B/] $log_file_size = $kafka::broker::log_file_size,
1718
Integer[1, 50] $log_file_count = $kafka::broker::log_file_count,
1819
) {
@@ -36,12 +37,16 @@
3637
}
3738

3839
if $manage_log4j {
40+
$_log4j_content = pick_default(
41+
$log4j_content,
42+
epp('kafka/log4j.properties.epp', { 'log_file_size' => $log_file_size, 'log_file_count' => $log_file_count })
43+
)
3944
file { "${config_dir}/log4j.properties":
4045
ensure => file,
4146
owner => $user_name,
4247
group => $group_name,
4348
mode => $config_mode,
44-
content => epp('kafka/log4j.properties.epp', { 'log_file_size' => $log_file_size, 'log_file_count' => $log_file_count }),
49+
content => $_log4j_content,
4550
notify => $config_notify,
4651
require => File[$config_dir],
4752
}

spec/classes/broker_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
it { is_expected.to contain_file('/opt/kafka/config/log4j.properties').with_content(%r{^log4j.appender.kafkaAppender.MaxFileSize=50MB$}) }
4747
it { is_expected.to contain_file('/opt/kafka/config/log4j.properties').with_content(%r{^log4j.appender.kafkaAppender.MaxBackupIndex=7$}) }
4848
end
49+
50+
context 'with manage_log4j => true and log4j_content' do
51+
let(:params) { { 'manage_log4j' => true, 'log4j_content' => 'TEST' } }
52+
53+
it { is_expected.to contain_file('/opt/kafka/config/log4j.properties').with_content(%r{^TEST$}) }
54+
end
4955
end
5056

5157
describe 'kafka::broker::service' do

0 commit comments

Comments
 (0)