-
Notifications
You must be signed in to change notification settings - Fork 28
✨ リクエストレート調査用のミドルウェア #2643
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?
✨ リクエストレート調査用のミドルウェア #2643
Conversation
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.
Pull Request Overview
This pull request introduces a new middleware for logging request rates without enforcing rate limiting, and it leverages a custom in-memory queue to calculate the request rate across the application.
- Added RateLimiterWithLogging middleware to log high request rates.
- Updated router/v3/router.go to integrate the new middleware on the API group.
- Implemented an in-memory access log for rate tracking in router/middlewares/rate_limit.go.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| router/v3/router.go | Integrated new RateLimiterWithLogging middleware into API routes. |
| router/middlewares/rate_limit.go | Added middleware implementation for logging request rates. |
| } | ||
|
|
||
| // RateLimiterWithLogging リクエストレートを記録するミドルウェア (レートが閾値を上回った場合にログを残す) | ||
| func RateLimiterWithLogging(rate rate.Limit, burst int, logger *zap.Logger) echo.MiddlewareFunc { |
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.
これ、レートリミットをしてそうに見えちゃうので(実際はしてないので混乱の元になる)命名をちょっと練ってほしいです!
|
| mutex.Lock() | ||
| l := accessLogs.Get(ip) | ||
| l.Add(ok) | ||
| if !ok { |
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.
逐一ログ出力するとうるさそうなので、ログ出したという事実も手元に持っておいてアクセスログがクリアされるまでは再度ログを出さない、みたいなことをするのもアリかも?(必須ではない)
|
レートはアクセスログから統計取ってくるのが良い気がするので一旦draftにします 🙇 |
ユーザー数 * 12 * sizeof(int)バイトの領域を確保するようになっています. (24KiBくらい?)