Skip to content

Commit

Permalink
Merge pull request #2745 from newrelic/addactopics
Browse files Browse the repository at this point in the history
include additional AC topics in Rails subscription
  • Loading branch information
fallwith authored Jul 15, 2024
2 parents f3d2ae6 + 2861ca9 commit c6f8b72
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@
NewRelic::Agent::Instrumentation::ActionControllerSubscriber \
.subscribe(/^process_action.action_controller$/)

subs = %w[send_file
subs = %w[exist_fragment?
expire_fragment
halted_callback
read_fragment
redirect_to
send_data
send_file
send_stream
redirect_to
halted_callback
unpermitted_parameters]
write_fragment
unpermitted_parameters].map { |s| Regexp.escape(s) }

# have to double escape period because its going from string -> regex
NewRelic::Agent::Instrumentation::ActionControllerOtherSubscriber \
.subscribe(Regexp.new("^(#{subs.join('|')})\\.action_controller$"))
.subscribe(Regexp.new("^(?:#{subs.join('|')})\\.action_controller$"))
end
end
83 changes: 82 additions & 1 deletion test/multiverse/suites/rails/action_controller_other_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# frozen_string_literal: true

require './app'

if defined?(ActionController::Live)

class DataController < ApplicationController
CACHE_KEY = :the_key

# send_file
def send_test_file
send_file(Rails.root + '../../../../README.md')
Expand Down Expand Up @@ -35,6 +36,26 @@ def do_a_redirect
def not_allowed
params.permit(:only_this)
end

# exist_fragment?
def exist_fragment
fragment_exist?(CACHE_KEY)
end

# expire_fragment
def expire_test_fragment
expire_fragment(CACHE_KEY)
end

# read_fragment
def read_test_fragment
read_fragment(CACHE_KEY)
end

# write_fragment
def write_test_fragment
write_fragment(CACHE_KEY, 'fragment')
end
end

class ActionControllerDataTest < ActionDispatch::IntegrationTest
Expand Down Expand Up @@ -121,6 +142,66 @@ def test_unpermitted_parameters
assert_metrics_recorded(['Controller/data/not_allowed', segment_name])
end

def test_exist_fragment?
skip if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('6.0.0')

get('/data/exist_fragment')

node = find_node_with_name_matching(last_transaction_trace, /ActionController/)

assert node, 'Could not find an >>ActionController<< metric while testing >>exist_fragment?<<'
child = node.children.detect { |n| n.metric_name.include?('FileStore/exist') }

assert child, 'Could not find a >>Filestore/exist<< child of the ActionController node!'
assert_includes child.params[:key], DataController::CACHE_KEY,
"Expected to find the cache key >>#{DataController::CACHE_KEY}<< in the node params!"
end

def test_expire_fragment
skip if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('6.0.0')

get('/data/expire_test_fragment')

node = find_node_with_name_matching(last_transaction_trace, /ActionController/)

assert node, 'Could not find an >>ActionController<< metric while testing >>expire_fragment<<'
child = node.children.detect { |n| n.metric_name.include?('FileStore/delete') }

assert child, 'Could not find a >>Filestore/delete<< child of the ActionController node!'
assert_includes child.params[:key], DataController::CACHE_KEY,
"Expected to find the cache key >>#{DataController::CACHE_KEY}<< in the node params!"
end

def test_read_fragment
skip if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('6.0.0')

get('/data/read_test_fragment')

node = find_node_with_name_matching(last_transaction_trace, /ActionController/)

assert node, 'Could not find an >>ActionController<< metric while testing >>read_fragment<<'
child = node.children.detect { |n| n.metric_name.include?('FileStore/read') }

assert child, 'Could not find a >>Filestore/read<< child of the ActionController node!'
assert_includes child.params[:key], DataController::CACHE_KEY,
"Expected to find the cache key >>#{DataController::CACHE_KEY}<< in the node params!"
end

def test_write_fragment
skip if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new('6.0.0')

get('/data/write_test_fragment')

node = find_node_with_name_matching(last_transaction_trace, /ActionController/)

assert node, 'Could not find an >>ActionController<< metric while testing >>write_fragment<<'
child = node.children.detect { |n| n.metric_name.include?('FileStore/write') }

assert child, 'Could not find a >>Filestore/write<< child of the ActionController node!'
assert_includes child.params[:key], DataController::CACHE_KEY,
"Expected to find the cache key >>#{DataController::CACHE_KEY}<< in the node params!"
end

class TestClassActionController; end

def test_no_metric_naming_error
Expand Down

0 comments on commit c6f8b72

Please sign in to comment.