-
-
Notifications
You must be signed in to change notification settings - Fork 59
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 RequestID to generate unique Identifier for each request #326
Conversation
This will also generate unique identifiers across multiple instances of a Humminbird application
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #326 +/- ##
=======================================
Coverage 84.62% 84.62%
=======================================
Files 78 79 +1
Lines 4831 4845 +14
=======================================
+ Hits 4088 4100 +12
- Misses 743 745 +2 ☔ View full report in Codecov by Sentry. |
Pull request benchmark comparison [ubuntu-latest] with 'main' run at 2023-12-31T17:10:54+00:00 |
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 agree with this change, at the very least for 2.x. Though I'm wondering to what extend users depend on the nature of this having been an integer
This was a request from someone using v1. So I'd prefer to merge into v1. Hmmm, I don't know about the integer thing, The fact it was an integer is really a side effect of how the id was generated. I can be explicit in the release notes about the id change and how it might affect users who depended on it being an integer that fitted into a Int64. |
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 realize there might be someone somewhere somehow counting on the ID being an Int, but that's quit unlikely as the id is only used in the log statement (unlike Vapor which exposes the request id to the public, for reasons that i think are legitimate but i still don't remember).
var description: String { | ||
String(Self.high, radix: 16) + self.formatAsHexWithLeadingZeros(self.low) | ||
} |
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's certainly cleaner this way, but it still feels unnecessary to transform
high
to aString
once perRequestID.description
call, considering.description
will be common due to the logging statement. - Doesn't this hex description (partially) defeat the point of having a nice easily-human-readable integer as the request's id? At that point a random UUID could just be the simpler solution although i assume it's somewhat more costly to create.
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.
Good point about transforming high
repeatedly.
I'm not using UUID because one it requires Foundation and two it is slower to generate. I reduced it to hex to shorten the id and the first 16 chars end up being a process id. Anyway not sure a 128bit integer is human readable.
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.
Hmm fair enough. I now think it's fine being a hex 🤔 i was thinking someone might rather read/have it as a decimal number, but I can't come up with enough reasons why that should be important. They can always turn the hex back to an integer trivially if it's that important 🤔
I think @Joannis requested that. He requested the same of HB and a |
Previously this was just an incrementing
Int
, but it was pointed out that ids across instances of an Hummingbird app would clash as they all started at zero. This is now two integers one identifying the instance and the other an incrementingUInt64
started at a random point in its range. This has all been encapsulated in aRequestID
type.