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

Make int64 based atomic ratelimiter default #101

Merged
merged 2 commits into from
Oct 31, 2022

Conversation

storozhukBM
Copy link
Contributor

No description provided.

@storozhukBM storozhukBM changed the title Fix return timestamp discrepancy between regular atomic limiter and int64 based one Make int64 based atomic ratelimiter default Oct 31, 2022
@codecov
Copy link

codecov bot commented Oct 31, 2022

Codecov Report

Merging #101 (980cfa4) into main (b62b799) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #101   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines           95        98    +3     
=========================================
+ Hits            95        98    +3     
Impacted Files Coverage Δ
limiter_atomic_int64.go 100.00% <100.00%> (ø)
ratelimit.go 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines +86 to +90
sleepDuration := time.Duration(newTimeOfNextPermissionIssue - now)
if sleepDuration > 0 {
t.clock.Sleep(sleepDuration)
return time.Unix(0, newTimeOfNextPermissionIssue)
}
Copy link
Contributor

@rabbbit rabbbit Oct 31, 2022

Choose a reason for hiding this comment

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

Okay, now I'm confused again :)

Why re-introduce this now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

4 month ago, you added a new test Example_default that checks the slack behaviour of the default ratelimiter.
It turns out, atomicLimiter returns now if it doesn't sleep, so I decided to sync this behaviour in atomicInt64Limiter.

you removed very similar lines in #95

Yes, these lines are similar, but slightly different in the current PR we return now if we don't sleep, and this is the only behaviour change, everything else works as it worked before.

#93 which "fixes the time" - which I assumed is the goal-state - doesn't have this change.

In #93 atomicLimiter is still a default implementation, so I didn't know about the difference between behaviours so far.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rabbbit rabbbit merged commit a12885f into uber-go:main Oct 31, 2022
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.

None yet

2 participants