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

Add Rate limiter #579

Merged
merged 2 commits into from
Oct 6, 2023
Merged

Add Rate limiter #579

merged 2 commits into from
Oct 6, 2023

Conversation

ribaraka
Copy link
Contributor

ref #559

Custom Rate Limiter (CRL) with several features:

  1. For every consecutive error encountered, the waiting time doubles.
  2. Configurable parameters for initial retry times and maximum wait times.
  3. Maximum number of retry attempts. When this limit is reached, it automatically triggers another re-request attempt in one hour.

CRL is built on the controller-runtime framework. For the CRL proper work, all controllers, in case of an error, should now return errors, instead of nil.
Refactored the Cassandra controller, for the CRL's capabilities and suits as an example for further refactoring and CRL integration. ReconcileReque60 now works only in case of possible Kubernetes error.

@ribaraka ribaraka added the enhancement New feature or request label Sep 27, 2023
@ribaraka ribaraka self-assigned this Sep 27, 2023
Comment on lines 5 to 13
type RateLimiter interface {
// When gets an item and gets to decide how long that item should wait
When(item interface{}) time.Duration
// Forget indicates that an item is finished being retried. Doesn't matter whether it's for failing
// or for success, we'll stop tracking it
Forget(item interface{})
// NumRequeues returns back how many failures the item has had
NumRequeues(item interface{}) int
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the point of duplicating the controller.RateLimiter interface? If you want to avoid using the controller package prefix, you can just create an alias for it type RateLimiter = controller.RateLimiter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, there is no use for duplicating it. I probably remove it.

Comment on lines 25 to 34
func NewItemExponentialFailureRateLimiterWithMaxTries(baseDelay time.Duration, maxDelay time.Duration) RateLimiter {
return &ItemExponentialFailureRateLimiterWithMaxTries{
failures: map[interface{}]int{},
baseDelay: baseDelay,
maxDelay: maxDelay,
maxTries: defaultMaxTries,
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be better if there was an opportunity to configure maxRetries myself. If it is not configured then set defaultMaxTries value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about the idea of configuring the maxTries. I think it's more of a generic thing. But let's get another opinion about this.

@ribaraka ribaraka force-pushed the rate_limiter branch 5 times, most recently from 065d65d to 25fad97 Compare September 29, 2023 11:58
@taaraora taaraora merged commit 71e1255 into main Oct 6, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants