Skip to content

Commit

Permalink
normalize labels in metric matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
senid231 committed Nov 29, 2023
1 parent bad109f commit d1466fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/prometheus_exporter/ext/rspec/metric_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def matches?(actual)

return false unless values_match?(metric_class, actual.class)
return false unless values_match?(metric_name, actual.name.to_s)
return false if !metric_payload.nil? && !values_match?(metric_payload, actual.to_h)

actual_payload = actual.to_h.transform_keys { |labels| labels.transform_keys(&:to_s) }
return false if !metric_payload.nil? && !values_match?(metric_payload, actual_payload)

true
end
Expand Down
4 changes: 2 additions & 2 deletions spec/prometheus_exporter/ext/metric/gauge_with_time_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@
before do
metric.observe(1, 'foo' => 'bar')
sleep 0.2
metric.observe(2, 'baz' => 'boo')
metric.observe(2, baz: 'boo')
end

it 'has correct to_h' do
expect(metric.to_h).to match(
{
{ 'foo' => 'bar' } => [1, ms_since_epoch],
{ 'baz' => 'boo' } => [2, ms_since_epoch]
{ baz: 'boo' } => [2, ms_since_epoch]
}
)
end
Expand Down

0 comments on commit d1466fc

Please sign in to comment.