Skip to content

Commit

Permalink
Merge pull request #96 from MikhailVerbitski/feature/ignored-paths-su…
Browse files Browse the repository at this point in the history
…pport

Add support for ignored_paths configuration and corresponding tests
  • Loading branch information
igorkasyanchuk authored Oct 25, 2024
2 parents 246128e + 121519c commit 3f68a55
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ RailsPerformance.setup do |config|
# for example when you have `current_user`
# config.verify_access_proc = proc { |controller| controller.current_user && controller.current_user.admin? }

# You can ignore endpoints with Rails standard notation controller#action
# config.ignored_endpoints = ['HomeController#contact']

# You can ignore request paths by specifying the beginning of the path.
# For example, all routes starting with '/admin' can be ignored:
# config.ignored_paths = ['/admin']

# store custom data for the request
# config.custom_data_proc = proc do |env|
# request = Rack::Request.new(env)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
# You can ignore endpoints with Rails standard notation controller#action
# config.ignored_endpoints = ['HomeController#contact']

# You can ignore request paths by specifying the beginning of the path.
# For example, all routes starting with '/admin' can be ignored:
# config.ignored_paths = ['/admin']

# store custom data for the request
# config.custom_data_proc = proc do |env|
# request = Rack::Request.new(env)
Expand Down
6 changes: 6 additions & 0 deletions lib/rails_performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def RailsPerformance.ignored_endpoints=(endpoints)
end
@@ignored_endpoints = []

mattr_reader :ignored_paths
def RailsPerformance.ignored_paths=(paths)
@@ignored_paths = Set.new(paths)
end
@@ignored_paths = []

# skip requests if it's inside Rails Performance view
mattr_accessor :skip
@@skip = false
Expand Down
1 change: 1 addition & 0 deletions lib/rails_performance/instrument/metrics_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def call(event_name, started, finished, event_id, payload)
event = ActiveSupport::Notifications::Event.new(event_name, started, finished, event_id, payload)

return if RailsPerformance.ignored_endpoints.include? "#{event.payload[:controller]}##{event.payload[:action]}"
return if RailsPerformance.ignored_paths.any? { |p| event.payload[:path].start_with?(p) }

record = {
controller: event.payload[:controller],
Expand Down
8 changes: 8 additions & 0 deletions test/rails_performance_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def requests_report_data
RailsPerformance.ignored_endpoints = original_ignored_endpoints
end

test "should respect ignored_paths configuration value" do
original_ignored_paths = RailsPerformance.ignored_paths
RailsPerformance.ignored_paths = ['/home']
get '/home/contact'
assert_equal requests_report_data.size, 0
RailsPerformance.ignored_paths = original_ignored_paths
end

test "should get index" do
setup_db
assert_equal requests_report_data.size, 1
Expand Down

0 comments on commit 3f68a55

Please sign in to comment.