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

Fix/5163 retry download upgrade verifiers #6276

Merged

Conversation

kaanyalti
Copy link
Contributor

@kaanyalti kaanyalti commented Dec 11, 2024

  • Bug

What does this PR do?

Adds backoff retry for verifier artifact requests

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • [ ] I have added an integration test or an E2E test

How to test this PR locally

Related issues

@kaanyalti kaanyalti requested a review from a team as a code owner December 11, 2024 06:36
Copy link
Contributor

mergify bot commented Dec 11, 2024

This pull request does not have a backport label. Could you fix it @kaanyalti? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label to automatically backport to the 8./d branch. /d is the digit

Copy link
Contributor

mergify bot commented Dec 11, 2024

backport-v8.x has been added to help with the transition to the new branch 8.x.
If you don't need it please use backport-skip label and remove the backport-8.x label.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Dec 11, 2024
Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

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

This looks good overall, just look at the lint issue.

resp, err = btr.next.RoundTrip(req)
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This lint error should be fixed. Should probably call close no matter what.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looked into this with @belimawr . The linter is most probably complaining here because the response is used in a closure and not passed onto anything else. Closing the response body here causes an error when the caller tries to read from it. The response is closed after each unsuccessful attempt so that we don't leak resources. When an attempt is successful, the response is sent back up the call stack. This is similar to how it is implemented in FleetAuthRoundTripper. Another option was to read the whole response into a buffer, close the body, and then assign the bufffer back to the response body after wrapping it with io.NopCloser. This is how the DebugRoundTripper handles the request body. While it is a valid solution, it may cause issues in case there are other midleware in the rountripper chain where there may be a response body size limiter, and it also doesn't seem to be necessary here as the current implementation works as expected. To resolve the linting problem I added a nolint comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the detailed explanation. Glad to see it was also added to the code.

@kaanyalti kaanyalti force-pushed the fix/5163_retry_download_upgrade_verifiers branch from 7e387dc to 5ea64d3 Compare December 13, 2024 15:45
exp := backoff.NewExponentialBackOff()
boCtx := backoff.WithContext(exp, req.Context())

opNotify := func(err error, retryAfter time.Duration) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@kaanyalti kaanyalti force-pushed the fix/5163_retry_download_upgrade_verifiers branch from b503a10 to a391457 Compare December 16, 2024 17:57
@kaanyalti kaanyalti merged commit a5eb77b into elastic:main Dec 18, 2024
13 checks passed
mergify bot pushed a commit that referenced this pull request Dec 18, 2024
* fix(5163): added context to the verify interface, updated relevant calls, added backoff roundtripper

* fix(5163): added backoff roundtripper, added tests for asc file download

* fix(5163): remove log

* fix(5163): ran mage fmt

* fix(5163): removed unused roundtripper

* fix(5163): closing response body on unsuccesful responses

* fix(5163): added changelog

* fix(5163): added comment explaining the backoff function, added nolint comment

* fix(5163): added logic to handle resetting request body in the retry roundtripper, added unit tests, updated comments

* fix(5163): fixed linting errors

* fix(5164): ran mage check

(cherry picked from commit a5eb77b)
@kaanyalti kaanyalti deleted the fix/5163_retry_download_upgrade_verifiers branch December 18, 2024 05:14
jlind23 added a commit that referenced this pull request Dec 30, 2024
* fix(5163): added context to the verify interface, updated relevant calls, added backoff roundtripper

* fix(5163): added backoff roundtripper, added tests for asc file download

* fix(5163): remove log

* fix(5163): ran mage fmt

* fix(5163): removed unused roundtripper

* fix(5163): closing response body on unsuccesful responses

* fix(5163): added changelog

* fix(5163): added comment explaining the backoff function, added nolint comment

* fix(5163): added logic to handle resetting request body in the retry roundtripper, added unit tests, updated comments

* fix(5163): fixed linting errors

* fix(5164): ran mage check

(cherry picked from commit a5eb77b)

Co-authored-by: Kaan Yalti <kaan.yalti@elastic.co>
Co-authored-by: Julien Lind <julien.lind@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade verifiers do not retry if the download fails or times out.
5 participants