-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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 channel_prefix support to AC redis/evented_redis adapters #27425
Add channel_prefix support to AC redis/evented_redis adapters #27425
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (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. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
cc @matthewd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the pull request. It makes sense to me. I made some minor comments in the files.
module ActionCable | ||
module SubscriptionAdapter | ||
module Naming | ||
extend ActiveSupport::Concern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It don't need to be a concern.
@@ -11,6 +11,7 @@ | |||
module ActionCable | |||
module SubscriptionAdapter | |||
class EventedRedis < Base # :nodoc: | |||
include Naming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a blank line after this one
@@ -6,6 +6,7 @@ | |||
module ActionCable | |||
module SubscriptionAdapter | |||
class Redis < Base # :nodoc: | |||
include Naming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a blank line after this one
@@ -14,3 +14,9 @@ def cable_config | |||
super.merge(driver: "hiredis") | |||
end | |||
end | |||
|
|||
class RedisAdapterWithChannelPrefixTest < RedisAdapterTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure this test would pass if it was added without any of the above implementation.
"It still works" is a good baseline, but we'll also need to prove we're achieving our aim: that two differently-configured adapters don't interfere with each other. (Ideally, we can make that a generic test for all adapters -- some will pass naturally, and others will be able to pull in the namespacing module.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having trouble writing tests with two differently configured adapters as ActionCable::Server::Base
's config is defined as a cattr_accessor, so when I make a second one & give it a new config, it shares config with the first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I worked around my issue by subclassing ActionCable::Server::Base
and making config an instance var. I made the tests an included module in the tests as I wasn't sure how to generalize it as the pg adapter is scoped by database. To generalize it, we could have all adapters support channel prefix, as while it's not needed by all adapters, it shouldn't hurt anything either.
@@ -7,3 +7,7 @@ test: | |||
production: | |||
adapter: redis | |||
url: redis://localhost:6379/1 | |||
# To avoid channel collisions when multiple use the same Redis instance, | |||
# we prefix channel names with the app/environment name. | |||
# (https://redis.io/topics/pubsub#database-amp-scoping) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This info probably better lives in the "how to configure the adapter" documentation. Do we have any of that at the moment? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think docs around ac adapter configuration needs some work. Don't think it even mentions the existence of a Postgres adapter for example. :)
@@ -17,15 +18,15 @@ def initialize(*) | |||
end | |||
|
|||
def broadcast(channel, payload) | |||
redis_connection_for_broadcasts.publish(channel, payload) | |||
redis_connection_for_broadcasts.publish(channel_name(channel), payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making the adapter call channel_name
, if we prepend
the module, it could define broadcast
/subscribe
/unsubscribe
methods that mangle the name then super
.
@@ -0,0 +1,12 @@ | |||
module ActionCable | |||
module SubscriptionAdapter | |||
module Naming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:nodoc:
How about we call this ChannelPrefix
or similar? SubscriptionAdapter::Naming feels a bit too vague to me.
Github didn't send me any notices about the comments here. Will make the requested changes. |
I believe I addressed everything here except documentation updates, but I'm not sure where those would go as documentation on configuring actioncable is rather sparse at the moment. |
Added some documentation on SubscriptionAdapter configuration to the ActionCable Overview guide. Not sure if it's in-scope for this PR or not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you squash your first 6 commits in one?
Sure
…On Tue, Jan 17, 2017, 11:11 PM Rafael França ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Could you squash your first 6 commits in one?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#27425 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AWGp59TchMiZHaiYdLlYuW3ha5YrbyTFks5rTZECgaJpZM4LTLjs>
.
|
Rebased & squashed. Shall I open a separate PR for the documentation updates? |
It was fine in a separated commit here but since you pulled it off a separate PR would be better |
#27719 has the docs updates |
Noticed the build failed on 2.3.3. Transient error? Couldn't reproduce it locally. |
It should be fine now |
Add changelog entry for #27425 [ci skip]
Summary
#27224
In Redis, Pub/Sub has no relation to the key space. It was made to not interfere with it on any level, including database numbers.
Publishing on db 10, will be heard by a subscriber on db 1.
(https://redis.io/topics/pubsub#database-amp-scoping)
To avoid problems when multiple Rails applications use the same Redis instance, the redis/evented_redis subscription adapters now support a channel_prefix option (specified in cable.yml)
Other backends do not appear to have this issue.
The generated cable.yml has also been updated to reflect this change.