mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 10:08:40 -05:00
(RE-7014) Add tracking of vm gets via statsd
Add the tracking of successful, failed, invalid, and empty pool vm gets. It is possible we may want to tweak this, but have validated with spec tests and pcaps. ``` vmpooler-tmp-dev.ready.debian-7-x86_64:1|c vmpooler-tmp-dev.running.debian-7-x86_64:1|c vmpooler-tmp-dev.checkout.invalid:1|c vmpooler-tmp-dev.checkout.success.debian-7-x86_64:1|c vmpooler-tmp-dev.checkout.empty:1|c vmpooler-tmp-dev.running.debian-7-x86_64:1|c vmpooler-tmp-dev.clone.debian-7-x86_64:12.10|ms vmpooler-tmp-dev.ready.debian-7-x86_64:1|c ```
This commit is contained in:
parent
8d75865a5c
commit
b983472088
4 changed files with 90 additions and 17 deletions
|
|
@ -180,6 +180,7 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
describe '/vm' do
|
||||
let(:redis) { double('redis') }
|
||||
let(:statsd) { double('stats') }
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:config) { {
|
||||
config: {
|
||||
|
|
@ -190,20 +191,27 @@ describe Vmpooler::API::V1 do
|
|||
{'name' => 'pool1', 'size' => 5},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
alias: { 'poolone' => 'pool1' }
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
statsd: { 'prefix' => 'vmpooler' }
|
||||
} }
|
||||
|
||||
before do
|
||||
app.settings.set :config, config
|
||||
app.settings.set :redis, redis
|
||||
app.settings.set :statsd, statsd
|
||||
|
||||
allow(redis).to receive(:exists).and_return '1'
|
||||
allow(redis).to receive(:exists).with('vmpooler__token__abcdefghijklmnopqrstuvwxyz012345').and_return '1'
|
||||
allow(redis).to receive(:exists).with('vmpooler__ready__pool1').and_return '1'
|
||||
allow(redis).to receive(:exists).with('vmpooler__ready__pool2').and_return '1'
|
||||
allow(redis).to receive(:hget).with('vmpooler__token__abcdefghijklmnopqrstuvwxyz012345', 'user').and_return 'jdoe'
|
||||
allow(redis).to receive(:hset).and_return '1'
|
||||
allow(redis).to receive(:sadd).and_return '1'
|
||||
allow(redis).to receive(:scard).and_return '5'
|
||||
allow(redis).to receive(:spop).with('vmpooler__ready__pool1').and_return 'abcdefghijklmnop'
|
||||
allow(redis).to receive(:spop).with('vmpooler__ready__pool2').and_return 'qrstuvwxyz012345'
|
||||
allow(statsd).to receive(:increment).with('vmpooler.checkout.success.pool1', 1)
|
||||
allow(statsd).to receive(:increment).with('vmpooler.checkout.success.pool2', 1)
|
||||
allow(statsd).to receive(:increment).with('vmpooler.checkout.fail.pool2', 1)
|
||||
end
|
||||
|
||||
describe 'POST /vm' do
|
||||
|
|
@ -223,7 +231,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns a single VM for an alias' do
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__poolone").and_return(false)
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__pool1").and_return(1)
|
||||
|
||||
post "#{prefix}/vm", '{"poolone":"1"}'
|
||||
|
||||
|
|
@ -241,12 +249,22 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
it 'fails on nonexistent pools' do
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__poolpoolpool").and_return(false)
|
||||
|
||||
expect(redis).to receive(:exists).with("vmpooler__empty__poolpoolpool").and_return(false)
|
||||
expect(statsd).to receive(:increment).with('vmpooler.checkout.invalid', 1)
|
||||
post "#{prefix}/vm", '{"poolpoolpool":"1"}'
|
||||
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
it 'fails on empty pools' do
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__emptypool").and_return(false)
|
||||
expect(redis).to receive(:exists).with("vmpooler__empty__emptypool").and_return(true)
|
||||
expect(statsd).to receive(:increment).with('vmpooler.checkout.empty', 1)
|
||||
post "#{prefix}/vm", '{"emptypool":"1"}'
|
||||
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
it 'returns multiple VMs' do
|
||||
post "#{prefix}/vm", '{"pool1":"1","pool2":"1"}'
|
||||
|
||||
|
|
@ -446,6 +464,7 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
describe '/vm/:template' do
|
||||
let(:redis) { double('redis') }
|
||||
let(:statsd) { double('stats') }
|
||||
let(:prefix) { '/api/v1' }
|
||||
let(:config) { {
|
||||
config: {
|
||||
|
|
@ -456,20 +475,27 @@ describe Vmpooler::API::V1 do
|
|||
{'name' => 'pool1', 'size' => 5},
|
||||
{'name' => 'pool2', 'size' => 10}
|
||||
],
|
||||
alias: { 'poolone' => 'pool1' }
|
||||
alias: { 'poolone' => 'pool1' },
|
||||
statsd: { 'prefix' => 'vmpooler' }
|
||||
} }
|
||||
|
||||
before do
|
||||
app.settings.set :config, config
|
||||
app.settings.set :redis, redis
|
||||
app.settings.set :statsd, statsd
|
||||
|
||||
allow(redis).to receive(:exists).and_return '1'
|
||||
allow(redis).to receive(:exists).with('vmpooler__token__abcdefghijklmnopqrstuvwxyz012345').and_return '1'
|
||||
allow(redis).to receive(:exists).with('vmpooler__ready__pool1').and_return '1'
|
||||
allow(redis).to receive(:exists).with('vmpooler__ready__pool2').and_return '1'
|
||||
allow(redis).to receive(:hget).with('vmpooler__token__abcdefghijklmnopqrstuvwxyz012345', 'user').and_return 'jdoe'
|
||||
allow(redis).to receive(:hset).and_return '1'
|
||||
allow(redis).to receive(:sadd).and_return '1'
|
||||
allow(redis).to receive(:scard).and_return '5'
|
||||
allow(redis).to receive(:spop).with('vmpooler__ready__pool1').and_return 'abcdefghijklmnop'
|
||||
allow(redis).to receive(:spop).with('vmpooler__ready__pool2').and_return 'qrstuvwxyz012345'
|
||||
allow(statsd).to receive(:increment).with('vmpooler.checkout.success.pool1', 1)
|
||||
allow(statsd).to receive(:increment).with('vmpooler.checkout.success.pool2', 1)
|
||||
allow(statsd).to receive(:increment).with('vmpooler.checkout.fail.pool2', 1)
|
||||
end
|
||||
|
||||
describe 'POST /vm/:template' do
|
||||
|
|
@ -489,7 +515,7 @@ describe Vmpooler::API::V1 do
|
|||
end
|
||||
|
||||
it 'returns a single VM for an alias' do
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__poolone").and_return(false)
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__pool1").and_return(1)
|
||||
|
||||
post "#{prefix}/vm/poolone", ''
|
||||
|
||||
|
|
@ -507,12 +533,23 @@ describe Vmpooler::API::V1 do
|
|||
|
||||
it 'fails on nonexistent pools' do
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__poolpoolpool").and_return(false)
|
||||
expect(redis).to receive(:exists).with("vmpooler__empty__poolpoolpool").and_return(false)
|
||||
expect(statsd).to receive(:increment).with('vmpooler.checkout.invalid', 1)
|
||||
|
||||
post "#{prefix}/vm/poolpoolpool", ''
|
||||
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
it 'fails on empty pools' do
|
||||
expect(redis).to receive(:exists).with("vmpooler__ready__emptypool").and_return(false)
|
||||
expect(redis).to receive(:exists).with("vmpooler__empty__emptypool").and_return(true)
|
||||
expect(statsd).to receive(:increment).with('vmpooler.checkout.empty', 1)
|
||||
post "#{prefix}/vm/emptypool", ''
|
||||
|
||||
expect_json(ok = false, http = 404)
|
||||
end
|
||||
|
||||
it 'returns multiple VMs' do
|
||||
post "#{prefix}/vm/pool1+pool2", ''
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue