-
Notifications
You must be signed in to change notification settings - Fork 849
Querier active api tracker #7216
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
| "github.com/edsrzf/mmap-go" | ||
| ) | ||
|
|
||
| type APITracker struct { |
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.
Can we make this tracker generic? Move to a better package maybe in utils. I feel it can be used in query frontend and more components as well. Maybe a generic name can be RequestsTracker. Make sure when inserting entries we can insert arbitrary entries?
| entryMap["timestamp_sec"] = time.Now().Unix() | ||
| entryMap["Path"] = r.URL.Path | ||
| entryMap["Method"] = r.Method | ||
| entryMap["User-Agent"] = r.Header.Get("User-Agent") |
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.
Why do we need this?
| entryMap["Method"] = r.Method | ||
| entryMap["User-Agent"] = r.Header.Get("User-Agent") | ||
| entryMap["X-Scope-OrgID"] = r.Header.Get("X-Scope-OrgID") | ||
| entryMap["X-Request-ID"] = r.Header.Get("X-Request-ID") |
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.
We shouldn't hardcode the request ID. It is extracted from the context
| entryMap["Path"] = r.URL.Path | ||
| entryMap["Method"] = r.Method | ||
| entryMap["User-Agent"] = r.Header.Get("User-Agent") | ||
| entryMap["X-Scope-OrgID"] = r.Header.Get("X-Scope-OrgID") |
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.
Extract user ID from context. There is helper function to do it
Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
justinjung04
left a comment
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.
LGTM, thank you!
Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
Signed-off-by: Friedrich Gonzalez <1517449+friedrichg@users.noreply.github.com>
|
One issue that still needs to be addressed is that the request id is not yet in the context at the time of it being added to the tracker. Getting request id from context currently returns an empty string |
Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
…caped characters Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
| } | ||
| fieldValueEncoded = fieldValueEncoded[1 : len(fieldValueEncoded)-1] | ||
| fieldValueEncodedTrimmed := trimStringByBytes(fieldValueEncoded, size) | ||
| fieldValueEncodedTrimmed = "\"" + removeHalfCutEscapeChar(fieldValueEncodedTrimmed) + "\"" |
Check failure
Code scanning / CodeQL
Potentially unsafe quoting Critical
JSON value
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 seems relevant. It seems very likely for the field value to have double quotes?
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.
The json encode puts double quotes which I remove on 107 and add back on 109 after trimming the string to the correct size. Let me know if theres a cleaner way to trim the string.
Originally, I was not encoding the string before trimming but this caused issues where escaping characters when encoding json makes the string larger than desired.
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'll take another look at it tmrw to see if theres a cleaner way and make sure its working well as intended
Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
yeya24
left a comment
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.
lint failure is also relevant
| Extract(r *http.Request) []byte | ||
| } | ||
|
|
||
| type DefaultExtractor struct{} |
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.
Let's remove DefaultExtractor as it is not used anywhere.
| } | ||
| fieldValueEncoded = fieldValueEncoded[1 : len(fieldValueEncoded)-1] | ||
| fieldValueEncodedTrimmed := trimStringByBytes(fieldValueEncoded, size) | ||
| fieldValueEncodedTrimmed = "\"" + removeHalfCutEscapeChar(fieldValueEncodedTrimmed) + "\"" |
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 seems relevant. It seems very likely for the field value to have double quotes?
Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
What this PR does:
Add an active api tracker to print api requests in a querier on OOMKill / crash
Example log:
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]