-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
✨ v3 (feature): add retry mechanism #1972
Conversation
* General logic is implemented. * Unit tests are added. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
* Replaced testify/assert with fiber's assert. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
* currentInterval bug is fixed in Retry. * If condition is fixed in next. * struct definition refactored and if condtion is removed in TestExponentialBackoff_Retry. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
I am ready for code review, comments, feedback, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think we should be able to change defaults by a config.
- Jitter backoff would be great.
- Hooks would be also great.
- A simple README for the middleware.
- Should we integrate this into the client directly?
* Constant variables are removed. * Helper function is added for default. * Helper function is used in New function. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
* Random number generation package has been replaced with more secure one, crypto/rand. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
* Explanation and examples are added. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
Hi @efectn. I have two questions. What do you mean by Should we integrate this into the client directly? Can you explain it? Also, what should I do for hooks? As a note, jitter is already provided with adding randomness. |
Perhaps we would integrate this into the client like https://github.com/go-resty/resty#retries to use with client easier.
|
* Comment lines are added for ExponentialBackoff variables. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
* Unused package(s) removed. Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
So, do you mean that we should use it as follow? app := fiber.New()
retry := app.NewExponentialBackoff())
err := retry.Retry(func() error)
// handle error (Naming can be changed like
As I understood that I should remove it from |
We may locate it in '/utils' as a directory. however i'm not sure.
i wasn't talking about it. i was talking about adding some built-in retry methods for client that use this retry function. ref: https://github.com/go-resty/resty/blob/master/request.go#L763 |
middleware/retry/config.go
Outdated
if len(config) == 0 { | ||
return DefaultConfig | ||
} | ||
cfg := config[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to get the config slice if we have set element 0 of the config slice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked configs in other parts and I saw it as a general convention or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because of the make config parameter optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because of the make config parameter optional.
Usually get a slice of the configuration with a type options pattern.
For normal configuration, getting slice is not necessary.
I think,
I think I understood what you meant. Maybe, I can create a new directory called
Also, what can I do with hooks? I don't have any idea what should I do. |
For example, we can execute hooks in each retry if user defined them. @ReneWerner87 what do you think about the location? |
Yeah its a good idea. I like hooks, its a good solution for customization and give the possibility to extend our functionality. |
Btw we're not sure about |
Usually retry is a core option for framework, i think we can set retry as option for framework. |
Can you provide an example of what should I do with hooks? It can be a code snippet, example code, or something like that. It can make more clear to understand your point. |
We may add it when to refactor client. Looks like we dont need at the moment. |
Hi @ReneWerner87. This is a polite ping. Can you review the PR? |
Oh sorry, sure will have a look this week(currently much todo) |
Now I need to use retry in client refactoring. I also think |
talked to efectn about it and we want to introduce a new folder this should be called "plugin", "addon" or "extension" in utils and helper should be only simple functionalities please create an order "addon" and under it the order "retry" -> there you place your new functionality please revise your readme -> the example confused me at first |
Hi @gozeloglu. Can you take a look when you're free? We'll merge this after these changes. |
Hi @efectn. Thanks for informing me. I'll take a look and make changes as soon as possible. |
Hi again, Thanks for renaming @efectn. It seems the PR is ready to merge. I have a question to @ReneWerner87 about the latest comment.
Which part confused you? What is the exact problem? Other than this part, rest of the code seems fine to merge. |
At the time when I wrote this, there was still a completely wrong example stored there |
It was related |
Thanks, @efectn. Looking forward to seeing the merge of the PR. 🚀 |
Congrats on merging your first pull request! 🎉 We here at Fiber are proud of you! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
Signed-off-by: Gökhan Özeloğlu gokhan.ozeloglu@deliveryhero.com
Please provide enough information so that others can review your pull request:
It is related to #1840.
Explain the details for making this change. What existing problem does the pull request solve?
I added a new package called
retry
. Exponential backoff algorithm is used. I can refactor the code like constant/default values, tests, etc. I am going to add more tests and maybe I'll do some small changes to the code.