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(2457): add retry logic to EcsCredentialProvider #2477

Conversation

annuh
Copy link
Contributor

@annuh annuh commented Jun 23, 2022

Fixes #2457

This adds retry-logic for EcsCredentialsProvider. I re-used most of the logic from the InstanceProfileCredentialsProvider.

Error retrieving credential from ECS (cURL error 28: Connection timed out after 5001 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://169.254.170.2/v2/credentials/79b82b9d-d686-417d-98f1-e4c6be43e196)

CONTRIBUTING.md Show resolved Hide resolved
@annuh annuh marked this pull request as ready for review June 23, 2022 16:40
@annuh annuh changed the title Add retry logic to EcsCredentialProvider fix(2457): add retry logic to EcsCredentialProvider Jun 23, 2022
@annuh annuh closed this Jun 25, 2022
@annuh annuh reopened this Jun 25, 2022
@annuh annuh closed this Jun 25, 2022
@annuh annuh reopened this Jun 27, 2022
Copy link
Member

@stobrien89 stobrien89 left a comment

Choose a reason for hiding this comment

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

Looks good! We'll need some unit tests here— I'd suggest follow the example of instanceprofileprovider tests focused on the retry logic. Let us know if you have any questions about this.

src/Credentials/EcsCredentialProvider.php Outdated Show resolved Hide resolved
@annuh
Copy link
Contributor Author

annuh commented Jul 15, 2022

I couldn't run the tests locally in PHP8 (#2403)

With these steps it worked:

  1. Add these lines to composer.json:
+    "config": {
+        "platform": {
+            "php": "7.4"
+        }
+    }
  1. Add this line to phpunit.xml.dist
     <php>
+        <ini name="memory_limit" value="1024M" />
          ...
     </php>
  1. Install Composer packages (for PHP 7.4): composer install
  2. Run tests via docker run -it --rm --name aws-sdk-php-tests -v "$PWD":/usr/src/aws-sdk-php -w /usr/src/aws-sdk-php php:7.4-cli make test

@annuh annuh requested a review from stobrien89 July 15, 2022 12:48
Comment on lines 47 to 54
$this->timeout = (float) getenv(self::ENV_TIMEOUT)
?: (isset($config['timeout'])
? $config['timeout']
: 1.0);
$this->retries = (int) getenv(self::ENV_RETRIES)
?: (isset($config['retries'])
? $config['retries']
: 3);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Personally, I think it's more logical to to use a different fallback here:

  1. Use $config['timeout'], otherwise
  2. Use getenv(self::ENV_TIMEOUT), otherwise
  3. Fallback to 1.0

Some environment variables may already be provided, outside of the application. So if you need multiple ECS credential providers, there is no way to set these configs per provider?

Suggested change
$this->timeout = (float) getenv(self::ENV_TIMEOUT)
?: (isset($config['timeout'])
? $config['timeout']
: 1.0);
$this->retries = (int) getenv(self::ENV_RETRIES)
?: (isset($config['retries'])
? $config['retries']
: 3);
$this->timeout = (int) isset($config['timeout'])
? $config['timeout']
: (getenv(self::ENV_TIMEOUT) ?: 1.0);
$this->retries = (int) isset($config['retries'])
? $config['retries']
: (getenv(self::ENV_RETRIES) ?: 3);

What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

I agree that looking at the most explicit (config) first should be the way to go here. Let's go with that and try to incorporate the null coalescing operator now that we've deprecated < 7.2

@annuh
Copy link
Contributor Author

annuh commented Sep 23, 2022

@stobrien89 can you please take another look at this PR? 🙂

@stobrien89
Copy link
Member

Hi @annuh,

Haven't forgotten about this. We've been sidetracked with some major work on core functionality— should have the capacity to give this a thorough review by the middle of next week.

@Bramw2003
Copy link

@stobrien89 Do you have time to look at this?

@stobrien89
Copy link
Member

Hi all,

Apologies for the delay. We're about to merge #2776 , which adds additional logic to make this more of a generalized "container provider", so I can take another pass at this while we're on the topic.

@annuh annuh marked this pull request as draft December 5, 2023 12:28
@annuh annuh marked this pull request as ready for review December 5, 2023 13:40
@annuh annuh requested a review from stobrien89 December 5, 2023 13:40
@annuh
Copy link
Contributor Author

annuh commented Dec 14, 2023

Just some nits for right now— let's see what this looks like after a rebase and continue from there.

@stobrien89 I fixed the merge conflicts and applied your suggestions. This PR is ready for review now 🙂

@stobrien89 stobrien89 closed this Jan 16, 2024
@stobrien89 stobrien89 reopened this Jan 16, 2024
@stobrien89
Copy link
Member

Had to close and re-open to trigger the CI. Will update you once reviewed!

@Bramw2003
Copy link

@stobrien89 any updates?

@wotta
Copy link
Contributor

wotta commented Apr 19, 2024

Hello @stobrien89,

I hope you are doing well. Do you have a timeline for us when we can expect this PR to be merged?
It appears all work that should have been done is done.

We would greatly appreciate if a timeline can be shared with us.
Thanks in advance and I hope you have a great day!

@stobrien89 stobrien89 closed this Apr 22, 2024
@stobrien89 stobrien89 reopened this Apr 22, 2024
Copy link
Member

@stobrien89 stobrien89 left a comment

Choose a reason for hiding this comment

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

Just a few minor things

src/Credentials/EcsCredentialProvider.php Show resolved Hide resolved
Copy link
Member

@stobrien89 stobrien89 left a comment

Choose a reason for hiding this comment

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

Looks like we should be good to merge after this- There are some test failures being caused by an env var that isn't being cleaned up.


public function testReadsRetriesFromEnvironment()
{
putenv('AWS_METADATA_SERVICE_NUM_ATTEMPTS=1');
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be cleaned up— it's being read by the InstanceProfileProvider tests 🙃

$this->retries = (int) isset($config['retries'])
? $config['retries']
: ((int) getenv(self::ENV_RETRIES) ?: self::DEFAULT_ENV_RETRIES);
$this->attempts = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Not a big deal, but this could be removed from the constructor

* @param array $creds
* @return \Closure
*/
private function getTestClient(
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this to the bottom of the file?

@wotta
Copy link
Contributor

wotta commented May 21, 2024

Thanks for the feedback @stobrien89!
I resolved it in my fork from which will be merged into @annuh's fork tomorrow.

Thank you for the clear communication! Have a nice day 😄

…ntials-provider

Updated code to line up with latest comments and expectations.
@wotta
Copy link
Contributor

wotta commented Jun 3, 2024

Goodmorning @stobrien89,

Hope you had a good weekend. I am guessing you are busy with other thing which is fine, but I am wondering if you happen to have a timeline for when we can expect this PR to be merged.
Let me know if you have more information.

Have a nice day.

@stobrien89
Copy link
Member

Thanks for all of the work @annuh, @wotta and everyone else who collaborated on this!

@stobrien89 stobrien89 merged commit 98a82b4 into aws:master Jun 3, 2024
18 checks passed
@wotta
Copy link
Contributor

wotta commented Jun 3, 2024

Thanks for merging @stobrien89! Have an amazing day😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for retries to EcsCredentialsProvider
4 participants