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

Generate rate limit frontend api handler #5636

Merged
merged 1 commit into from
Feb 2, 2024
Merged

Conversation

Shaddoll
Copy link
Contributor

@Shaddoll Shaddoll commented Jan 29, 2024

What changed?
Generate rate limit frontend api handler code
Some fix:

  • Change rate limit type of the following APIs:
  • ScanWorkflowExecution
  • RefreshWorkflowTasks
  • GetClusterInfo

Why?
To reduce manual work

How did you test it?

Potential risks

Release notes

Documentation Changes

@coveralls
Copy link

coveralls commented Feb 1, 2024

Pull Request Test Coverage Report for Build 018d6b8b-50b8-4c5f-95e5-5177c23645c8

  • -2 of 40 (95.0%) changed or added relevant lines in 3 files are covered.
  • 114 unchanged lines in 15 files lost coverage.
  • Overall coverage decreased (-0.05%) to 62.631%

Changes Missing Coverage Covered Lines Changed/Added Lines %
service/frontend/wrappers/ratelimited/ratelimit.go 8 10 80.0%
Files with Coverage Reduction New Missed Lines %
common/task/weighted_round_robin_task_scheduler.go 1 89.05%
common/membership/hashring.go 2 84.05%
common/persistence/executionManager.go 2 78.94%
common/persistence/statsComputer.go 2 93.57%
common/util.go 2 91.69%
service/history/task/transfer_active_task_executor.go 2 72.22%
tools/cli/admin_db_decode_thrift.go 2 70.13%
common/task/fifo_task_scheduler.go 3 84.54%
service/history/queue/timer_gate.go 3 95.83%
service/worker/scanner/executor/runq.go 3 85.48%
Totals Coverage Status
Change from base Build 018d661a-a997-4c31-afe5-e98adb09026e: -0.05%
Covered Lines: 92035
Relevant Lines: 146949

💛 - Coveralls

@Shaddoll Shaddoll force-pushed the ratelimit branch 3 times, most recently from 28aa13e to 50d3d50 Compare February 1, 2024 20:39
@Shaddoll Shaddoll force-pushed the ratelimit branch 2 times, most recently from 37fa6eb to 091050e Compare February 2, 2024 01:19
Copy link
Contributor

@Groxx Groxx left a comment

Choose a reason for hiding this comment

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

gonna stick myself in here for "I think this needs a careful read before approval, but broadly I like it". I just don't have the brain energy to do that right now.

main concern is that this makes a significant change to when the call occurs, and that needs to be verified to be safe.

whether we return a 429 or "bad request" error on floods of bad requests: eh, I think both are defensible, changing it seems fine to me. it's just worth checking if there are any particularly valuable ones that will be lost (I sincerely doubt it).

Comment on lines +38 to +49
func (h *apiHandler) allowDomain(requestType ratelimitType, domain string) bool {
switch requestType {
case ratelimitTypeUser:
return h.userRateLimiter.Allow(quotas.Info{Domain: domain})
case ratelimitTypeWorker:
return h.workerRateLimiter.Allow(quotas.Info{Domain: domain})
case ratelimitTypeVisibility:
return h.visibilityRateLimiter.Allow(quotas.Info{Domain: domain})
default:
panic("coding error, unrecognized request ratelimit type value")
}
}
Copy link
Contributor

@Groxx Groxx Feb 2, 2024

Choose a reason for hiding this comment

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

this is a fairly minimal change and if you prefer that then 👍 but:
we could take this opportunity to remove this method and the iota and directly call the appropriate limiter.

I didn't do that initially when adding these, to keep things minimal, but it's definitely due for a cleanup at some point. Does not have to be now though.

Copy link
Contributor

@Groxx Groxx left a comment

Choose a reason for hiding this comment

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

All done with a round-1 careful read!

A couple smallish changes worth verifying, but other than those / check comments, this all looks good. should be pretty easy to re-review after those things are checked/changed.

@Shaddoll Shaddoll force-pushed the ratelimit branch 2 times, most recently from f95adb7 to 6662f3c Compare February 2, 2024 20:23
Comment on lines +410 to +417
if rp1 == nil {
err = validate.ErrRequestNotSet
return
}
if rp1.TaskToken == nil {
err = validate.ErrTaskTokenNotSet
return
}
Copy link
Contributor

@Groxx Groxx Feb 2, 2024

Choose a reason for hiding this comment

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

at some point we should probably make some validation-wrappers that occur early and get rid of this need at random levels...
but 👍 yep, same as existing behavior, LGTM. I've been trying to come up with a nice way to build that kind of validator, but everything feels like a huge pain / very disconnected from where the checks matter...

Copy link
Contributor

@Groxx Groxx left a comment

Choose a reason for hiding this comment

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

Yep, looks good! Thanks for the template-ization, the more we can standardize and pull out of the handlers the better 👍

@Shaddoll Shaddoll merged commit 4ace4f5 into uber:master Feb 2, 2024
16 checks passed
@Shaddoll Shaddoll deleted the ratelimit branch February 2, 2024 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants