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
api: add Rate-limit config update API #4843
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>
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. |
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Codecov Report
@@ Coverage Diff @@
## master #4843 +/- ##
==========================================
+ Coverage 75.64% 75.78% +0.14%
==========================================
Files 309 310 +1
Lines 30598 30664 +66
==========================================
+ Hits 23145 23238 +93
+ Misses 5453 5428 -25
+ Partials 2000 1998 -2
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>
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.
Rest LGTM
server/api/service_middleware.go
Outdated
if err != nil { | ||
h.rd.JSON(w, http.StatusInternalServerError, err.Error()) | ||
} else { | ||
h.rd.JSON(w, http.StatusOK, fmt.Sprintf("%s %s", concurrencyUpdatedFlag, qpsRateUpdatedFlag)) |
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.
h.rd.JSON(w, http.StatusOK, fmt.Sprintf("%s %s", concurrencyUpdatedFlag, qpsRateUpdatedFlag)) | |
h.rd.JSON(w, http.StatusOK, fmt.Sprintf("%s\n%s", concurrencyUpdatedFlag, qpsRateUpdatedFlag)) |
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.
How about returns the new ratelimit config once set success?
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
server/api/router.go
Outdated
@@ -285,6 +285,7 @@ func createRouter(prefix string, svr *server.Server) *mux.Router { | |||
serviceMiddlewareHandler := newServiceMiddlewareHandler(svr, rd) | |||
registerFunc(apiRouter, "/service-middleware/config", serviceMiddlewareHandler.GetServiceMiddlewareConfig, setMethods("GET")) | |||
registerFunc(apiRouter, "/service-middleware/config", serviceMiddlewareHandler.SetServiceMiddlewareConfig, setMethods("POST"), setAuditBackend(localLog)) | |||
registerFunc(apiRouter, "/service-middleware/rate-limit/config", serviceMiddlewareHandler.SetRatelimitConfig, setMethods("POST"), setAuditBackend(localLog)) |
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.
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.
/service-middleware/rate-limit/config
is used to update Incrementally. If users want to overwrite config, we can use /service-middleware/config
} | ||
// update qps rate limiter | ||
qpsRateUpdatedFlag := "QPS rate limiter is not changed." | ||
qps, okq := input["qps"].(float64) |
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.
if QPS is less than 0, does it belong to an error?
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.
It means delete QPS limit
server/api/service_middleware.go
Outdated
} | ||
|
||
type rateLimitResult struct { | ||
ConcurrencyUpdatedFlag string `json:"Concurrency"` |
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.
use small letter?
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
server/api/service_middleware.go
Outdated
ConcurrencyUpdatedFlag string `json:"Concurrency"` | ||
QPSRateUpdatedFlag string `json:"QPS"` | ||
ConcurrencyUpdatedFlag string `json:"concurrency"` | ||
QPSRateUpdatedFlag string `json:"qps"` | ||
LimiterConfig map[string]ratelimit.DimensionConfig `json:"new-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.
LimiterConfig map[string]ratelimit.DimensionConfig `json:"new-config"` | |
LimiterConfig map[string]ratelimit.DimensionConfig `json:"limiter-config"` |
server/api/service_middleware.go
Outdated
// @Param body body object string "json params" | ||
// @Produce json | ||
// @Success 200 {string} string "" | ||
// @Failure 400 {string} string "" |
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.
// @Failure 400 {string} string "" | |
// @Failure 400 {string} string "The input is invalid." |
server/api/service_middleware.go
Outdated
concurrency := uint64(concurrencyFloat) | ||
cfg.ConcurrencyLimit = concurrency | ||
} |
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.
concurrency := uint64(concurrencyFloat) | |
cfg.ConcurrencyLimit = concurrency | |
} | |
cfg.ConcurrencyLimit = uint64(concurrencyFloat) | |
} |
/merge |
@rleungx: 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: d558575
|
@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
What is changed and how it works?
add Rate-limit config update API
Check List
Tests
Code changes
Release note