-
Notifications
You must be signed in to change notification settings - Fork 30
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: default value of rate-limit and unnecessary content of access logs. #70
Fix: default value of rate-limit and unnecessary content of access logs. #70
Conversation
…dit logs - set default max to 60 in rate-limit middleware. - change audit-log middleware message format. - update test cases.
- rename "AuditLoggingMiddleware" to "AccessLogMiddleware". - rename option name from "audit-log" to "access-log". - rename "AUDIT" to "ACCESS_LOG" in "getLogger" function.
Codecov ReportBase: 92.08% // Head: 91.94% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## develop #70 +/- ##
===========================================
- Coverage 92.08% 91.94% -0.14%
===========================================
Files 215 215
Lines 2980 2991 +11
Branches 346 354 +8
===========================================
+ Hits 2744 2750 +6
- Misses 172 175 +3
- Partials 64 66 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
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.
Other part LGTM.
const reqSize = req.length ? bytes(req.length).toLowerCase() : 'none'; | ||
const respSize = resp.length ? bytes(resp.length).toLowerCase() : 'none'; |
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.
Nice to print request/response size, but I can't get both of them in lab env, how do we get them to work?
Should we calculate the response size after other middlewares (after next() function)? Response data might be set after them.
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.
Hi @oscar60310, thanks for reviewing and suggesting, I have checked the lab env both, and like you said the request/response size (Content-Length) shows an undefined
value ( Also includes integrating-testing
and my app.spec
test cases in serve
package.
So I searching for the reason, and I the request header only have Content-Length
when HTTP method is POST
or PUT
, because Content-Length
only calculates payload data size, please check the references below and my test by sample with typescript-koa-starter
to add test api:
- https://www.ibm.com/docs/en/ibm-mq/9.0?topic=headers-content-length-http-entity-header
- https://stackoverflow.com/questions/8540931/what-is-the-correct-content-length-to-set-for-a-get-request
- other repository issues also discussion the issue > RequestBodyBufferMiddleware: 411 No Content Length for GET requests? reactphp/http#232 (comment)
- https://stackoverflow.com/questions/3854842/content-length-header-with-head-requests
POST request and return JSON format
GET request and return JSON format
For the response header, as we know, because we use the stream and the header will shows Transfer-Encoding: chunck
, so Content-Length
won't work.
GET request and return Stream format
POST request and return Stream format
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.
Currently I still keep the request and response size, because maybe we will have POST / PUT API in the future.
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.
Thanks for the survey!
displayFilePath: 'hideNodeModulesOnly', | ||
displayFunctionName: true, |
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.
May I ask why we set different default config from Access log?
2022-09-14 08:21:41.405 DEBUG [SERVE packages/serve/src/lib/response-formatter/jsonFormatter.ts:71 JsonStringTransformer.<anonymous>] convert to json format stream > done.
The path can be so long that I think it should be displayed with --verbose
flag.
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.
Thanks for reviewing, discussing with me, and giving suggestions, I have made CORE
, BUILD
and , SERVE
both hide the file path and function name, and according to the discussion, we will make it show 'hideNodeModulesOnly'
and display the function name in the future by implementing the `--verbose flag.
I also refactor the getLogger
, so even non above the default logger scope also hides the file path and function name, it refactors by commit 9efb93e
/** | ||
* TODO: The response body of our API server might be huge. | ||
* We can let users to set what data they want to record in config in the future. | ||
*/ |
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.
Should we remove this note?
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.
Thanks for finding the non removed comment, it has been removed, please check it
…ing scope both hide the function name and file path
Hi @oscar60310, The PR has been fixed, please check it, thanks! |
Description
Fix the default value of sending 5 times requests in 1 minute to 60 times in 1 minute for the rate limit and refactor the access log message.
We rename the
AuditLoggingMiddleware
toAccessLogMiddleware
, and change the module name fromaudit-log
toaccess-log
.The access log message become to below format:
Commit Message
audit-log
toaccess-log
AuditLoggingMiddleware
toAccessLogMiddleware
.audit-log
toaccess-log
.AUDIT
toACCESS_LOG
ingetLogger
function.AccessLogMiddleware
log after other middleware rannext()