mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(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:
parent
b983472088
commit
c133bed945
5 changed files with 39 additions and 23 deletions
|
|
@ -88,7 +88,7 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.new_statsd(server, port)
|
def self.new_statsd(server, port)
|
||||||
if server.nil? or server.empty? or server.length == 0
|
if server.nil? || server.empty?
|
||||||
nil
|
nil
|
||||||
else
|
else
|
||||||
Statsd.new server, port
|
Statsd.new server, port
|
||||||
|
|
|
||||||
|
|
@ -393,9 +393,9 @@ module Vmpooler
|
||||||
if jdata
|
if jdata
|
||||||
empty = jdata.delete('empty')
|
empty = jdata.delete('empty')
|
||||||
invalid = jdata.delete('invalid')
|
invalid = jdata.delete('invalid')
|
||||||
statsd.increment(statsd_prefix + '.checkout.empty', empty) if !empty.nil?
|
statsd.increment(statsd_prefix + '.checkout.empty', empty) if empty
|
||||||
statsd.increment(statsd_prefix + '.checkout.invalid', invalid) if !invalid.nil?
|
statsd.increment(statsd_prefix + '.checkout.invalid', invalid) if invalid
|
||||||
if !jdata.empty?
|
unless jdata.empty?
|
||||||
result = atomically_allocate_vms(jdata)
|
result = atomically_allocate_vms(jdata)
|
||||||
else
|
else
|
||||||
status 404
|
status 404
|
||||||
|
|
@ -426,9 +426,9 @@ module Vmpooler
|
||||||
if payload
|
if payload
|
||||||
empty = payload.delete('empty')
|
empty = payload.delete('empty')
|
||||||
invalid = payload.delete('invalid')
|
invalid = payload.delete('invalid')
|
||||||
statsd.increment(statsd_prefix + '.checkout.empty', empty) if !empty.nil?
|
statsd.increment(statsd_prefix + '.checkout.empty', empty) if empty
|
||||||
statsd.increment(statsd_prefix + '.checkout.invalid', invalid) if !invalid.nil?
|
statsd.increment(statsd_prefix + '.checkout.invalid', invalid) if invalid
|
||||||
if !payload.empty?
|
unless payload.empty?
|
||||||
result = atomically_allocate_vms(payload)
|
result = atomically_allocate_vms(payload)
|
||||||
else
|
else
|
||||||
status 404
|
status 404
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,9 @@ module Vmpooler
|
||||||
$logger = logger
|
$logger = logger
|
||||||
|
|
||||||
# statsd and graphite are mutex in the context of vmpooler
|
# statsd and graphite are mutex in the context of vmpooler
|
||||||
unless statsd.nil?
|
if statsd
|
||||||
$statsd = statsd
|
$statsd = statsd
|
||||||
end
|
elsif graphite
|
||||||
|
|
||||||
unless graphite.nil? || !statsd.nil?
|
|
||||||
$graphite = graphite
|
$graphite = graphite
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -263,8 +261,8 @@ module Vmpooler
|
||||||
$redis.decr('vmpooler__tasks__clone')
|
$redis.decr('vmpooler__tasks__clone')
|
||||||
|
|
||||||
begin
|
begin
|
||||||
$statsd.timing($config[:statsd]['prefix'] + ".clone.#{vm['template']}", finish) if defined? $statsd
|
$statsd.timing($config[:statsd]['prefix'] + ".clone.#{vm['template']}", finish) if $statsd
|
||||||
$graphite.log($config[:graphite]['prefix'] + ".clone.#{vm['template']}", finish) if defined? $graphite
|
$graphite.log($config[:graphite]['prefix'] + ".clone.#{vm['template']}", finish) if $graphite
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -300,7 +298,7 @@ module Vmpooler
|
||||||
|
|
||||||
$logger.log('s', "[-] [#{pool}] '#{vm}' destroyed in #{finish} seconds")
|
$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
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -571,10 +569,10 @@ module Vmpooler
|
||||||
total = $redis.scard('vmpooler__pending__' + pool['name']) + ready
|
total = $redis.scard('vmpooler__pending__' + pool['name']) + ready
|
||||||
|
|
||||||
begin
|
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'] + '.ready.' + pool['name'], $redis.scard('vmpooler__ready__' + pool['name']))
|
||||||
$statsd.increment($config[:statsd]['prefix'] + '.running.' + pool['name'], $redis.scard('vmpooler__running__' + 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'] + '.ready.' + pool['name'], $redis.scard('vmpooler__ready__' + pool['name']))
|
||||||
$graphite.log($config[:graphite]['prefix'] + '.running.' + pool['name'], $redis.scard('vmpooler__running__' + pool['name']))
|
$graphite.log($config[:graphite]['prefix'] + '.running.' + pool['name'], $redis.scard('vmpooler__running__' + pool['name']))
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,8 @@ require 'rubygems' unless defined?(Gem)
|
||||||
|
|
||||||
module Vmpooler
|
module Vmpooler
|
||||||
class Statsd
|
class Statsd
|
||||||
def initialize(
|
def initialize(server = 'statsd', port = 8125)
|
||||||
s = 'statsd',
|
@server = Statsd.new(server, port)
|
||||||
port = 8125
|
|
||||||
)
|
|
||||||
@server = Statsd.new s, port
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -286,6 +286,17 @@ describe 'Pool Manager' do
|
||||||
expect(graphite).to receive(:log).with('vmpooler.running.pool1', 5)
|
expect(graphite).to receive(:log).with('vmpooler.running.pool1', 5)
|
||||||
subject._check_pool(config[:pools][0])
|
subject._check_pool(config[:pools][0])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'increments graphite when ready with 0 when pool empty and statsd disabled' do
|
||||||
|
allow(redis).to receive(:scard).with('vmpooler__ready__pool1').and_return(0)
|
||||||
|
allow(redis).to receive(:scard).with('vmpooler__cloning__pool1').and_return(0)
|
||||||
|
allow(redis).to receive(:scard).with('vmpooler__pending__pool1').and_return(0)
|
||||||
|
allow(redis).to receive(:scard).with('vmpooler__running__pool1').and_return(5)
|
||||||
|
|
||||||
|
expect(graphite).to receive(:log).with('vmpooler.ready.pool1', 0)
|
||||||
|
expect(graphite).to receive(:log).with('vmpooler.running.pool1', 5)
|
||||||
|
subject._check_pool(config[:pools][0])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'statsd' do
|
context 'statsd' do
|
||||||
|
|
@ -307,6 +318,16 @@ describe 'Pool Manager' do
|
||||||
expect(statsd).to receive(:increment).with('vmpooler.running.pool1', 5)
|
expect(statsd).to receive(:increment).with('vmpooler.running.pool1', 5)
|
||||||
subject._check_pool(config[:pools][0])
|
subject._check_pool(config[:pools][0])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'increments statsd ready with 0 when pool empty' do
|
||||||
|
allow(redis).to receive(:scard).with('vmpooler__running__pool1').and_return(1)
|
||||||
|
allow(redis).to receive(:scard).with('vmpooler__ready__pool1').and_return(0)
|
||||||
|
allow(redis).to receive(:scard).with('vmpooler__pending__pool1').and_return(0)
|
||||||
|
allow(statsd).to receive(:increment).with('vmpooler.running.pool1', 1)
|
||||||
|
|
||||||
|
expect(statsd).to receive(:increment).with('vmpooler.ready.pool1', 0)
|
||||||
|
subject._check_pool(config[:pools][0])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue