Skip to content

Commit

Permalink
Add way to use sentinel rate limiter during Redis fallback with DRL (T…
Browse files Browse the repository at this point in the history
…ykTechnologies#3298)

Added new `drl_enable_sentinel_rate_limiter` config param

WIP

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality)

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes that apply -->
<!-- If you're unsure about any of these, don't hesitate to ask; we're here to help! -->
- [ ] Make sure you are requesting to **pull a topic/feature/bugfix branch** (right side). If pulling from your own
      fork, don't request your `master`!
- [ ] Make sure you are making a pull request against the **`master` branch** (left side). Also, you should start
      *your branch* off *our latest `master`*.
- [ ] My change requires a change to the documentation.
  - [ ] If you've changed APIs, describe what needs to be updated in the documentation.
  - [ ] If new config option added, ensure that it can be set via ENV variable
- [ ] I have updated the documentation accordingly.
- [ ] Modules and vendor dependencies have been updated; run `go mod tidy && go mod vendor`
- [ ] When updating library version must provide reason/explanation for this update.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
- [ ] Check your code additions will not fail linting checks:
  - [ ] `go fmt -s`
  - [ ] `go vet`
  • Loading branch information
buger authored Sep 3, 2020
1 parent 52b5ce9 commit 605b593
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ type Config struct {
EnableSentinelRateLimiter bool `json:"enable_sentinel_rate_limiter"`
EnableRedisRollingLimiter bool `json:"enable_redis_rolling_limiter"`
DRLNotificationFrequency int `json:"drl_notification_frequency"`
DRLEnableSentinelRateLimiter bool `json:"drl_enable_sentinel_rate_limiter"`
DRLThreshold float64 `json:"drl_threshold"`

// Organization configurations
Expand Down
4 changes: 2 additions & 2 deletions gateway/session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (l *SessionLimiter) doRollingWindowWrite(key, rateLimiterKey, rateLimiterSe

// Subtract by 1 because of the delayed add in the window
subtractor := 1
if globalConf.EnableSentinelRateLimiter {
if globalConf.EnableSentinelRateLimiter || globalConf.DRLEnableSentinelRateLimiter {
// and another subtraction because of the preemptive limit
subtractor = 2
}
Expand All @@ -77,7 +77,7 @@ func (l *SessionLimiter) doRollingWindowWrite(key, rateLimiterKey, rateLimiterSe
//log.Info("break: ", (int(currentSession.Rate) - subtractor))
if ratePerPeriodNow > int(rate)-subtractor {
// Set a sentinel value with expire
if globalConf.EnableSentinelRateLimiter {
if globalConf.EnableSentinelRateLimiter || globalConf.DRLEnableSentinelRateLimiter {
if !dryRun {
store.SetRawKey(rateLimiterSentinelKey, "1", int64(per))
}
Expand Down

0 comments on commit 605b593

Please sign in to comment.