mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-26 01:58:41 -05:00
Add promstats component check
This commit is contained in:
parent
d47df61c19
commit
07d1ca2b2c
2 changed files with 17 additions and 4 deletions
|
|
@ -21,6 +21,7 @@ module Vmpooler
|
|||
REDIS_CONNECT_BUCKETS = [1.0, 2.0, 3.0, 5.0, 8.0, 13.0, 18.0, 23.0].freeze
|
||||
|
||||
@p_metrics = {}
|
||||
@torun = []
|
||||
|
||||
def initialize(logger, params = {})
|
||||
@prefix = params['prefix'] || 'vmpooler'
|
||||
|
|
@ -368,6 +369,7 @@ module Vmpooler
|
|||
# Top level method to register all the prometheus metrics.
|
||||
|
||||
def setup_prometheus_metrics(torun)
|
||||
@torun = torun
|
||||
@p_metrics = vmpooler_metrics_table
|
||||
@p_metrics.each do |name, metric_spec|
|
||||
# Only register metrics appropriate to api or manager
|
||||
|
|
@ -399,7 +401,10 @@ module Vmpooler
|
|||
metric_key = sublabels.shift.to_sym
|
||||
raise("Invalid Metric #{metric_key} for #{label}") unless @p_metrics.key? metric_key
|
||||
|
||||
metric = @p_metrics[metric_key].clone
|
||||
metric_spec = @p_metrics[metric_key]
|
||||
raise("Invalid Component #{component} for #{metric_key}") if (metric_spec[:torun] & @torun).nil?
|
||||
|
||||
metric = metric_spec.clone
|
||||
|
||||
if metric.key? :metric_suffixes
|
||||
metric_subkey = sublabels.shift.to_sym
|
||||
|
|
|
|||
|
|
@ -21,7 +21,10 @@ describe 'prometheus' do
|
|||
param_labels: %i[first second last] }
|
||||
end
|
||||
let!(:labels_hash) { { labels: { :first => nil, :second => nil, :last => nil } } }
|
||||
before { subject.instance_variable_set(:@p_metrics, { foo: foo_metrics }) }
|
||||
before {
|
||||
subject.instance_variable_set(:@p_metrics, { foo: foo_metrics, torun: %i[api] })
|
||||
subject.instance_variable_set(:@torun, [ :api ])
|
||||
}
|
||||
|
||||
it 'returns the metric for a given label including parsed labels' do
|
||||
expect(subject.find_metric('foo.bar')).to include(metric_name: 'mtest_foo_bar')
|
||||
|
|
@ -41,10 +44,15 @@ describe 'prometheus' do
|
|||
context "Node Name Handling" do
|
||||
let!(:node_metrics) do
|
||||
{ metric_name: 'connection_to',
|
||||
param_labels: %i[node] }
|
||||
param_labels: %i[node],
|
||||
torun: %i[api]
|
||||
}
|
||||
end
|
||||
let!(:nodename_hash) { { labels: { :node => 'test.bar.net'}}}
|
||||
before { subject.instance_variable_set(:@p_metrics, { connection_to: node_metrics }) }
|
||||
before {
|
||||
subject.instance_variable_set(:@p_metrics, { connection_to: node_metrics })
|
||||
subject.instance_variable_set(:@torun, [ :api ])
|
||||
}
|
||||
|
||||
it 'Return final remaining fields (e.g. fqdn) in last label' do
|
||||
expect(subject.find_metric('connection_to.test.bar.net')).to include(nodename_hash)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue