Add ActiveSupport::Notifications hook to ActionCable::Server.broadcast #24988

Merged
merged 1 commit into from Jul 3, 2016

Conversation

Projects
None yet
6 participants
@mwear
Contributor

mwear commented May 12, 2016

Summary

ActionCable already has ActiveSupport::Notifications hooks around a number of operations in Channel::Base. It would be nice to gain visibility into messages sent via ActionCable.server.broadcast. This PR adds a notification hook to the broadcast method that will allow users to monitor and profile the performance messages being sent over the PubSub adapter.

@rails-bot

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot May 12, 2016

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

actionmailer/CHANGELOG.md
@@ -1,2 +1,5 @@
+* Add ActiveSupport::Notifications hook to ActionCable::Server.broadcast

This comment has been minimized.

@maclover7

maclover7 May 12, 2016

Member

Wrong CHANGELOG.md file 😬

@maclover7

maclover7 May 12, 2016

Member

Wrong CHANGELOG.md file 😬

This comment has been minimized.

@mwear

mwear May 12, 2016

Contributor

😳

@mwear

mwear May 12, 2016

Contributor

😳

@@ -20,7 +20,10 @@ module Server
module Broadcasting
# Broadcast a hash directly to a named <tt>broadcasting</tt>. This will later be JSON encoded.
def broadcast(broadcasting, message, coder: ActiveSupport::JSON)
- broadcaster_for(broadcasting, coder: coder).broadcast(message)
+ payload = { broadcasting: broadcasting, message: message, coder: coder }
+ ActiveSupport::Notifications.instrument("broadcast.action_cable", payload) do

This comment has been minimized.

@jeremy

jeremy May 12, 2016

Member

Should this be in Broadcaster#broadcast?

@jeremy

jeremy May 12, 2016

Member

Should this be in Broadcaster#broadcast?

This comment has been minimized.

@mwear

mwear May 12, 2016

Contributor

Initially I put the notification code in the broadcast method on the Broadcasting module since that was the entry point for the public API. After your comment I noticed that broadcaster_for is part of the public API and returns a Broadcaster instance. Putting the notification in Broadcaster#broadcast is indeed the best place for the notification code. Thanks for pointing that out!

@mwear

mwear May 12, 2016

Contributor

Initially I put the notification code in the broadcast method on the Broadcasting module since that was the entry point for the public API. After your comment I noticed that broadcaster_for is part of the public API and returns a Broadcaster instance. Putting the notification in Broadcaster#broadcast is indeed the best place for the notification code. Thanks for pointing that out!

@jeremy jeremy assigned jeremy and unassigned pixeltrix May 12, 2016

Add ActiveSupport::Notifications hook to Broadcaster#broadcast
This addition of this notification hook will give users better visibility
into the messages being sent over the PubSub adapter.

@matthewd matthewd merged commit 08a9074 into rails:master Jul 3, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment