Skip to content

Add channel_prefix support to AC redis/evented_redis adapters #27425

Merged
rafaelfranca merged 1 commit into
rails:masterfrom
matrix9180:action_cable_channel_prefix
Jan 18, 2017
Merged

Add channel_prefix support to AC redis/evented_redis adapters #27425
rafaelfranca merged 1 commit into
rails:masterfrom
matrix9180:action_cable_channel_prefix

Conversation

@matrix9180

@matrix9180 matrix9180 commented Dec 21, 2016

Copy link
Copy Markdown
Contributor

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.

@rails-bot

Copy link
Copy Markdown

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.

@matrix9180

Copy link
Copy Markdown
Contributor Author

cc @matthewd

@matrix9180 matrix9180 changed the title #27224 Add channel_prefix support to AC redis/evented_redis adapters Add channel_prefix support to AC redis/evented_redis adapters Dec 24, 2016

@rafaelfranca rafaelfranca left a comment

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

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.)

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Contributor Author

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.

Copy link
Copy Markdown
Member

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? 😅

Copy link
Copy Markdown
Contributor Author

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. :)

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

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.

@matrix9180

Copy link
Copy Markdown
Contributor Author

Github didn't send me any notices about the comments here. Will make the requested changes.

@matrix9180

Copy link
Copy Markdown
Contributor Author

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.

@matrix9180

Copy link
Copy Markdown
Contributor Author

r? @rafaelfranca @matthewd

@matrix9180

Copy link
Copy Markdown
Contributor Author

Added some documentation on SubscriptionAdapter configuration to the ActionCable Overview guide. Not sure if it's in-scope for this PR or not.

@rafaelfranca rafaelfranca left a comment

Copy link
Copy Markdown
Member

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?

@matrix9180

matrix9180 commented Jan 18, 2017 via email

Copy link
Copy Markdown
Contributor Author

@matrix9180

Copy link
Copy Markdown
Contributor Author

Rebased & squashed. Shall I open a separate PR for the documentation updates?

@rafaelfranca

Copy link
Copy Markdown
Member

It was fine in a separated commit here but since you pulled it off a separate PR would be better

@matrix9180

Copy link
Copy Markdown
Contributor Author

#27719 has the docs updates

@matrix9180

Copy link
Copy Markdown
Contributor Author

Noticed the build failed on 2.3.3. Transient error? Couldn't reproduce it locally.

@rafaelfranca

Copy link
Copy Markdown
Member

It should be fine now

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.

5 participants