Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new support for logging (log4j2.properties) #1234

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ The following parameters are available in the `elasticsearch` class:
* [`logdir`](#-elasticsearch--logdir)
* [`logdir_mode`](#-elasticsearch--logdir_mode)
* [`logging_config`](#-elasticsearch--logging_config)
* [`logging_content`](#-elasticsearch--logging_content)
* [`logging_file`](#-elasticsearch--logging_file)
* [`logging_level`](#-elasticsearch--logging_level)
* [`logging_path`](#-elasticsearch--logging_path)
* [`logging_template`](#-elasticsearch--logging_template)
* [`manage_datadir`](#-elasticsearch--manage_datadir)
* [`manage_logdir`](#-elasticsearch--manage_logdir)
* [`manage_logging`](#-elasticsearch--manage_logging)
* [`manage_repo`](#-elasticsearch--manage_repo)
* [`oss`](#-elasticsearch--oss)
* [`package_dir`](#-elasticsearch--package_dir)
Expand Down Expand Up @@ -451,6 +454,14 @@ Data type: `Hash`

Representation of information to be included in the log4j.properties file.

##### <a name="-elasticsearch--logging_content"></a>`logging_content`

Data type: `Optional[String]`

Representation of content to be included in the log4j2.properties file.

Default value: `undef`

##### <a name="-elasticsearch--logging_file"></a>`logging_file`

Data type: `Optional[String]`
Expand All @@ -464,6 +475,14 @@ Data type: `String`

Default logging level for Elasticsearch.

##### <a name="-elasticsearch--logging_path"></a>`logging_path`

Data type: `Stdlib::Absolutepath`

Custom path to the logging file.

Default value: `"${configdir}/log4j2.properties"`

##### <a name="-elasticsearch--logging_template"></a>`logging_template`

Data type: `Optional[String]`
Expand All @@ -483,6 +502,14 @@ Data type: `Boolean`

Enable logdir management (default true).

##### <a name="-elasticsearch--manage_logging"></a>`manage_logging`

Data type: `Boolean`

Enable logging (log4j) management (default false).

Default value: `false`

##### <a name="-elasticsearch--manage_repo"></a>`manage_repo`

Data type: `Boolean`
Expand Down
14 changes: 14 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@
# before => Class['elasticsearch::service'],
# }

# Logging file
if $elasticsearch::manage_logging and !empty($elasticsearch::logging_content) {
file { $elasticsearch::logging_path:
ensure => file,
content => $elasticsearch::logging_content,
group => $elasticsearch::elasticsearch_group,
owner => $elasticsearch::elasticsearch_user,
mode => '0644',
notify => $elasticsearch::_notify_service,
require => File[$elasticsearch::configdir],
before => Class['elasticsearch::service'],
}
}

# Generate Elasticsearch config
$data =
$elasticsearch::config + { 'path.data' => $elasticsearch::datadir } + { 'path.logs' => $elasticsearch::logdir } + $_tls_config
Expand Down
12 changes: 12 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,19 @@
# @param logging_config
# Representation of information to be included in the log4j.properties file.
#
# @param logging_content
# Representation of content to be included in the log4j2.properties file.
#
# @param logging_file
# Instead of a hash, you may supply a `puppet://` file source for the
# log4j.properties file.
#
# @param logging_level
# Default logging level for Elasticsearch.
#
# @param logging_path
# Custom path to the logging file.
#
# @param logging_template
# Use a custom logging template - just supply the relative path, i.e.
# `$module/elasticsearch/logging.yml.erb`
Expand All @@ -171,6 +177,9 @@
# @param manage_logdir
# Enable logdir management (default true).
#
# @param manage_logging
# Enable logging (log4j) management (default false).
#
# @param manage_repo
# Enable repo management by enabling official Elastic repositories.
#
Expand Down Expand Up @@ -430,6 +439,9 @@
String $default_logging_level = $logging_level,
Optional[String] $keystore_password = undef,
Optional[Stdlib::Absolutepath] $keystore_path = undef,
Optional[String] $logging_content = undef,
Stdlib::Absolutepath $logging_path = "${configdir}/log4j2.properties",
Boolean $manage_logging = false,
Optional[Stdlib::Absolutepath] $private_key = undef,
Enum['rsa','dsa','ec'] $private_key_type = 'rsa',
Boolean $restart_config_change = $restart_on_change,
Expand Down
53 changes: 53 additions & 0 deletions spec/classes/000_elasticsearch_init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,59 @@
}
end

context 'When managing the logging file (with content)' do
let(:params) do
default_params.merge(
logging_content: '# Content',
manage_logging: true
)
end

it {
expect(subject).to contain_file('/etc/elasticsearch/log4j2.properties').
with(ensure: 'file', content: '# Content')
}
end

context 'When managing the logging file (with content and specific path)' do
let(:params) do
default_params.merge(
logging_content: '# Content',
logging_path: '/etc/elasticsearch/log4j.properties',
manage_logging: true
)
end

it {
expect(subject).to contain_file('/etc/elasticsearch/log4j.properties').
with(ensure: 'file', content: '# Content')
}
end

context 'When managing the logging file (with no content)' do
let(:params) do
default_params.merge(
manage_logging: true
)
end

it {
expect(subject).not_to contain_file('/etc/elasticsearch/log4j2.properties')
}
end

context 'When not managing the logging file' do
let(:params) do
default_params.merge(
manage_logging: false
)
end

it {
expect(subject).not_to contain_file('/etc/elasticsearch/log4j2.properties')
}
end

context 'with restart_on_change => true' do
let(:params) do
default_params.merge(
Expand Down
Loading