-
Notifications
You must be signed in to change notification settings - Fork 4.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
feat(correlation-id) new "tracker" generator #1288
Conversation
ngx.var.pid, | ||
ngx.var.connection, -- connection serial number | ||
ngx.var.connection_requests, -- current number of requests made through a connection | ||
ngx.now() -- the current time stamp from the nginx cached time. |
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 we cache all those global accesses? Something like:
local fmt = string.format
local now = ngx.now
local pid = ngx.worker.pid -- only need to retrieve it once
-- ...
local var = ngx.var
return fmt(...,
var.server_addr,
var.server_port,
pid,
-- ...
now()
)
I'm afraid the chances of collision is really high with this generator. |
updated doc is done. |
yes, crossed my mind as well. But figured it would be easy to add a counter within the millisecond precision if needs be and it actually causes collisions. But maybe better to prevent it any way and add such a counter right away. |
in modern operating system, pid_t is int type, and the pid will be increasing(pid%MAX_INT), can you tell me that I'm wrong? @Tieske @thibaultcha |
not sure, but I don't think you should be caching the magic table Not sure I understand your comment (with pid_t) but the question imo is whether we'll assume there will be no collisions, or we code to make sure there are none. |
And dont forget subsequent requests may come to different nodes on different hosts who may have varying clocks which could increase the chances of collision. |
Correlation ID = "ip-port-pid-connection-connection_requests-timestamp"
code can be make sure there are no collisions, |
ngx.worker.pid(), | ||
ngx.var.connection, -- connection serial number | ||
ngx.var.connection_requests, -- current number of requests made through a connection | ||
ngx.now() -- the current time stamp from the nginx cached time. |
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 see you cached string.format
, but please do follow my other caching suggestions.
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 already gave it a quick edit; https://github.com/WALL-E/kong/pull/1
Right, the combination of |
@@ -79,6 +82,12 @@ describe("Correlation ID Plugin", function() | |||
end) | |||
end) | |||
|
|||
describe("tracker genetator", function() |
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.
typo: generator
@WALL-E can you rebase on @thibaultcha any more comments, or ready to merge? (after rebase) |
Manually applied the patch with minor modifications to next. Thank you for your contribution! |
Looking forward to next release :) |
I seem to have missed the beautiful moment :( |
SEE ALSO #1228