Skip to content

faucet: rate limit initial implementation#2603

Merged
zzzckck merged 11 commits intodevelopfrom
faucet-ratelimit1
Jul 29, 2024
Merged

faucet: rate limit initial implementation#2603
zzzckck merged 11 commits intodevelopfrom
faucet-ratelimit1

Conversation

@emailtovamos
Copy link
Copy Markdown
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
  • ...

@emailtovamos emailtovamos requested a review from MatusKysel July 24, 2024 10:20
Comment on lines +294 to +295
limiter := f.limiter.GetLimiter(ip)
if !limiter.Allow() {
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@zzzckck zzzckck deleted the faucet-ratelimit1 branch May 14, 2025 06:24
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