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

✨ v3 (feature): add retry mechanism #1972

Merged
merged 9 commits into from
Aug 19, 2022

Conversation

gozeloglu
Copy link
Contributor

@gozeloglu gozeloglu commented Jul 9, 2022

  • General logic is implemented.
  • Unit tests are added.

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.

* General logic is implemented.

* Unit tests are added.

Signed-off-by: Gökhan Özeloğlu <gokhan.ozeloglu@deliveryhero.com>
@welcome
Copy link

welcome bot commented Jul 9, 2022

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

@efectn efectn changed the title ✨ v3 (feature):: Add retry mechanism ✨ v3 (feature): add retry mechanism Jul 10, 2022
@efectn efectn linked an issue Jul 10, 2022 that may be closed by this pull request
@efectn efectn added this to the v3 milestone Jul 10, 2022
Gökhan Özeloğlu added 2 commits July 10, 2022 15:34
* 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>
@gozeloglu gozeloglu marked this pull request as ready for review July 11, 2022 20:20
@gozeloglu
Copy link
Contributor Author

I am ready for code review, comments, feedback, etc.

@gozeloglu gozeloglu requested a review from efectn July 11, 2022 20:21
Copy link
Member

@efectn efectn left a 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?

Gökhan Özeloğlu added 3 commits July 12, 2022 19:51
* 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>
@gozeloglu
Copy link
Contributor Author

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.

@efectn
Copy link
Member

efectn commented Jul 13, 2022

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.

  • Btw don't forget running go mod tidy to remove testify from go.mod and go.sum
  • Also you can remove app.Use lines from README due to this is not handler middleware.
  • Jitter seems ok to me

Gökhan Özeloğlu added 2 commits July 13, 2022 14:44
* 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>
@gozeloglu
Copy link
Contributor Author

Perhaps we would integrate this into the client like https://github.com/go-resty/resty#retries to use with client easier.

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 retry.Retry might not be good.)
So, also you mentioned that

Also you can remove app.Use lines from README due to this is not handler middleware.

As I understood that I should remove it from /middleware directory and carry it to the root directory. If yes, it might be a problem for the config part. If I am wrong, please correct me.

@efectn
Copy link
Member

efectn commented Jul 13, 2022

As I understood that I should remove it from /middleware directory and carry it to the root directory. If yes, it might be a problem for the config part. If I am wrong, please correct me.

We may locate it in '/utils' as a directory. however i'm not sure.

(Naming can be changed like retry.Retry might not be good.)

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

if len(config) == 0 {
return DefaultConfig
}
cfg := config[0]
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

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.

@gozeloglu
Copy link
Contributor Author

We may locate it in '/utils' as a directory. however i'm not sure.

I think, utils is not a good place to locate them. Because, in general, utils is a place for utility functions used across the codebase. Also, it has a flat structure. I am not going to change it until you give another suggestion.

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

I think I understood what you meant. Maybe, I can create a new directory called retry in the root directory. But, it might not good for the framework.

Hooks would be also great.

Also, what can I do with hooks? I don't have any idea what should I do.

@efectn
Copy link
Member

efectn commented Jul 16, 2022

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?

@ReneWerner87
Copy link
Member

Yeah its a good idea. I like hooks, its a good solution for customization and give the possibility to extend our functionality.

@efectn
Copy link
Member

efectn commented Jul 16, 2022

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 middleware/ is true location for retry. What do you think?

@Ja7ad
Copy link
Contributor

Ja7ad commented Jul 17, 2022

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 middleware/ is true location for retry. What do you think?

Usually retry is a core option for framework, i think we can set retry as option for framework.

@gozeloglu
Copy link
Contributor Author

Yeah its a good idea. I like hooks, its a good solution for customization and give the possibility to extend our functionality.

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.

@efectn
Copy link
Member

efectn commented Jul 30, 2022

Yeah its a good idea. I like hooks, its a good solution for customization and give the possibility to extend our functionality.

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.

@efectn efectn requested a review from ReneWerner87 July 30, 2022 08:44
@gozeloglu
Copy link
Contributor Author

Hi @ReneWerner87. This is a polite ping. Can you review the PR?

@ReneWerner87
Copy link
Member

Oh sorry, sure will have a look this week(currently much todo)

@efectn efectn mentioned this pull request Aug 4, 2022
27 tasks
@wangjq4214
Copy link
Member

Now I need to use retry in client refactoring. I also think middleware/ is not a good location, it might be a good idea to put it in utils/ or client/retry.go?

@ReneWerner87
Copy link
Member

Now I need to use retry in client refactoring. I also think middleware/ is not a good location, it might be a good idea to put it in utils/ or client/retry.go?

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
also helps go modules, so that only what is needed is checked out

please revise your readme -> the example confused me at first

@efectn
Copy link
Member

efectn commented Aug 16, 2022

Now I need to use retry in client refactoring. I also think middleware/ is not a good location, it might be a good idea to put it in utils/ or client/retry.go?

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 also helps go modules, so that only what is needed is checked out

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.

@gozeloglu
Copy link
Contributor Author

Hi @efectn. Thanks for informing me. I'll take a look and make changes as soon as possible.

@gozeloglu
Copy link
Contributor Author

Hi again,

Thanks for renaming @efectn. It seems the PR is ready to merge. I have a question to @ReneWerner87 about the latest comment.

please revise your readme -> the example confused me at first

Which part confused you? What is the exact problem? Other than this part, rest of the code seems fine to merge.

@ReneWerner87
Copy link
Member

At the time when I wrote this, there was still a completely wrong example stored there
Look at it tomorrow and then I merge

@efectn
Copy link
Member

efectn commented Aug 18, 2022

Hi again,

Thanks for renaming @efectn. It seems the PR is ready to merge. I have a question to @ReneWerner87 about the latest comment.

please revise your readme -> the example confused me at first

Which part confused you? What is the exact problem? Other than this part, rest of the code seems fine to merge.

It was related app.Use part but i fixed that.

@gozeloglu
Copy link
Contributor Author

It was related app.Use part but i fixed that

Thanks, @efectn. Looking forward to seeing the merge of the PR. 🚀
Thanks, @ReneWerner87 as well.

@ReneWerner87 ReneWerner87 merged commit 4adda50 into gofiber:v3-beta Aug 19, 2022
@welcome
Copy link

welcome bot commented Aug 19, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

🚀 v3 Request: Retry Mechanism
5 participants