(RE-7014) statsd nitpicks and additional rspec

Cleaned up some code review nitpicks and added pool_manager_spec for empty pool.
This commit is contained in:
Rick Sherman 2016-06-08 11:03:22 -05:00
parent b983472088
commit c133bed945
5 changed files with 39 additions and 23 deletions

View file

@ -88,7 +88,7 @@ module Vmpooler
end
def self.new_statsd(server, port)
if server.nil? or server.empty? or server.length == 0
if server.nil? || server.empty?
nil
else
Statsd.new server, port

View file

@ -18,7 +18,7 @@ module Vmpooler
def statsd_prefix
if Vmpooler::API.settings.statsd
Vmpooler::API.settings.config[:statsd]['prefix']? Vmpooler::API.settings.config[:statsd]['prefix'] : 'vmpooler'
Vmpooler::API.settings.config[:statsd]['prefix'] ? Vmpooler::API.settings.config[:statsd]['prefix'] : 'vmpooler'
end
end
@ -393,9 +393,9 @@ module Vmpooler
if jdata
empty = jdata.delete('empty')
invalid = jdata.delete('invalid')
statsd.increment(statsd_prefix + '.checkout.empty', empty) if !empty.nil?
statsd.increment(statsd_prefix + '.checkout.invalid', invalid) if !invalid.nil?
if !jdata.empty?
statsd.increment(statsd_prefix + '.checkout.empty', empty) if empty
statsd.increment(statsd_prefix + '.checkout.invalid', invalid) if invalid
unless jdata.empty?
result = atomically_allocate_vms(jdata)
else
status 404
@ -426,9 +426,9 @@ module Vmpooler
if payload
empty = payload.delete('empty')
invalid = payload.delete('invalid')
statsd.increment(statsd_prefix + '.checkout.empty', empty) if !empty.nil?
statsd.increment(statsd_prefix + '.checkout.invalid', invalid) if !invalid.nil?
if !payload.empty?
statsd.increment(statsd_prefix + '.checkout.empty', empty) if empty
statsd.increment(statsd_prefix + '.checkout.invalid', invalid) if invalid
unless payload.empty?
result = atomically_allocate_vms(payload)
else
status 404

View file

@ -1,17 +1,15 @@
module Vmpooler
class PoolManager
def initialize(config, logger, redis, graphite=nil, statsd=nil)
def initialize(config, logger, redis, graphite = nil, statsd = nil)
$config = config
# Load logger library
$logger = logger
# statsd and graphite are mutex in the context of vmpooler
unless statsd.nil?
if statsd
$statsd = statsd
end
unless graphite.nil? || !statsd.nil?
elsif graphite
$graphite = graphite
end
@ -263,8 +261,8 @@ module Vmpooler
$redis.decr('vmpooler__tasks__clone')
begin
$statsd.timing($config[:statsd]['prefix'] + ".clone.#{vm['template']}", finish) if defined? $statsd
$graphite.log($config[:graphite]['prefix'] + ".clone.#{vm['template']}", finish) if defined? $graphite
$statsd.timing($config[:statsd]['prefix'] + ".clone.#{vm['template']}", finish) if $statsd
$graphite.log($config[:graphite]['prefix'] + ".clone.#{vm['template']}", finish) if $graphite
rescue
end
end
@ -300,7 +298,7 @@ module Vmpooler
$logger.log('s', "[-] [#{pool}] '#{vm}' destroyed in #{finish} seconds")
$graphite.log($config[:graphite]['prefix'] + ".destroy.#{pool}", finish) if defined? $graphite
$graphite.log($config[:graphite]['prefix'] + ".destroy.#{pool}", finish) if $graphite
end
end
end
@ -571,10 +569,10 @@ module Vmpooler
total = $redis.scard('vmpooler__pending__' + pool['name']) + ready
begin
if defined? $statsd
if $statsd
$statsd.increment($config[:statsd]['prefix'] + '.ready.' + pool['name'], $redis.scard('vmpooler__ready__' + pool['name']))
$statsd.increment($config[:statsd]['prefix'] + '.running.' + pool['name'], $redis.scard('vmpooler__running__' + pool['name']))
elsif defined? $graphite
elsif $graphite
$graphite.log($config[:graphite]['prefix'] + '.ready.' + pool['name'], $redis.scard('vmpooler__ready__' + pool['name']))
$graphite.log($config[:graphite]['prefix'] + '.running.' + pool['name'], $redis.scard('vmpooler__running__' + pool['name']))
end

View file

@ -2,11 +2,8 @@ require 'rubygems' unless defined?(Gem)
module Vmpooler
class Statsd
def initialize(
s = 'statsd',
port = 8125
)
@server = Statsd.new s, port
def initialize(server = 'statsd', port = 8125)
@server = Statsd.new(server, port)
end
end
end