-
Notifications
You must be signed in to change notification settings - Fork 720
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
server: add limiter config and reload mechanism #4842
Conversation
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Codecov Report
@@ Coverage Diff @@
## master #4842 +/- ##
==========================================
+ Coverage 75.43% 75.56% +0.13%
==========================================
Files 309 309
Lines 30507 30552 +45
==========================================
+ Hits 23012 23086 +74
+ Misses 5475 5459 -16
+ Partials 2020 2007 -13
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@@ -1475,6 +1506,14 @@ func (s *Server) reloadConfigFromKV() error { | |||
return nil | |||
} | |||
|
|||
func (s *Server) loadRateLimitConfig() { |
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 it?
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 configuration of the Limiter differs from that of EnableRateLimit. The value of EnableRateLimit is fetched from PersistOption on every request, but Limiter does not. So after resigning leader, we should reload the associated configuration.
} | ||
|
||
// NewServiceMiddlewareConfig returns a new service middleware config | ||
func NewServiceMiddlewareConfig() *ServiceMiddlewareConfig { | ||
audit := AuditConfig{ | ||
EnableAudit: defaultEnableAuditMiddleware, | ||
} | ||
ratelimit := RateLimitConfig{ | ||
EnableRateLimit: defaultEnableRateLimitMiddleware, |
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.
need make?
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.
update
} | ||
postData, err = json.Marshal(ms) | ||
c.Assert(err, IsNil) | ||
c.Assert(tu.CheckPostJSON(testDialClient, addr, postData, tu.StatusOK(c)), IsNil) | ||
sc = &config.ServiceMiddlewareConfig{} | ||
c.Assert(tu.ReadGetJSON(c, testDialClient, addr, sc), IsNil) | ||
c.Assert(sc.EnableAudit, Equals, false) | ||
c.Assert(sc.EnableRateLimit, Equals, false) |
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 you please separate the test for rate-limit from audit
?
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.
Meanwhile, could you please add some tests of updating the item of limiter-config
?
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.
Meanwhile, could you please add some tests of updating the item of
limiter-config
?
Some tests will be added in #4843 after providering update API
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.
Meanwhile, could you please add some tests of updating the item of
limiter-config
?
I add a simple test, more test will in #4843 by specific API
} | ||
postData, err = json.Marshal(ms) | ||
c.Assert(err, IsNil) | ||
c.Assert(tu.CheckPostJSON(testDialClient, addr, postData, tu.StatusOK(c)), IsNil) | ||
sc = &config.ServiceMiddlewareConfig{} | ||
c.Assert(tu.ReadGetJSON(c, testDialClient, addr, sc), IsNil) | ||
c.Assert(sc.EnableAudit, Equals, false) | ||
c.Assert(sc.EnableRateLimit, Equals, false) |
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.
Meanwhile, could you please add some tests of updating the item of limiter-config
?
func (s *Server) SetRateLimitConfig(cfg config.RateLimitConfig) error { | ||
old := s.serviceMiddlewarePersistOptions.GetRateLimitConfig() | ||
s.serviceMiddlewarePersistOptions.SetRateLimitConfig(&cfg) | ||
if err := s.serviceMiddlewarePersistOptions.Persist(s.storage); err != nil { |
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.
Oh, Should we make this function threadsafe? Was it possible that two goroutines run this function, for example, should we avoid the following case:
- go1 finished L1001 and update the cfg to false
- go2 finished 1001 and update the cfg to true in cache
- go2 persist the value with true (from cache) and return success
- go1 persist the value with true(from cache) while it expect the value is false.
and more different cases may meet in thePersist
with it not protect while read and write..
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 happens to all config that needs to Persist
, and if optimization is needed, I think we can fix it together in another PR
tests/server/config/config_test.go
Outdated
|
||
func (s *testConfigPresistSuite) SetUpSuite(c *C) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
server.EnableZap = 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.
This config is no longer used.
s.cleanup() | ||
} | ||
|
||
func (s *testServiceMiddlewareSuite) TestConfigAudit(c *C) { | ||
func (s *testAuditMiddlewareSuite) TestConfigAuditSwitch(c *C) { |
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.
Please add a test for the default 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.
update
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
/merge |
@nolouch: It seems you want to merge this PR, I will help you trigger all the tests: /run-all-tests Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
This pull request has been accepted and is ready to merge. Commit hash: ed0bbf4
|
@CabinfeverB: Your PR was out of date, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository. |
Signed-off-by: Cabinfever_B cabinfeveroier@gmail.com
What problem does this PR solve?
Issue Number: Ref #4666
This PR should be merged after #4839
**This PR should be merged after #4869 **
This PR is used to reload the limit config for limiter after leader resign or restart and do some integration tests
What is changed and how it works?
update limiter config when reload presist config
Check List
Tests
Release note