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

Subscribe to additional Action View topic #1748

Conversation

hannahramadan
Copy link
Contributor

@hannahramadan hannahramadan commented Jan 20, 2023

  • subscribe to render_layout.action_view
  • add test for render_layout.action_view
  • refactor ActionViewSubscriber's start and finish to accommodate for new start and finish methods inherited from NotificationsSubscriber

closes #1512

Refactor ActionViewSubscriber methods `start` and `finish` (which now inherit from
NotificationsSubscriber to `start_segment` and `finish_segment`.
@hannahramadan hannahramadan changed the title Subscribe to Action View's render_layout Subscribe to render_layout.action_view Jan 20, 2023
@hannahramadan hannahramadan changed the title Subscribe to render_layout.action_view Subscribe to render_layout.action_view Jan 20, 2023
@hannahramadan hannahramadan changed the title Subscribe to render_layout.action_view Subscribe to additional Action View topic Jan 20, 2023
@hannahramadan hannahramadan marked this pull request as ready for review January 20, 2023 22:49
@hannahramadan hannahramadan changed the base branch from dev to action_controller_subscriber_additional_topic January 20, 2023 22:56
Comment on lines +113 to +128
def test_records_metrics_for_simple_layout
params = {:identifier => '/root/app/views/model/_layout.html.erb'}
nr_freeze_process_time
in_transaction do
@subscriber.start('render_layout.action_view', :id, params)
@subscriber.start('!render_layout.action_view', :id,
:virtual_path => 'model/_layout')
advance_process_time(2.0)
@subscriber.finish('!render_layout.action_view', :id,
:virtual_path => 'model/_layout')
@subscriber.finish('render_layout.action_view', :id, params)
end
expected = {:call_count => 1, :total_call_time => 2.0}

assert_metrics_recorded('View/model/_layout.html.erb/Layout' => expected)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you walk me through this test? What I think I'm seeing is:

  • pause the clock
  • start two similar events, but one with a false name (because it leads with a !), for the same params
  • advance the clock
  • finish both events
  • make sure only one of the events is recorded

Is that right, or is there something else going on too? Are only metrics supposed to be recorded for render_layout, not segments?

(It looks like a great test, I just want to make sure I'm reading it correctly!)

Copy link
Contributor

Choose a reason for hiding this comment

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

We chatted about this and the description above matches my understanding, except the events that start with ! are the ones we want recorded! Descriptive comment available in NewRelic::Agent::ActionViewSubscriber#recordable?

@github-actions
Copy link
Contributor

SimpleCov Report

Coverage Threshold
Line 93.19% 93%
Branch 84.65% 84%

Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

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

Great work, Hannah!


def metric_action(name)
case name
when /#{RENDER_TEMPLATE_EVENT_NAME}$/o then 'Rendering'
when RENDER_PARTIAL_EVENT_NAME then 'Partial'
when RENDER_COLLECTION_EVENT_NAME then 'Partial'
when RENDER_LAYOUT_EVENT_NAME then 'Layout'
else 'Unknown'
Copy link
Contributor

Choose a reason for hiding this comment

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

There are places where "Unknown" (capital U) are used, but for the subscriber stuff we've been consistently using "unknown" (lower case u). Perhaps this should be changed?

Copy link
Contributor

@kaylareopelle kaylareopelle Jan 21, 2023

Choose a reason for hiding this comment

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

Great catch. I wonder if we should define the UNKNOWN constant in NotificationsSubscriber so we have the same value everywhere?

@hannahramadan hannahramadan merged commit 57d6f61 into action_controller_subscriber_additional_topic Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rails notifications: subscribe to additional ActionView topics
3 participants