Skip to content
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

Merged
merged 85 commits into from Jun 15, 2022

Conversation

CabinfeverB
Copy link
Member

@CabinfeverB CabinfeverB commented Apr 25, 2022

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

add Rate-limit config update API

Check List

Tests

  • Unit test

Code changes

Release note

None.

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>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Apr 25, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • AndreMouche
  • rleungx

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note The PR should write the release note. labels Apr 25, 2022
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@codecov
Copy link

codecov bot commented Apr 25, 2022

Codecov Report

Merging #4843 (3774d3b) into master (c628ff9) will increase coverage by 0.14%.
The diff coverage is 89.62%.

@@            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     
Flag Coverage Δ
unittests 75.78% <89.62%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/jsonutil/jsonutil.go 73.33% <73.33%> (ø)
server/server.go 73.60% <87.50%> (-0.38%) ⬇️
server/api/service_middleware.go 84.82% <92.85%> (+15.85%) ⬆️
server/api/config.go 61.50% <100.00%> (+0.13%) ⬆️
server/api/router.go 97.83% <100.00%> (+<0.01%) ⬆️
server/tso/tso.go 67.79% <0.00%> (-6.78%) ⬇️
pkg/dashboard/adapter/manager.go 75.86% <0.00%> (-5.75%) ⬇️
server/schedule/labeler/rules.go 87.50% <0.00%> (-2.28%) ⬇️
pkg/etcdutil/etcdutil.go 84.88% <0.00%> (-1.17%) ⬇️
server/config/persist_options.go 93.37% <0.00%> (-0.70%) ⬇️
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c628ff9...3774d3b. Read the comment docs.

@CabinfeverB CabinfeverB changed the title Rata limit config api api: add Rate-limit config update API Apr 25, 2022
@CabinfeverB CabinfeverB marked this pull request as ready for review April 25, 2022 08:28
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 25, 2022
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Copy link
Member

@AndreMouche AndreMouche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

if err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
} else {
h.rd.JSON(w, http.StatusOK, fmt.Sprintf("%s %s", concurrencyUpdatedFlag, qpsRateUpdatedFlag))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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))

Copy link
Member

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?

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Copy link
Member

@AndreMouche AndreMouche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 14, 2022
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@@ -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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need it?

Copy link
Member Author

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)
Copy link
Member

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?

Copy link
Member Author

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 Show resolved Hide resolved
}

type rateLimitResult struct {
ConcurrencyUpdatedFlag string `json:"Concurrency"`
Copy link
Member

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>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
ConcurrencyUpdatedFlag string `json:"Concurrency"`
QPSRateUpdatedFlag string `json:"QPS"`
ConcurrencyUpdatedFlag string `json:"concurrency"`
QPSRateUpdatedFlag string `json:"qps"`
LimiterConfig map[string]ratelimit.DimensionConfig `json:"new-config"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LimiterConfig map[string]ratelimit.DimensionConfig `json:"new-config"`
LimiterConfig map[string]ratelimit.DimensionConfig `json:"limiter-config"`

// @Param body body object string "json params"
// @Produce json
// @Success 200 {string} string ""
// @Failure 400 {string} string ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// @Failure 400 {string} string ""
// @Failure 400 {string} string "The input is invalid."

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Comment on lines 189 to 191
concurrency := uint64(concurrencyFloat)
cfg.ConcurrencyLimit = concurrency
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
concurrency := uint64(concurrencyFloat)
cfg.ConcurrencyLimit = concurrency
}
cfg.ConcurrencyLimit = uint64(concurrencyFloat)
}

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jun 15, 2022
@rleungx
Copy link
Member

rleungx commented Jun 15, 2022

/merge

@ti-chi-bot
Copy link
Member

@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.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: d558575

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jun 15, 2022
@ti-chi-bot
Copy link
Member

@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.

@ti-chi-bot ti-chi-bot merged commit 0da658c into tikv:master Jun 15, 2022
ti-chi-bot added a commit that referenced this pull request Jul 5, 2022
close #4666, ref #4839, ref #4840, ref #4842, ref #4843

Add rate limit middleware for HTTP API.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

Co-authored-by: Ryan Leung <rleungx@gmail.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
CabinfeverB added a commit to CabinfeverB/pd that referenced this pull request Jul 14, 2022
ref tikv#4666, ref tikv#4839

add Rate-limit config update API

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

Co-authored-by: Ryan Leung <rleungx@gmail.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
CabinfeverB added a commit to CabinfeverB/pd that referenced this pull request Jul 14, 2022
close tikv#4666, ref tikv#4839, ref tikv#4840, ref tikv#4842, ref tikv#4843

Add rate limit middleware for HTTP API.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

Co-authored-by: Ryan Leung <rleungx@gmail.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

--wip-- [skip ci]
CabinfeverB added a commit to CabinfeverB/pd that referenced this pull request Jul 14, 2022
close tikv#4666, ref tikv#4839, ref tikv#4840, ref tikv#4842, ref tikv#4843

Add rate limit middleware for HTTP API.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

Co-authored-by: Ryan Leung <rleungx@gmail.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>

--wip-- [skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants