Skip to content

Commit

Permalink
Merge pull request #363 from voxpupuli/custom_log4j
Browse files Browse the repository at this point in the history
feat: add option to allow for custom log4j configuration
  • Loading branch information
Christoph Maser committed Apr 17, 2024
2 parents 501ef08 + a24a5f3 commit 6cba25e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
1 change: 0 additions & 1 deletion .puppet-lint.rc
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
--fail-on-warnings
--no-parameter_documentation-check
--no-parameter_types-check
32 changes: 21 additions & 11 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,11 @@ The following parameters are available in the `kafka::broker` class:
* [`heap_opts`](#-kafka--broker--heap_opts)
* [`jmx_opts`](#-kafka--broker--jmx_opts)
* [`log4j_opts`](#-kafka--broker--log4j_opts)
* [`opts`](#-kafka--broker--opts)
* [`manage_log4j`](#-kafka--broker--manage_log4j)
* [`log4j_content`](#-kafka--broker--log4j_content)
* [`log_file_size`](#-kafka--broker--log_file_size)
* [`log_file_count`](#-kafka--broker--log_file_count)
* [`opts`](#-kafka--broker--opts)

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

Expand Down Expand Up @@ -610,38 +611,47 @@ Set the Log4j options.

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

##### <a name="-kafka--broker--opts"></a>`opts`

Data type: `String[0]`
##### <a name="-kafka--broker--manage_log4j"></a>`manage_log4j`

Set the Kafka options.
Data type: `Boolean`

Default value: `$kafka::params::broker_opts`
Enable or disable the management of the log4j configuration file.

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

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

Data type: `Optional[String[1]]`

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

Default value: `$kafka::params::manage_log4j`
Default value: `undef`

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

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


Set the max size of the Kafka log files before they are rolled.

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

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

Data type: `Integer[1, 50]`


Set the number of Kafka log files to keep.

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

##### <a name="-kafka--broker--opts"></a>`opts`

Data type: `String[0]`

Set the Kafka options.

Default value: `$kafka::params::broker_opts`

### <a name="kafka--consumer"></a>`kafka::consumer`

This class handles the Kafka (consumer).
Expand Down
13 changes: 13 additions & 0 deletions manifests/broker.pp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@
# @param log4j_opts
# Set the Log4j options.
#
# @param manage_log4j
# Enable or disable the management of the log4j configuration file.
#
# @param log4j_content
# Provide custom content for the log4j configuration file if manage_log4j is enabled,
# instead of using the content provided in this module.
# @param log_file_size
# Set the max size of the Kafka log files before they are rolled.
#
# @param log_file_count
# Set the number of Kafka log files to keep.
#
# @param opts
# Set the Kafka options.
#
Expand Down Expand Up @@ -151,6 +163,7 @@
String[1] $log4j_opts = $kafka::params::broker_log4j_opts,
String[0] $opts = $kafka::params::broker_opts,
Boolean $manage_log4j = $kafka::params::manage_log4j,
Optional[String[1]] $log4j_content = undef,
Pattern[/[1-9][0-9]*[KMG]B/] $log_file_size = $kafka::params::log_file_size,
Integer[1, 50] $log_file_count = $kafka::params::log_file_count
) inherits kafka::params {
Expand Down
7 changes: 6 additions & 1 deletion manifests/broker/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
String[1] $group_name = $kafka::broker::group_name,
Stdlib::Filemode $config_mode = $kafka::broker::config_mode,
Boolean $manage_log4j = $kafka::broker::manage_log4j,
Optional[String[1]] $log4j_content = $kafka::broker::log4j_content,
Pattern[/[1-9][0-9]*[KMG]B/] $log_file_size = $kafka::broker::log_file_size,
Integer[1, 50] $log_file_count = $kafka::broker::log_file_count,
) {
Expand All @@ -36,12 +37,16 @@
}

if $manage_log4j {
$_log4j_content = pick_default(
$log4j_content,
epp('kafka/log4j.properties.epp', { 'log_file_size' => $log_file_size, 'log_file_count' => $log_file_count })
)
file { "${config_dir}/log4j.properties":
ensure => file,
owner => $user_name,
group => $group_name,
mode => $config_mode,
content => epp('kafka/log4j.properties.epp', { 'log_file_size' => $log_file_size, 'log_file_count' => $log_file_count }),
content => $_log4j_content,
notify => $config_notify,
require => File[$config_dir],
}
Expand Down
6 changes: 6 additions & 0 deletions spec/classes/broker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
it { is_expected.to contain_file('/opt/kafka/config/log4j.properties').with_content(%r{^log4j.appender.kafkaAppender.MaxFileSize=50MB$}) }
it { is_expected.to contain_file('/opt/kafka/config/log4j.properties').with_content(%r{^log4j.appender.kafkaAppender.MaxBackupIndex=7$}) }
end

context 'with manage_log4j => true and log4j_content' do
let(:params) { { 'manage_log4j' => true, 'log4j_content' => 'TEST' } }

it { is_expected.to contain_file('/opt/kafka/config/log4j.properties').with_content(%r{^TEST$}) }
end
end

describe 'kafka::broker::service' do
Expand Down

0 comments on commit 6cba25e

Please sign in to comment.