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

serverapi:add rate limit for api #4235

Closed
wants to merge 1 commit into from

Conversation

qidi1
Copy link
Contributor

@qidi1 qidi1 commented Oct 24, 2021

Signed-off-by: qidi1 1083369179@qq.com

What problem does this PR solve?

Associated Issue:

What is changed and how it works?

add a middleware which used for rate limit for http request

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • No code
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Code changes

  • Has configuration change
  • Has HTTP API interfaces change (Don't forget to add the declarative for API)
  • Has persistent data change

Side effects

  • Possible performance regression
  • Increased code complexity
  • Breaking backward compatibility

Related changes

Release note

 None.

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has not been approved.

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 release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/invalid-commit-message labels Oct 24, 2021
@ti-chi-bot ti-chi-bot requested review from nolouch and rleungx October 24, 2021 03:20
@qidi1 qidi1 mentioned this pull request Oct 24, 2021
14 tasks
@qidi1 qidi1 force-pushed the rate-limit-serverapi branch from cb2c669 to f755785 Compare October 24, 2021 04:45
@@ -123,6 +130,36 @@ func (h *redirector) ServeHTTP(w http.ResponseWriter, r *http.Request, next http
NewCustomReverseProxies(client, urls).ServeHTTP(w, r)
}

type apiLimit struct {
bucket *ratelimit.Bucket
capacity int64
Copy link
Contributor

Choose a reason for hiding this comment

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

why needs to save capacity and rate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

already delete these

Signed-off-by: qidi1 <1083369179@qq.com>
@@ -36,6 +36,8 @@ func NewHandler(ctx context.Context, svr *server.Server) (http.Handler, server.S
router.PathPrefix(apiPrefix).Handler(negroni.New(
serverapi.NewRuntimeServiceValidator(svr, group),
serverapi.NewRedirector(svr),
serverapi.NewAPILimit(svr.GetConfig().PDServerCfg.APIBucketCapacity,
Copy link
Member

Choose a reason for hiding this comment

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

APIBucketCapacity and APIBucketRate need to be defined.

Copy link
Member

Choose a reason for hiding this comment

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

These have been defined in PR #4234

Copy link
Member

Choose a reason for hiding this comment

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

got

disksing added a commit to oh-my-tidb/pd that referenced this pull request Nov 18, 2021
close tikv#4235

Signed-off-by: disksing <i@disksing.com>
@qidi1 qidi1 closed this Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants