(MAINT) Clarity refactor of Prom Stats code

Introducing the Prometheus Stats code into ABS showed that the Clarity
could be improved a bit with better variable naming, some refactoring
to reduce repitition and documenting the Metrics table itself.

Filtering these changes back to the vmpooler code base.
This commit is contained in:
John O'Connor 2020-07-30 20:25:37 +01:00
parent 2556ed6105
commit 0a6ad896f5
5 changed files with 173 additions and 56 deletions

View file

@ -4,7 +4,7 @@ require 'spec_helper'
describe 'prometheus' do
logger = MockLogger.new
params = { 'prefix': 'test', 'metrics_prefix': 'mtest', 'endpoint': 'eptest' }
params = { 'prefix' => 'test', 'prometheus_prefix' => 'mtest', 'prometheus_endpoint' => 'eptest' }
subject = Vmpooler::Metrics::Promstats.new(logger, params)
let(:logger) { MockLogger.new }
@ -24,7 +24,7 @@ describe 'prometheus' do
before { subject.instance_variable_set(:@p_metrics, { foo: foo_metrics }) }
it 'returns the metric for a given label including parsed labels' do
expect(subject.find_metric('foo.bar')).to include(metric_name: '_bar')
expect(subject.find_metric('foo.bar')).to include(metric_name: 'mtest_foo_bar')
expect(subject.find_metric('foo.bar')).to include(foo_metrics)
expect(subject.find_metric('foo.bar')).to include(labels_hash)
end
@ -57,7 +57,6 @@ describe 'prometheus' do
Prometheus::Client.config.data_store = Prometheus::Client::DataStores::Synchronized.new
subject.setup_prometheus_metrics(%i[api manager])
end
let(:MCOUNTER) { 1 }
describe '#setup_prometheus_metrics' do
it 'calls add_prometheus_metric for each item in list' do
@ -260,12 +259,12 @@ describe 'prometheus' do
po.get(labels: metric[:labels])
}.by(1)
end
it 'Increments label api_vm.#{method}.#{subpath}.#{operation}' do
it 'Increments label http_requests_vm_total.#{method}.#{subpath}.#{operation}' do
method = 'get'
subpath = 'template'
operation = 'something'
expect { subject.increment("api_vm.#{method}.#{subpath}.#{operation}") }.to change {
metric, po = subject.get("api_vm.#{method}.#{subpath}.#{operation}")
expect { subject.increment("http_requests_vm_total.#{method}.#{subpath}.#{operation}") }.to change {
metric, po = subject.get("http_requests_vm_total.#{method}.#{subpath}.#{operation}")
po.get(labels: metric[:labels])
}.by(1)
end