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

faucet: rate limit initial implementation #2603

Merged
merged 11 commits into from
Jul 29, 2024
Merged

faucet: rate limit initial implementation #2603

merged 11 commits into from
Jul 29, 2024

Conversation

emailtovamos
Copy link
Contributor

@emailtovamos emailtovamos commented Jul 22, 2024

Description

This PR introduces some rate limiting for faucet.
Also couple of concurrencies being introduced so that the main loop doesn't potentially get stuck in one single request.

Addressing issue: #2606

Rationale

tell us why we need these changes...

Example

add an example CLI or API response...

Changes

Notable changes:

  • add each change in a bullet point here
  • ...

cmd/faucet/faucet.go Outdated Show resolved Hide resolved
cmd/faucet/faucet.go Outdated Show resolved Hide resolved
cmd/faucet/faucet.go Outdated Show resolved Hide resolved
Comment on lines 294 to 295
limiter := f.limiter.GetLimiter(ip)
if !limiter.Allow() {
Copy link
Contributor

@MatusKysel MatusKysel Jul 25, 2024

Choose a reason for hiding this comment

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

as you are not using limiter maybe better approach will be to implement f.limiter.Allow(ip)

Copy link
Collaborator

Choose a reason for hiding this comment

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

agree

MatusKysel
MatusKysel previously approved these changes Jul 25, 2024
Copy link
Contributor

@MatusKysel MatusKysel left a comment

Choose a reason for hiding this comment

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

looks much better 👍

@emailtovamos emailtovamos marked this pull request as ready for review July 26, 2024 07:50
return i, nil
}

func (i *IPRateLimiter) AddIP(ip string) *rate.Limiter {
Copy link
Collaborator

Choose a reason for hiding this comment

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

if AddIP is only for internal usage, we can name it: addIP

type IPRateLimiter struct {
ips *lru.Cache
r rate.Limit
b int
Copy link
Collaborator

Choose a reason for hiding this comment

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

better to add some comments for b, it is the burst value within 5min?

@zzzckck zzzckck merged commit 00cac12 into develop Jul 29, 2024
6 of 7 checks passed
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