FIX: kwargs patching (#313)
Amends method profiler patching to use Ruby 3.0 patterns and enforces Ruby 3.0 and up.
This commit is contained in:
parent
d1724827d9
commit
e23bac5471
|
@ -4,4 +4,11 @@ inherit_gem:
|
|||
AllCops:
|
||||
Exclude:
|
||||
- 'gemfiles/**/*'
|
||||
- 'vendor/**/*'
|
||||
- 'vendor/**/*'
|
||||
|
||||
Discourse/Plugins/NoMonkeyPatching:
|
||||
Enabled: false
|
||||
|
||||
Discourse/Plugins/NamespaceMethods:
|
||||
Exclude:
|
||||
- bin/prometheus_exporter
|
||||
|
|
|
@ -40,7 +40,7 @@ To learn more see [Instrumenting Rails with Prometheus](https://samsaffron.com/a
|
|||
|
||||
## Requirements
|
||||
|
||||
Minimum Ruby of version 2.6.0 is required, Ruby 2.5.0 is EOL as of March 31st 2021.
|
||||
Minimum Ruby of version 3.0.0 is required, Ruby 2.7 is EOL as of March 31st 2023.
|
||||
|
||||
## Migrating from v0.x
|
||||
|
||||
|
@ -884,7 +884,7 @@ prometheus_exporter -p 8080 \
|
|||
--prefix 'foo_'
|
||||
```
|
||||
|
||||
You can use `-b` option to bind the `prometheus_exporter` web server to any IPv4 interface with `-b 0.0.0.0`,
|
||||
You can use `-b` option to bind the `prometheus_exporter` web server to any IPv4 interface with `-b 0.0.0.0`,
|
||||
any IPv6 interface with `-b ::`, or `-b ANY` to any IPv4/IPv6 interfaces available on your host system.
|
||||
|
||||
#### Enabling Basic Authentication
|
||||
|
|
|
@ -2,4 +2,6 @@
|
|||
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "activerecord", "~> 7.0.0"
|
||||
|
||||
gemspec path: "../"
|
||||
|
|
|
@ -44,7 +44,7 @@ class PrometheusExporter::Instrumentation::MethodProfiler
|
|||
patch_source_line = __LINE__ + 3
|
||||
patches = methods.map do |method_name|
|
||||
<<~RUBY
|
||||
def #{method_name}(*args, &blk)
|
||||
def #{method_name}(...)
|
||||
unless prof = Thread.current[:_method_profiler]
|
||||
return super
|
||||
end
|
||||
|
@ -75,13 +75,13 @@ class PrometheusExporter::Instrumentation::MethodProfiler
|
|||
<<~RUBY
|
||||
unless defined?(#{method_name}__mp_unpatched)
|
||||
alias_method :#{method_name}__mp_unpatched, :#{method_name}
|
||||
def #{method_name}(*args, &blk)
|
||||
def #{method_name}(...)
|
||||
unless prof = Thread.current[:_method_profiler]
|
||||
return #{method_name}__mp_unpatched(*args, &blk)
|
||||
return #{method_name}__mp_unpatched(...)
|
||||
end
|
||||
begin
|
||||
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||
#{method_name}__mp_unpatched(*args, &blk)
|
||||
#{method_name}__mp_unpatched(...)
|
||||
ensure
|
||||
data = (prof[:#{name}] ||= {duration: 0.0, calls: 0})
|
||||
data[:duration] += Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
|
||||
|
|
|
@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|||
spec.add_development_dependency "oj", "~> 3.0"
|
||||
spec.add_development_dependency "rack-test", "~> 0.8.3"
|
||||
spec.add_development_dependency "minitest-stub-const", "~> 0.6"
|
||||
spec.add_development_dependency "rubocop-discourse", ">2"
|
||||
spec.add_development_dependency "rubocop-discourse", ">= 3"
|
||||
spec.add_development_dependency "appraisal", "~> 2.3"
|
||||
spec.add_development_dependency "activerecord", "~> 6.0.0"
|
||||
spec.add_development_dependency "redis", "> 5"
|
||||
|
@ -42,5 +42,5 @@ Gem::Specification.new do |spec|
|
|||
if !RUBY_ENGINE == 'jruby'
|
||||
spec.add_development_dependency "raindrops", "~> 0.19"
|
||||
end
|
||||
spec.required_ruby_version = '>= 2.6.0'
|
||||
spec.required_ruby_version = '>= 3.0.0'
|
||||
end
|
||||
|
|
|
@ -22,7 +22,7 @@ class PrometheusInstrumentationMethodProfilerTest < Minitest::Test
|
|||
def test_alias_method_source_location
|
||||
file, line = SomeClassPatchedUsingAliasMethod.instance_method(:some_method).source_location
|
||||
source = File.read(file).lines[line - 1].strip
|
||||
assert_equal 'def #{method_name}(*args, &blk)', source
|
||||
assert_equal 'def #{method_name}(...)', source
|
||||
end
|
||||
|
||||
def test_alias_method_preserves_behavior
|
||||
|
@ -32,7 +32,7 @@ class PrometheusInstrumentationMethodProfilerTest < Minitest::Test
|
|||
def test_prepend_source_location
|
||||
file, line = SomeClassPatchedUsingPrepend.instance_method(:some_method).source_location
|
||||
source = File.read(file).lines[line - 1].strip
|
||||
assert_equal 'def #{method_name}(*args, &blk)', source
|
||||
assert_equal 'def #{method_name}(...)', source
|
||||
end
|
||||
|
||||
def test_prepend_preserves_behavior
|
||||
|
|
Loading…
Reference in New Issue