Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kwargs patching #313

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--ignore-unrecognized-cops
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required for compatibility with older versions of rubocop-discourse

9 changes: 8 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@ inherit_gem:
AllCops:
Exclude:
- 'gemfiles/**/*'
- 'vendor/**/*'
- 'vendor/**/*'

Discourse/Plugins/NoMonkeyPatching:
Enabled: false

Discourse/Plugins/NamespaceMethods:
Exclude:
- bin/prometheus_exporter
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions gemfiles/ar_70.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

source "https://rubygems.org"

gem "activerecord", "~> 7.0.0"

gemspec path: "../"
8 changes: 4 additions & 4 deletions lib/prometheus_exporter/instrumentation/method_profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def self.define_methods_on_module(klass, methods, name)
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
Expand Down Expand Up @@ -75,13 +75,13 @@ def self.patch_using_alias_method(klass, methods, name)
<<~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
Expand Down
4 changes: 2 additions & 2 deletions prometheus_exporter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ 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"
spec.add_development_dependency "m"
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
4 changes: 2 additions & 2 deletions test/instrumentation/method_profiler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def some_method
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
Expand All @@ -32,7 +32,7 @@ def test_alias_method_preserves_behavior
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
Expand Down