Skip to content

Commit

Permalink
Merge branch 'deemon87-metricsProvider'
Browse files Browse the repository at this point in the history
  • Loading branch information
deric committed Mar 16, 2021
2 parents 82364be + 555ae4c commit ac95fe1
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 148 deletions.
3 changes: 1 addition & 2 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#
# PRIVATE CLASS - do not use directly (use main `zookeeper` class).
class zookeeper::config inherits zookeeper {

file { $zookeeper::cfg_dir:
ensure => directory,
owner => $zookeeper::user,
Expand Down Expand Up @@ -84,7 +83,7 @@
command => "${zookeeper::initialize_datastore_bin} --myid=${zookeeper::id}",
user => $zookeeper::user,
creates => "${zookeeper::datastore}/version-2",
require => [ File[$zookeeper::datastore], Class['zookeeper::install'] ],
require => [File[$zookeeper::datastore], Class['zookeeper::install']],
}
}
}
194 changes: 98 additions & 96 deletions manifests/init.pp

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
anchor { 'zookeeper::install::java': }

ensure_resource('package', $zookeeper::java_package,
{'ensure' => $zookeeper::ensure, 'allow_virtual' => true,
'before' => Anchor['zookeeper::install::intermediate'],
'require' => Anchor['zookeeper::install::begin']}
{ 'ensure' => $zookeeper::ensure,
'allow_virtual' => true,
'before' => Anchor['zookeeper::install::intermediate'],
'require' => Anchor['zookeeper::install::begin']
}
)
}

Expand Down
2 changes: 0 additions & 2 deletions manifests/install/archive.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#
# PRIVATE CLASS - do not use directly (use main `zookeeper` class).
class zookeeper::install::archive inherits zookeeper::install {


# Apache updated the filename base for archive files in release 3.5.5
if versioncmp($zookeeper::archive_version, '3.5.5') >= 0 {
$filename = "apache-${module_name}-${zookeeper::archive_version}-bin"
Expand Down
3 changes: 1 addition & 2 deletions manifests/install/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#
# PRIVATE CLASS - do not use directly (use main `zookeeper` class).
class zookeeper::install::package inherits zookeeper::install {

# Allow installing multiple packages, like zookeeper, zookeeper-bin etc.
ensure_resource('package', $zookeeper::packages, {'ensure' => $zookeeper::ensure})
ensure_resource('package', $zookeeper::packages, { 'ensure' => $zookeeper::ensure })

# Make sure, that service package was not installed earlier
if ($zookeeper::service_provider == 'init.d' and (!member($zookeeper::packages, $zookeeper::service_package))) {
Expand Down
5 changes: 5 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,9 @@
$remove_realm_principal = false
# whitelist of Four Letter Words commands, see https://zookeeper.apache.org/doc/r3.4.12/zookeeperAdmin.html#sc_zkCommands
$whitelist_4lw = []

# Metrics Providers
$metrics_provider_classname = undef
$metrics_provider_http_port = 7000
$metrics_provider_export_jvm_info = true
}
24 changes: 12 additions & 12 deletions manifests/post_install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,35 @@
# If !$cleanup_count, then ensure this cron is absent.
if ($_clean and $zookeeper::snap_retain_count > 0 and $zookeeper::ensure != 'absent') {
if ($zookeeper::ensure_cron){
if ($zookeeper::ensure_cron) {
include cron
cron::job { 'zookeeper-cleanup':
ensure => present,
command => "${zookeeper::cleanup_sh} ${zookeeper::datastore} ${zookeeper::snap_retain_count}",
hour => 2,
minute => 42,
user => $zookeeper::user,
ensure => present,
command => "${zookeeper::cleanup_sh} ${zookeeper::datastore} ${zookeeper::snap_retain_count}",
hour => 2,
minute => 42,
user => $zookeeper::user,
}
}else {
} else {
file { '/etc/cron.daily/zkcleanup':
ensure => present,
content => "${zookeeper::cleanup_sh} ${zookeeper::datastore} ${zookeeper::snap_retain_count}",
ensure => file,
content => "${zookeeper::cleanup_sh} ${zookeeper::datastore} ${zookeeper::snap_retain_count}",
}
}
}
# Package removal
if($_clean and $zookeeper::ensure == 'absent'){
if ($zookeeper::ensure_cron){
if ($_clean and $zookeeper::ensure == 'absent') {
if ($zookeeper::ensure_cron) {
class { 'cron':
manage_package => false,
}
cron::job { 'zookeeper-cleanup':
ensure => $zookeeper::ensure,
}
}else{
} else {
file { '/etc/cron.daily/zkcleanup':
ensure => $zookeeper::ensure,
}
Expand Down
4 changes: 2 additions & 2 deletions manifests/sasl.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#
# PRIVATE CLASS - do not use directly (use main `zookeeper` class).
class zookeeper::sasl inherits zookeeper {
file{"${zookeeper::cfg_dir}/jaas.conf":
ensure => present,
file { "${zookeeper::cfg_dir}/jaas.conf":
ensure => file,
owner => $zookeeper::user,
group => $zookeeper::group,
content => template("${module_name}/conf/jaas.conf.erb"),
Expand Down
26 changes: 14 additions & 12 deletions manifests/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# PRIVATE CLASS - do not use directly (use main `zookeeper` class).
class zookeeper::service inherits zookeeper {

#
case $zookeeper::install_method {
'archive': {
$_zoo_dir = "${zookeeper::archive_install_dir}/${module_name}"
Expand All @@ -16,21 +16,22 @@
}

if $zookeeper::manage_service_file == true {
if $zookeeper::service_provider == 'systemd' {
exec { 'systemctl daemon-reload # for zookeeper':
refreshonly => true,
path => $::path,
}
if $zookeeper::service_provider == 'systemd' {
file { "${zookeeper::systemd_path}/${zookeeper::service_name}.service":
ensure => 'present',
ensure => file,
content => template("${module_name}/zookeeper.service.erb"),
}
~> exec { 'systemctl daemon-reload # for zookeeper':
refreshonly => true,
path => $::path,
notify => Exec['systemctl daemon-reload # for zookeeper'],
}
} elsif (
$zookeeper::service_provider == 'init'
or $zookeeper::service_provider == 'redhat'
) {
) {
file { "/etc/init.d/${zookeeper::service_name}":
ensure => present,
ensure => file,
content => template("${module_name}/zookeeper.${facts['os']['family']}.init.erb"),
mode => '0755',
before => Service[$zookeeper::service_name],
Expand All @@ -46,7 +47,7 @@
provider => $zookeeper::service_provider,
enable => true,
require => [
Class['::zookeeper::install'],
Class['zookeeper::install'],
File["${zookeeper::cfg_dir}/zoo.cfg"]
],
}
Expand All @@ -57,8 +58,9 @@
File["${zookeeper::cfg_dir}/zoo.cfg"] ~> Service[$zookeeper::service_name]
File["${zookeeper::cfg_dir}/${zookeeper::environment_file}"] ~> Service[$zookeeper::service_name]
File["${zookeeper::cfg_dir}/log4j.properties"] ~> Service[$zookeeper::service_name]
if $::zookeeper::manage_service_file and $zookeeper::service_provider == 'systemd' {
Exec['systemctl daemon-reload # for zookeeper'] ~> Service[$::zookeeper::service_name]

if $zookeeper::manage_service_file and $zookeeper::service_provider == 'systemd' {
Exec['systemctl daemon-reload # for zookeeper'] ~> Service[$zookeeper::service_name]
}
}
}
60 changes: 47 additions & 13 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,6 @@
end
end

context 'install from archive' do
let :pre_condition do
'class {"zookeeper":
install_method => "archive",
archive_version => "3.4.9",
}'
end

it do
is_expected.to contain_file(environment_file).without_content(%r{CLASSPATH})
end
end

context 'extra environment_file parameter' do
# set custom params
let :pre_condition do
Expand Down Expand Up @@ -538,6 +525,27 @@
end
end

context 'setting metrics provider' do
let :pre_condition do
'class {"zookeeper":
metrics_provider_classname => "org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider",
metrics_provider_http_port => 7007,
}'
end

it do
is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg',
).with_content(%r{^metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider})
end

it do
is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg',
).with_content(%r{^metricsProvider.httpPort=7007})
end
end

context 'set global outstanding limit' do
let :pre_condition do
'class {"zookeeper":
Expand Down Expand Up @@ -577,6 +585,32 @@
end
end
end
context 'setting metrics provider' do
let :pre_condition do
'class {"zookeeper":
metrics_provider_classname => "org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider",
metrics_provider_http_port => 7007,
metrics_provider_export_jvm_info => false,
}'
end

it do
is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg',
).with_content(%r{metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider})
end

it do
is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg',
).with_content(%r{metricsProvider.httpPort=7007})
end
it do
is_expected.to contain_file(
'/etc/zookeeper/conf/zoo.cfg',
).with_content(%r{metricsProvider.exportJvmInfo=false})
end
end
end

describe 'zookeeper::config' do
Expand Down
8 changes: 4 additions & 4 deletions spec/classes/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
it do
is_expected.to contain_file(
"/usr/lib/systemd/system/#{service_name}.service",
).with('ensure' => 'present')
).with('ensure' => 'file')
end

it do
Expand Down Expand Up @@ -84,7 +84,7 @@
end

it do
is_expected.not_to contain_file(service_file).with('ensure' => 'present')
is_expected.not_to contain_file(service_file).with('ensure' => 'file')
end
end

Expand All @@ -100,7 +100,7 @@
end

it do
is_expected.to contain_file(service_file).with('ensure' => 'present')
is_expected.to contain_file(service_file).with('ensure' => 'file')
end

it do
Expand Down Expand Up @@ -159,7 +159,7 @@
end

it do
is_expected.to contain_file(custom_service_file).with('ensure' => 'present')
is_expected.to contain_file(custom_service_file).with('ensure' => 'file')
end

it do
Expand Down
14 changes: 14 additions & 0 deletions templates/conf/zoo.cfg.erb
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,17 @@ kerberos.removeRealmFromPrincipal=true
# Supported since 3.4.10
4lw.commands.whitelist=<%= scope.lookupvar("zookeeper::whitelist_4lw").join(',') %>
<% end -%>

# Supported since 3.6
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
<% unless [nil, :undefined, :undef].include?(scope.lookupvar("zookeeper::metrics_provider_classname")) -%>
metricsProvider.className=<%= scope.lookupvar("zookeeper::metrics_provider_classname") %>
metricsProvider.httpPort=<%= scope.lookupvar("zookeeper::metrics_provider_http_port") %>
metricsProvider.exportJvmInfo=<%= scope.lookupvar("zookeeper::metrics_provider_export_jvm_info") %>
<% else -%>
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
<% end -%>

0 comments on commit ac95fe1

Please sign in to comment.