Giuseppe Lavagetto has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/356060 )
Change subject: profile::nutcracker: correctly handle monitoring, refactoring ...................................................................... profile::nutcracker: correctly handle monitoring, refactoring * Add a monitoring_port parameter to set which port to monitor, if any * Add base settings for both redis and memcached, allowing only to override those, allowing a more DRY approach. * Add a parser function to merge the hashes, this could be avoided with either the future parser or a better base class. Change-Id: I35ff9fecc6b342de640e6e37e5b7764797080603 --- M hieradata/role/common/scb.yaml M modules/nutcracker/manifests/monitoring.pp A modules/profile/lib/puppet/parser/functions/nutcracker_pools.rb M modules/profile/manifests/nutcracker.pp 4 files changed, 75 insertions(+), 23 deletions(-) Approvals: Giuseppe Lavagetto: Verified; Looks good to me, approved diff --git a/hieradata/role/common/scb.yaml b/hieradata/role/common/scb.yaml index df434b7..214004e 100644 --- a/hieradata/role/common/scb.yaml +++ b/hieradata/role/common/scb.yaml @@ -75,17 +75,9 @@ statistics.interval.ms: 60000 changeprop::restbase_uri: http://restbase-async.discovery.wmnet:7231 -profile::nutcracker::pools: +profile::nutcracker::redis_pools: redis_eqiad: - auto_eject_hosts: true - distribution: 'ketama' - redis: true - redis_auth: "%{::passwords::redis::main_password}" - hash: md5 - server_connections: 1 - server_failure_limit: 3 server_retry_timeout: 10000 - timeout: 1000 server_map: cp-1: host: 10.64.32.76 @@ -95,15 +87,7 @@ port: 6382 listen: '/var/run/nutcracker/redis_eqiad.sock 0666' redis_codfw: - auto_eject_hosts: true - distribution: 'ketama' - redis: true - redis_auth: "%{::passwords::redis::main_password}" - hash: md5 - server_connections: 1 - server_failure_limit: 3 server_retry_timeout: 10000 - timeout: 1000 server_map: cp-1: host: 10.192.0.119 @@ -112,3 +96,5 @@ host: 10.192.16.122 port: 6382 listen: '/var/run/nutcracker/redis_codfw.sock 0666' +profile::nutcracker::memcached_pools: {} +profile::nutcracker::monitor_port: 0 # we have nothing exposed via tcp diff --git a/modules/nutcracker/manifests/monitoring.pp b/modules/nutcracker/manifests/monitoring.pp index 8563b1a..dee33d2 100644 --- a/modules/nutcracker/manifests/monitoring.pp +++ b/modules/nutcracker/manifests/monitoring.pp @@ -2,15 +2,17 @@ # # Provisions Icinga alerts for nutcracker. # -class nutcracker::monitoring { +class nutcracker::monitoring($port = 11212) { nrpe::monitor_service { 'nutcracker': description => 'nutcracker process', nrpe_command => '/usr/lib/nagios/plugins/check_procs -c 1:1 -u nutcracker -C nutcracker', } - nrpe::monitor_service { 'nutcracker_port': - description => 'nutcracker port', - nrpe_command => '/usr/lib/nagios/plugins/check_tcp -H 127.0.0.1 -p 11212 --timeout=2', + if ($port != 0) { + nrpe::monitor_service { 'nutcracker_port': + description => 'nutcracker port', + nrpe_command => "/usr/lib/nagios/plugins/check_tcp -H 127.0.0.1 -p ${port} --timeout=2", + } } diamond::collector { 'Nutcracker': diff --git a/modules/profile/lib/puppet/parser/functions/nutcracker_pools.rb b/modules/profile/lib/puppet/parser/functions/nutcracker_pools.rb new file mode 100644 index 0000000..eb73e99 --- /dev/null +++ b/modules/profile/lib/puppet/parser/functions/nutcracker_pools.rb @@ -0,0 +1,32 @@ +module Puppet::Parser::Functions + newfunction(:nutcracker_pools, :type => :rvalue, :arity => 4, :doc => <<-EOS + Given a list of redis pools, memcached pools, and base settings for both, + extracts a server list that is then fed to class nutcracker. + EOS + ) do |args| + if args.size < 4 + raise(Puppet::ParseError, "nutcracker_pools: 4 arguments needed, (#{args.size} given)") + end + redis, memc, redis_settings, memc_settings = args + + pools = {} + if redis.is_a?(Hash) + redis.keys.each do |k| + if pools.include?(k) + raise(Puppet::ParseError, "Pool #{k} already defined") + end + pools[k] = redis_settings.merge(redis[k]) + end + end + if memc.is_a?(Hash) + memc.keys.each do |k| + if pools.include?(k) + raise(Puppet::ParseError, "Pool #{k} already defined") + end + pools[k] = memc_settings.merge(memc[k]) + end + end + + pools + end +end diff --git a/modules/profile/manifests/nutcracker.pp b/modules/profile/manifests/nutcracker.pp index 21ff977..bb40052 100644 --- a/modules/profile/manifests/nutcracker.pp +++ b/modules/profile/manifests/nutcracker.pp @@ -2,16 +2,48 @@ # # Configures a generic nutcracker instance class profile::nutcracker( - $pools = hiera('profile::nutcracker::pools') + $redis_pools = hiera('profile::nutcracker::redis_pools'), + $memcached_pools = hiera('profile::nutcracker::memcached_pools'), + $monitor_port = hiera('profile::nutcracker::monitor_port'), # set to 0 if no port available ) { include ::passwords::redis + # Default settings that should be ok for any pool + # pools *need* to define just the listen and server_map entries + $redis_base_settings = { + auto_eject_hosts => true, + distribution => 'ketama', + redis => true, + redis_auth => $::passwords::redis::main_password, + hash => 'md5', + server_connections => 1, + server_failure_limit => 3, + server_retry_timeout => to_milliseconds('30s'), + timeout => 1000, + } + + $memcached_base_settings = { + auto_eject_hosts => true, + distribution => 'ketama', + hash => 'md5', + preconnect => true, + server_connections => 1, + server_failure_limit => 3, + server_retry_timeout => to_milliseconds('30s'), + timeout => 250, + } + + # TODO: this is now a parser function, should be doable with map() + # when we enable the future parser + $pools = nutcracker_pools($redis_pools, $memcached_pools, $redis_base_settings, $memcached_base_settings) class { '::nutcracker': mbuf_size => '64k', pools => $pools, } - class { '::nutcracker::monitoring': } + class { '::nutcracker::monitoring': + port => $monitor_port, + } ferm::rule { 'skip_nutcracker_conntrack_out': -- To view, visit https://gerrit.wikimedia.org/r/356060 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I35ff9fecc6b342de640e6e37e5b7764797080603 Gerrit-PatchSet: 4 Gerrit-Project: operations/puppet Gerrit-Branch: production Gerrit-Owner: Giuseppe Lavagetto <[email protected]> Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
