-
Notifications
You must be signed in to change notification settings - Fork 10
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
Change rate limit logs level #298
Conversation
WalkthroughThe recent changes focus on refining logging behavior in the rate limiting and response writing functionalities. Specifically, the logging level for rate limit messages was adjusted from Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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!
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.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- api/ratelimiter.go (1 hunks)
- api/server.go (2 hunks)
Additional comments not posted (2)
api/ratelimiter.go (1)
29-29
: Change of log level fromWarn
toDebug
aligns with the PR objective to reduce log verbosity.Verification successful
The change in log level from
Warn
toDebug
inapi/ratelimiter.go
is isolated and does not affect other functionalities.
services/ingestion/subscriber.go
services/requester/requester.go
models/engine.go
api/server.go
bootstrap/bootstrap.go
api/api.go
These instances of
logger.Warn()
are in different contexts and files.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the change in log level does not affect other functionalities. # Test: Search for any other usages of the `logger.Warn()` in the context of rate limiting. rg --type go $'logger.Warn()'Length of output: 616
api/server.go (1)
26-26
: The import oferrs
is necessary for the updated error handling in theWrite
method.
body := make(map[string]string) | ||
_ = json.Unmarshal(data, &body) | ||
delete(body, "jsonrpc") | ||
|
||
if body["error"] != nil { | ||
w.logger. | ||
Error(). | ||
Fields(body). | ||
Msg("API response") | ||
} else { | ||
w.logger. | ||
Debug(). | ||
Fields(body). | ||
Msg("API response") | ||
l := w.logger.Debug() | ||
|
||
// only set error level if error is present in response | ||
if body["error"] != "" { | ||
// and it's not rate limit error, we want to downgrade them since they are common | ||
if !strings.Contains(body["error"], errs.ErrRateLimit.Error()) { | ||
l = w.logger.Error() | ||
} | ||
} | ||
|
||
l.Fields(body).Msg("API response") | ||
|
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.
Refinement in logging logic to adjust log levels based on error content is a good approach. Consider refactoring to improve readability.
- if body["error"] != "" {
- if !strings.Contains(body["error"], errs.ErrRateLimit.Error()) {
- l = w.logger.Error()
- }
- }
+ if errContent := body["error"]; errContent != "" && !strings.Contains(errContent, errs.ErrRateLimit.Error()) {
+ l = w.logger.Error()
+ }
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
body := make(map[string]string) | |
_ = json.Unmarshal(data, &body) | |
delete(body, "jsonrpc") | |
if body["error"] != nil { | |
w.logger. | |
Error(). | |
Fields(body). | |
Msg("API response") | |
} else { | |
w.logger. | |
Debug(). | |
Fields(body). | |
Msg("API response") | |
l := w.logger.Debug() | |
// only set error level if error is present in response | |
if body["error"] != "" { | |
// and it's not rate limit error, we want to downgrade them since they are common | |
if !strings.Contains(body["error"], errs.ErrRateLimit.Error()) { | |
l = w.logger.Error() | |
} | |
} | |
l.Fields(body).Msg("API response") | |
body := make(map[string]string) | |
_ = json.Unmarshal(data, &body) | |
delete(body, "jsonrpc") | |
l := w.logger.Debug() | |
// only set error level if error is present in response | |
if errContent := body["error"]; errContent != "" && !strings.Contains(errContent, errs.ErrRateLimit.Error()) { | |
l = w.logger.Error() | |
} | |
l.Fields(body).Msg("API response") |
Lower rate limit logs to debug level since they are pretty common.
Summary by CodeRabbit