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

Add support for ignored_paths configuration and corresponding tests #96

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
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']
Copy link
Owner

Choose a reason for hiding this comment

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

please also include it in the readme

the rest of the changes are fine 👍

Copy link
Author

Choose a reason for hiding this comment

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

done


# 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