-
-
Notifications
You must be signed in to change notification settings - Fork 930
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 global key prefix for keys set by Redis transporter #1349
Add global key prefix for keys set by Redis transporter #1349
Conversation
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 is clean and functioning beautifully, thank you @gabor-boros !
- I tested this using the PR test instructions.
- I read through the code.
- Includes documentation for the new argument -- open question about where/how to update the docs generated from these comments.
@matusvalo @auvipy The linter issues are fixed and I had a question regarding documentation. Could you please take a look? |
Hi @gabor-boros thank you for your PR. The CI seems to be failing with following:
|
Unfortunatelly, I will also need more time for PR review so please be patient. |
821c4a4
to
d3f6435
Compare
@matusvalo The linter error is fixed. Let me know if you need me to update anything else. |
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.
@gabor-boros unfortunately, the code misses the case when default exchange is used:
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379>
(kombu38) matus@dev:~/dev/kombu$ cat p.py
import kombu
with kombu.Connection('redis://') as conn:
with conn.channel() as channel:
producer = kombu.Producer(channel)
producer.publish(
{'hello': 'world'},
retry=True,
routing_key='rkey',
retry_policy={
'interval_start': 0, # First retry immediately,
'interval_step': 2, # then increase by 2s for every retry.
'interval_max': 30, # but don't exceed 30s between retries.
'max_retries': 30, # give up after 30 tries.
},
transport_options={'global_keyprefix': 'myprefix'}
)
(kombu38) matus@dev:~/dev/kombu$ python p.py
(kombu38) matus@dev:~/dev/kombu$ redis-cli
127.0.0.1:6379> keys *
1) "rkey"
127.0.0.1:6379>
@matusvalo Oh! Thank you for pointing it out. I'll update the PR today to include that case too. |
@matusvalo I was curious why did the |
@gabor-boros yes it was typo but it is still not working (this time I have ensured that transport options were filled as expected):
BTW: I you look into codebase of kombu it cannot work since you are not adjusting key value here (method kombu/kombu/transport/redis.py Lines 829 to 834 in e5dbfed
Moreover, I have also problem with the PR itself. I think that it does changes on wrong layer. Key name adjustments should be done in lower layer in client itself. I propose a solution by :
class PrefixedClient:
def __init__(self, redis_client, prefix=''):
self.prefix = prefix
self.client = client
def lpush(queue, *args, **kwargs):
return self.client.lpush(prefix + queue, *args, **kwargs)
... # All other used methods needs to be implemented in similar way
The reason behind this is following:
|
@matusvalo Thank you for your feedback and for investigating the root cause of the issue. Adding Do you mean to create the |
@matusvalo Could you please help me to get unblocked and sort out the remaining bits of this PR? |
Sorry @gabor-boros for late reply. I was thinking about creating wrapper around |
@matusvalo Yes, it makes. I'll update the PR with the requested changes soon. |
d3f6435
to
1a358f2
Compare
This pull request introduces 2 alerts when merging 1a358f2 into 78f9b60 - view on LGTM.com new alerts:
|
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.
please fix the lint failures
@auvipy I wasn't satisfied with the constant names I introduced so renaming them solves two problems at once. |
This pull request introduces 2 alerts when merging 20e20e7 into 78f9b60 - view on LGTM.com new alerts:
|
This pull request introduces 2 alerts when merging 75e6113 into 78f9b60 - view on LGTM.com new alerts:
|
Co-authored-by: Matus Valo <[email protected]>
As per the suggestions, refactor the redis key prefixing to use a custom redis client that prefixes the keys it uses. The custom client implementation does not prefix every key by default as the way of prefixing keys may differ for some redis commands, instead it lists those keys that will be prefixed. In case of commands, where multiple keys can be passed as an argument, the custom client defines where the arg positions are starting and ending for the given command.
1c3d19a
to
0c12e02
Compare
@auvipy Thanks for noticing. I just squashed the commits and will fix the failing test |
This pull request introduces 3 alerts when merging 0c12e02 into 78f9b60 - view on LGTM.com new alerts:
|
This pull request introduces 3 alerts when merging d95ce1d into 78f9b60 - view on LGTM.com new alerts:
|
Co-authored-by: Matus Valo <[email protected]> refactor: use a custom redis client As per the suggestions, refactor the redis key prefixing to use a custom redis client that prefixes the keys it uses. The custom client implementation does not prefix every key by default as the way of prefixing keys may differ for some redis commands, instead it lists those keys that will be prefixed. In case of commands, where multiple keys can be passed as an argument, the custom client defines where the arg positions are starting and ending for the given command. docs: update authors doc (cherry picked from commit 3fe1f880846fa44b346496390e4198859662476c) squashed commits from celery#1349
@auvipy @matusvalo @thedrow I believe this is now ready for your review. |
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 seems that example from PR description (at least first one) is not working with the patch. When executed nothing is printed:
(kombu37) matus@matus-debian:~/zmaz$ python ex1.py
(kombu37) matus@matus-debian:~/zmaz$
But when I have adjusted the example in a way that I have removed prefixed option - hence connection looked like following:
connection = Connection('redis://')
The script worked fine:
(kombu37) matus@matus-debian:~/zmaz$ python ex1.py
<Message object at 0x7fa5df224c18 with details {'state': 'RECEIVED', 'content_type': 'text/plain', 'delivery_tag': 'c7bf6578-4fb7-4c52-a921-4a975046ebd2', 'body_length': 9, 'properties': {}, 'delivery_info': {'exchange': 'default', 'routing_key': ''}}>
I think this PR needs more love... I will try to allocate some time for investigation - please be patient...
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.
@gabor-boros I have found out the reason why the examples were failing - see my code review. The missing piece are unittests covering it. Unfortunately, I am not able to push changes directly to PR branch since you have unchecked this possibility.
Co-authored-by: Matus Valo <[email protected]>
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 tested this using the PR test instructions, and everything works perfectly now!
- I read through the code
-
I checked for accessibility issuesN/A - Includes documentation
Co-authored-by: Matus Valo <[email protected]> refactor: use a custom redis client As per the suggestions, refactor the redis key prefixing to use a custom redis client that prefixes the keys it uses. The custom client implementation does not prefix every key by default as the way of prefixing keys may differ for some redis commands, instead it lists those keys that will be prefixed. In case of commands, where multiple keys can be passed as an argument, the custom client defines where the arg positions are starting and ending for the given command. docs: update authors doc (cherry picked from commit 3fe1f880846fa44b346496390e4198859662476c) squashed commits from celery#1349 fix: wrap redis.parse_response to remove key prefixes Co-authored-by: Matus Valo <[email protected]> (cherry picked from commit 537534a) fix: typo (cherry picked from commit 434f923)
This pull request introduces 3 alerts when merging 5e6dcc8 into 9a91e8b - view on LGTM.com new alerts:
|
Thank you @gabor-boros ! |
* Introduce global key prefix for redis transport Co-authored-by: Matus Valo <[email protected]> * refactor: use a custom redis client As per the suggestions, refactor the redis key prefixing to use a custom redis client that prefixes the keys it uses. The custom client implementation does not prefix every key by default as the way of prefixing keys may differ for some redis commands, instead it lists those keys that will be prefixed. In case of commands, where multiple keys can be passed as an argument, the custom client defines where the arg positions are starting and ending for the given command. * test: fix unit tests by moving import statement * fix: wrap redis.parse_response to remove key prefixes Co-authored-by: Matus Valo <[email protected]> * fix: typo * fix: lint Co-authored-by: Antonin Delpeuch <[email protected]> Co-authored-by: Matus Valo <[email protected]> Co-authored-by: Jillian Vogel <[email protected]>
* Introduce global key prefix for redis transport Co-authored-by: Matus Valo <[email protected]> * refactor: use a custom redis client As per the suggestions, refactor the redis key prefixing to use a custom redis client that prefixes the keys it uses. The custom client implementation does not prefix every key by default as the way of prefixing keys may differ for some redis commands, instead it lists those keys that will be prefixed. In case of commands, where multiple keys can be passed as an argument, the custom client defines where the arg positions are starting and ending for the given command. * test: fix unit tests by moving import statement * fix: wrap redis.parse_response to remove key prefixes Co-authored-by: Matus Valo <[email protected]> * fix: typo * fix: lint Co-authored-by: Antonin Delpeuch <[email protected]> Co-authored-by: Matus Valo <[email protected]> Co-authored-by: Jillian Vogel <[email protected]> (cherry picked from commit 39584a1)
This PR continues the work of @wetneb, adding a global key prefix to queue names addressing #853. In the original PR, there were some unresolved issues that are resolved by this PR.
I believe most of the comments in the original approach were answered/resolved but #912 (review).
By adding the global key prefix to the
unacked_key
,unacked_index_key
,unacked_mutex_key
the prefix is applied for theunacked
andunacked_index
keys as well when the message is not ack'ed.Also, the implementation adds the global key prefix even to the queue received by producer. Meaning that in the following example, the Redis transport will handle
a_queue_name
as<prefix>a_queue_name
.Discussions:
Dependencies: None
Testing instructions:
docker run --name kombu_redis --rm -it -p 6379:6379 redis:latest
)docker exec -it kombu_redis redis-cli
)KEYS *
) and validate empty array returnedKEYS *
) and validate (only)_prefixed__kombu.binding.default
is listedFLUSHALL
)ipython
shell and validate the message object is printedKEYS *
) and validate (only)_prefixed_unacked
,_prefixed_unacked_index
, and_prefixed__kombu.binding.default
are listedKEYS *
) and validate that the_prefixed_a_queue_name
is restored and_prefixed__kombu.binding.default
is still listedSMEMBERS _prefixed__kombu.binding.default
and validate that1) "\x06\x16\x06\x16_prefixed_a_queue_name"
is presentExample 1
Example 2
Author notes and concerns:
The original PR listed some maintainer concerns, but -- as I mentioned -- I believe those were "discussed" though not confirmed. In case any questions from the original PR are still open and not addressed by this PR, please let me know.