mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Merge pull request #102 from sschneid/tag_index_and_reporting
(QENG-2056) Create daily tag indexes, report in /summary
This commit is contained in:
commit
6d06128481
4 changed files with 98 additions and 12 deletions
54
README.md
54
README.md
|
|
@ -79,14 +79,14 @@ Token-based authentication can be used when requesting or modifying VMs. The `/
|
||||||
Get information about an existing token.
|
Get information about an existing token.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ curl -u sschneid --url vmpooler.company.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y
|
$ curl -u jdoe --url vmpooler.company.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y
|
||||||
Enter host password for user 'sschneid':
|
Enter host password for user 'jdoe':
|
||||||
```
|
```
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"ok": true,
|
"ok": true,
|
||||||
"utpg2i2xswor6h8ttjhu3d47z53yy47y": {
|
"utpg2i2xswor6h8ttjhu3d47z53yy47y": {
|
||||||
"user": "sschneid",
|
"user": "jdoe",
|
||||||
"timestamp": "2015-04-28 19:17:47 -0700"
|
"timestamp": "2015-04-28 19:17:47 -0700"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -97,8 +97,8 @@ Enter host password for user 'sschneid':
|
||||||
Generate a new authentication token.
|
Generate a new authentication token.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ curl -X POST -u sschneid --url vmpooler.company.com/token
|
$ curl -X POST -u jdoe --url vmpooler.company.com/token
|
||||||
Enter host password for user 'sschneid':
|
Enter host password for user 'jdoe':
|
||||||
```
|
```
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
|
@ -112,8 +112,8 @@ Enter host password for user 'sschneid':
|
||||||
Delete an authentication token.
|
Delete an authentication token.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ curl -X DELETE -u sschneid --url vmpooler.company.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y
|
$ curl -X DELETE -u jdoe --url vmpooler.company.com/token/utpg2i2xswor6h8ttjhu3d47z53yy47y
|
||||||
Enter host password for user 'sschneid':
|
Enter host password for user 'jdoe':
|
||||||
```
|
```
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
|
@ -213,6 +213,10 @@ $ curl --url vmpooler.company.com/vm/pxpmtoonx7fiqg6
|
||||||
"lifetime": 12,
|
"lifetime": 12,
|
||||||
"running": 3.1,
|
"running": 3.1,
|
||||||
"state": "running",
|
"state": "running",
|
||||||
|
"tags": {
|
||||||
|
"department": "engineering",
|
||||||
|
"user": "jdoe"
|
||||||
|
},
|
||||||
"domain": "company.com"
|
"domain": "company.com"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -243,7 +247,7 @@ $ curl -X PUT -d '{"lifetime":"2"}' --url vmpooler.company.com/vm/fq6qlpjlsskycq
|
||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
$ curl -X PUT -d '{"tags":{"department":"engineering","user":"sschneid"}}' --url vmpooler.company.com/vm/fq6qlpjlsskycq6
|
$ curl -X PUT -d '{"tags":{"department":"engineering","user":"jdoe"}}' --url vmpooler.company.com/vm/fq6qlpjlsskycq6
|
||||||
```
|
```
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
|
@ -361,6 +365,20 @@ $ curl --url vmpooler.company.com/summary
|
||||||
"total": 14,
|
"total": 14,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"tag": {
|
||||||
|
"department": {
|
||||||
|
"engineering": 14,
|
||||||
|
"help desk": 10,
|
||||||
|
"IT": 44,
|
||||||
|
"total": 68
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"arodgers": 54,
|
||||||
|
"cmatthews": 10,
|
||||||
|
"jnelson": 4,
|
||||||
|
"total": 68
|
||||||
|
}
|
||||||
|
},
|
||||||
"daily": [
|
"daily": [
|
||||||
{
|
{
|
||||||
"date": "2015-03-11",
|
"date": "2015-03-11",
|
||||||
|
|
@ -385,6 +403,20 @@ $ curl --url vmpooler.company.com/summary
|
||||||
"count": {
|
"count": {
|
||||||
"total": 14
|
"total": 14
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"tag": {
|
||||||
|
"department": {
|
||||||
|
"engineering": 14,
|
||||||
|
"help desk": 10,
|
||||||
|
"IT": 44,
|
||||||
|
"total": 68
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"arodgers": 54,
|
||||||
|
"cmatthews": 10,
|
||||||
|
"jnelson": 4,
|
||||||
|
"total": 68
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -422,7 +454,8 @@ $ curl -G -d 'from=2015-03-10' -d 'to=2015-03-11' --url vmpooler.company.com/sum
|
||||||
"count": {
|
"count": {
|
||||||
"total": 0
|
"total": 0
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"tag": { }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"date": "2015-03-11",
|
"date": "2015-03-11",
|
||||||
|
|
@ -447,7 +480,8 @@ $ curl -G -d 'from=2015-03-10' -d 'to=2015-03-11' --url vmpooler.company.com/sum
|
||||||
"count": {
|
"count": {
|
||||||
"total": 14
|
"total": 14
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"tag": { }
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,28 @@ module Vmpooler
|
||||||
queue
|
queue
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_tag_metrics(backend, date_str)
|
||||||
|
tags = {}
|
||||||
|
|
||||||
|
backend.hgetall('vmpooler__tag__' + date_str).each do |key, value|
|
||||||
|
hostname = 'unknown'
|
||||||
|
tag = 'unknown'
|
||||||
|
|
||||||
|
if key =~ /\:/
|
||||||
|
hostname, tag = key.split(':', 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
tags[tag] ||= {}
|
||||||
|
tags[tag][value] ||= 0
|
||||||
|
tags[tag][value] += 1
|
||||||
|
|
||||||
|
tags[tag]['total'] ||= 0
|
||||||
|
tags[tag]['total'] += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
tags
|
||||||
|
end
|
||||||
|
|
||||||
def get_task_metrics(backend, task_str, date_str, opts = {})
|
def get_task_metrics(backend, task_str, date_str, opts = {})
|
||||||
opts = {:bypool => false}.merge(opts)
|
opts = {:bypool => false}.merge(opts)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,7 @@ module Vmpooler
|
||||||
pool: {}
|
pool: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
tag: {},
|
||||||
daily: []
|
daily: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,7 +125,8 @@ module Vmpooler
|
||||||
daily = {
|
daily = {
|
||||||
date: date.to_s,
|
date: date.to_s,
|
||||||
boot: get_task_metrics(backend, 'boot', date.to_s, :bypool => true),
|
boot: get_task_metrics(backend, 'boot', date.to_s, :bypool => true),
|
||||||
clone: get_task_metrics(backend, 'clone', date.to_s, :bypool => true)
|
clone: get_task_metrics(backend, 'clone', date.to_s, :bypool => true),
|
||||||
|
tag: get_tag_metrics(backend, date.to_s)
|
||||||
}
|
}
|
||||||
|
|
||||||
result[:daily].push(daily)
|
result[:daily].push(daily)
|
||||||
|
|
@ -194,6 +196,17 @@ module Vmpooler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
result[:daily].each do |daily|
|
||||||
|
daily[:tag].each_key do |tag|
|
||||||
|
result[:tag][tag] ||= {}
|
||||||
|
|
||||||
|
daily[:tag][tag].each do |key, value|
|
||||||
|
result[:tag][tag][key] ||= 0
|
||||||
|
result[:tag][tag][key] += value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
JSON.pretty_generate(result)
|
JSON.pretty_generate(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -530,6 +543,7 @@ module Vmpooler
|
||||||
when 'tags'
|
when 'tags'
|
||||||
arg.keys.each do |tag|
|
arg.keys.each do |tag|
|
||||||
backend.hset('vmpooler__vm__' + params[:hostname], 'tag:' + tag, arg[tag])
|
backend.hset('vmpooler__vm__' + params[:hostname], 'tag:' + tag, arg[tag])
|
||||||
|
backend.hset('vmpooler__tag__' + Date.today.to_s, params[:hostname] + ':' + tag, arg[tag])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -152,4 +152,20 @@ describe Vmpooler::API::Helpers do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
describe '#get_tag_metrics' do
|
||||||
|
let(:redis) { double('redis') }
|
||||||
|
|
||||||
|
it 'returns basic tag metrics' do
|
||||||
|
allow(redis).to receive(:hgetall).with('vmpooler__tag__2015-01-01').and_return({"abcdefghijklmno:tag" => "value"})
|
||||||
|
|
||||||
|
expect(subject.get_tag_metrics(redis, '2015-01-01')).to eq({"tag" => {"value"=>1, "total"=>1}})
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'calculates tag totals' do
|
||||||
|
allow(redis).to receive(:hgetall).with('vmpooler__tag__2015-01-01').and_return({"abcdefghijklmno:tag" => "value", "pqrstuvwxyz12345:tag" => "another_value"})
|
||||||
|
|
||||||
|
expect(subject.get_tag_metrics(redis, '2015-01-01')).to eq({"tag"=>{"value"=>1, "total"=>2, "another_value"=>1}})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue