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 ActiveSupport::Notifications hook to ActionCable::Server.broadcast #24988

Merged
merged 1 commit into from Jul 3, 2016

Conversation

mwear
Copy link
Contributor

@mwear 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
Copy link

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.

@@ -1,2 +1,5 @@
* Add ActiveSupport::Notifications hook to ActionCable::Server.broadcast
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong CHANGELOG.md file 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😳

@mwear mwear force-pushed the action_cable_broadcast_notifications branch from ef663d0 to 6986b54 Compare May 12, 2016 00:52
@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Should this be in Broadcaster#broadcast?

Copy link
Contributor Author

@mwear mwear May 12, 2016

Choose a reason for hiding this comment

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

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
@mwear mwear force-pushed the action_cable_broadcast_notifications branch from 6986b54 to 35b6382 Compare May 12, 2016 01:58
This addition of this notification hook will give users better visibility
into the messages being sent over the PubSub adapter.
@mwear mwear force-pushed the action_cable_broadcast_notifications branch from 35b6382 to f3ba0c1 Compare May 12, 2016 17:58
@matthewd matthewd merged commit 08a9074 into rails:master Jul 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants