Skip to content

Commit

Permalink
new parameters logging support
Browse files Browse the repository at this point in the history
  • Loading branch information
stjmt committed Jul 31, 2024
1 parent 543c582 commit 1b3f1c3
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
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: `"${elasticsearch::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 = "${elasticsearch::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

Check failure on line 537 in spec/classes/000_elasticsearch_init_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Lint/Syntax: unexpected token tIDENTIFIER (Using Ruby 2.6 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
)
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

0 comments on commit 1b3f1c3

Please sign in to comment.