Skip to content

Commit

Permalink
Merge pull request #397 from puppetlabs/maint-promstats-check
Browse files Browse the repository at this point in the history
(maint) Add promstats component check
  • Loading branch information
jcoconnor authored Sep 1, 2020
2 parents d47df61 + 07d1ca2 commit bdf77a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/vmpooler/metrics/promstats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Promstats < Metrics
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'
Expand Down Expand Up @@ -368,6 +369,7 @@ def add_prometheus_metric(metric_spec, name, docstring)
# 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
Expand Down Expand Up @@ -399,7 +401,10 @@ def find_metric(label)
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
Expand Down
14 changes: 11 additions & 3 deletions spec/unit/promstats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
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')
Expand All @@ -41,10 +44,15 @@
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)
Expand Down

0 comments on commit bdf77a9

Please sign in to comment.