Skip to content

Commit

Permalink
FIX: stop raising NoMethodError when processing unregistered types
Browse files Browse the repository at this point in the history
  • Loading branch information
hx committed Jan 27, 2022
1 parent d44f9b3 commit e8a9add
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/prometheus_exporter/server/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ def process_hash(obj)
if collector = @collectors[obj["type"]]
collector.collect(obj)
else
metric = @metrics[obj["name"]]
if !metric
metric = register_metric_unsafe(obj)
end
metric = @metrics[obj["name"]] || register_metric_unsafe(obj) or
return

keys = obj["keys"] || {}
if obj["custom_labels"]
Expand Down
8 changes: 8 additions & 0 deletions test/server/collector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ def test_it_can_pass_options_to_histogram
assert_equal(text, collector.prometheus_metrics_text)
end

def test_it_does_not_raise_on_fail_to_register
collector = PrometheusExporter::Server::Collector.new
json = {
type: :something_with_no_registered_collector
}.to_json
collector.process(json) # Should not raise an exception; previously raised NoMethodError
end

def test_it_can_collect_sidekiq_metrics
collector = PrometheusExporter::Server::Collector.new
client = PipedClient.new(collector)
Expand Down

0 comments on commit e8a9add

Please sign in to comment.