Merge pull request #395 from jcoconnor/MAINT-Remove-Tokens

(MAINT) Normalise all tokens for stats
This commit is contained in:
Gene Liverman 2020-08-21 12:37:45 -04:00 committed by GitHub
commit e533223db8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 1 deletions

View file

@ -114,6 +114,9 @@ module Vmpooler
path
.gsub(%r{/vm/.+$}, '/vm')
.gsub(%r{/ondemand/.+$}, '/ondemand')
.gsub(%r{/token/.+$}, '/token')
.gsub(%r{/lib/.+$}, '/lib')
.gsub(%r{/img/.+$}, '/img')
end
end
end

View file

@ -55,7 +55,7 @@ describe Vmpooler::Metrics::Promstats::CollectorMiddleware do
expect(registry.get(metric).get(labels: labels)).to include("0.1" => 0, "0.25" => 1)
end
it 'normalizes paths cotaining /vm by default' do
it 'normalizes paths containing /vm by default' do
expect(Benchmark).to receive(:realtime).and_yield.and_return(0.3)
get '/foo/vm/bar-mumble-flame'
@ -83,6 +83,62 @@ describe Vmpooler::Metrics::Promstats::CollectorMiddleware do
expect(registry.get(metric).get(labels: labels)).to include("0.1" => 0, "0.5" => 1)
end
it 'normalizes paths containing /token by default' do
expect(Benchmark).to receive(:realtime).and_yield.and_return(0.3)
get '/token/secret-token-name'
metric = :http_server_requests_total
labels = { method: 'get', path: '/token', code: '200' }
expect(registry.get(metric).get(labels: labels)).to eql(1.0)
metric = :http_server_request_duration_seconds
labels = { method: 'get', path: '/token' }
expect(registry.get(metric).get(labels: labels)).to include("0.1" => 0, "0.5" => 1)
end
it 'normalizes paths containing /api/v1/token by default' do
expect(Benchmark).to receive(:realtime).and_yield.and_return(0.3)
get '/api/v1/token/secret-token-name'
metric = :http_server_requests_total
labels = { method: 'get', path: '/api/v1/token', code: '200' }
expect(registry.get(metric).get(labels: labels)).to eql(1.0)
metric = :http_server_request_duration_seconds
labels = { method: 'get', path: '/api/v1/token' }
expect(registry.get(metric).get(labels: labels)).to include("0.1" => 0, "0.5" => 1)
end
it 'normalizes paths containing /img by default' do
expect(Benchmark).to receive(:realtime).and_yield.and_return(0.3)
get '/img/image-name'
metric = :http_server_requests_total
labels = { method: 'get', path: '/img', code: '200' }
expect(registry.get(metric).get(labels: labels)).to eql(1.0)
metric = :http_server_request_duration_seconds
labels = { method: 'get', path: '/img' }
expect(registry.get(metric).get(labels: labels)).to include("0.1" => 0, "0.5" => 1)
end
it 'normalizes paths containing /lib by default' do
expect(Benchmark).to receive(:realtime).and_yield.and_return(0.3)
get '/lib/xxxxx.js'
metric = :http_server_requests_total
labels = { method: 'get', path: '/lib', code: '200' }
expect(registry.get(metric).get(labels: labels)).to eql(1.0)
metric = :http_server_request_duration_seconds
labels = { method: 'get', path: '/lib' }
expect(registry.get(metric).get(labels: labels)).to include("0.1" => 0, "0.5" => 1)
end
context 'when the app raises an exception' do
let(:original_app) do
lambda do |env|