discourse / prometheus_exporter

A framework for collecting and aggregating prometheus metrics
MIT License
538 stars 155 forks source link

Incorrect keyword arguments handling in MethodProfiler #312

Closed simpl1g closed 7 months ago

simpl1g commented 8 months ago

Patched method that has keyword arguments can raise error

require 'bundler/inline'

gemfile do
  gem 'prometheus_exporter', '2.1.0'
end

require 'prometheus_exporter/instrumentation/method_profiler'

class Test
  def method(sql, cache: false, **settings)
    puts "sql -> #{sql}"
    puts "cache -> #{cache}"
    puts "settings -> #{settings}"
  end
end

PrometheusExporter::Instrumentation::MethodProfiler.patch(Test, [:method], :some_name, instrument: :prepend)

t = Test.new

t.method('select * from table')
# sql -> select * from table
# cache -> false
# settings -> {}

t.method('select * from table', cache: true, other_setting: false)
# => wrong number of arguments (given 2, expected 1) (ArgumentError)

@SamSaffron I can create pull request that:

Are you ok with these changes?