-
Notifications
You must be signed in to change notification settings - Fork 32
🐛 fix rabbit mq unique queue name #6328
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
🐛 fix rabbit mq unique queue name #6328
Conversation
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6328 +/- ##
=========================================
+ Coverage 84.5% 88.5% +3.9%
=========================================
Files 10 962 +952
Lines 214 43819 +43605
Branches 25 260 +235
=========================================
+ Hits 181 38801 +38620
- Misses 23 4960 +4937
- Partials 10 58 +48
Flags with carried forward coverage won't be shown. Click here to find out more.
|
| RABBIT_QUEUE_MESSAGE_DEFAULT_TTL_MS: Final[int] = 15 * _MINUTE * 1000 | ||
|
|
||
| CHARACTERS = string.ascii_letters + string.digits | ||
| _GENERATE_RANDOM_STRING_LENGTH = 6 |
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.
@pcrespov I guess I can create a function for this and add it to utils_secrets.py? we do not yet have one that combines letters and numbers as far as I can see.
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 guess here generate_passcode might work for this case as well.
In any case, more than a secure here the idea is to generate some sort of unique identifer.
I would start a new module with helpesr like servicelib.identifiers_utils and add functions that can produce unique identifiers e.g. based on some unique feature (time, hostname, etc...)
import hashlib
import time
from models_library.basic_types import IdStr
def short_sha256(input_string, length=8) -> IdStr:
sha_signature = hashlib.sha256(input_string.encode()).hexdigest()
return IdStr(sha_signature[:length])
# Example usage
def get_rabbitma_client_unique_name(prefix: str)
hostname = socket.gethostname()
unique_id = short_sha256( f"{time.time()}" + hostname , length=8)
return f"{prefix}_{hostname}_{unique_id}"NOTE that the value you pass to input_string provides the "uniqueness" scope of that value. Therefore you use as discriminator.
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.
see my comment. thanks! And let's see what happens.
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.
Thx. Left some comments for your consideration.
Let's check after they merge whether they restart faster. Add the 🚨
| RABBIT_QUEUE_MESSAGE_DEFAULT_TTL_MS: Final[int] = 15 * _MINUTE * 1000 | ||
|
|
||
| CHARACTERS = string.ascii_letters + string.digits | ||
| _GENERATE_RANDOM_STRING_LENGTH = 6 |
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 guess here generate_passcode might work for this case as well.
In any case, more than a secure here the idea is to generate some sort of unique identifer.
I would start a new module with helpesr like servicelib.identifiers_utils and add functions that can produce unique identifiers e.g. based on some unique feature (time, hostname, etc...)
import hashlib
import time
from models_library.basic_types import IdStr
def short_sha256(input_string, length=8) -> IdStr:
sha_signature = hashlib.sha256(input_string.encode()).hexdigest()
return IdStr(sha_signature[:length])
# Example usage
def get_rabbitma_client_unique_name(prefix: str)
hostname = socket.gethostname()
unique_id = short_sha256( f"{time.time()}" + hostname , length=8)
return f"{prefix}_{hostname}_{unique_id}"NOTE that the value you pass to input_string provides the "uniqueness" scope of that value. Therefore you use as discriminator.
| random_string = "".join( | ||
| random.choice(CHARACTERS) for _ in range(_GENERATE_RANDOM_STRING_LENGTH) | ||
| ) | ||
| return f"{base_name}_{socket.gethostname()}_{random_string}" |
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 not convinced by this. The whole idea of using the hostname here was to make it unique.
I would rather drop the hostname and use a larger random string, which makes collisions less likely. You might even get away with using a uuid from which you strip the -.
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 note that all your tests will fail if something fishy is happening with the queue names. You might want to check what your change introduced.


What do these changes do?
Related issue/s
How to test
Dev-ops checklist