Skip to content

Commit

Permalink
Updated sts creds provider to use the standard retry strategy, update…
Browse files Browse the repository at this point in the history
…d api usage to use the new API. (#115)
  • Loading branch information
JonathanHenson committed Dec 8, 2020
1 parent d52a560 commit 78527d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions source/aws_imds_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ struct aws_imds_client *aws_imds_client_new(
.el_group = options->bootstrap->event_loop_group,
.max_retries = IMDS_DEFAULT_RETRIES,
};
/* exponential backoff is plenty here. We're hitting a local endpoint and do not run the risk of bringing
* down more than the local VM. */
client->retry_strategy = aws_retry_strategy_new_exponential_backoff(allocator, &retry_options);
}
if (!client->retry_strategy) {
Expand Down Expand Up @@ -240,7 +242,7 @@ static void s_user_data_destroy(struct imds_user_data *user_data) {
if (user_data->request) {
aws_http_message_destroy(user_data->request);
}
aws_retry_strategy_release_retry_token(user_data->retry_token);
aws_retry_token_release(user_data->retry_token);
aws_imds_client_release(client);
aws_mem_release(user_data->allocator, user_data);
}
Expand Down Expand Up @@ -596,7 +598,7 @@ static void s_query_complete(struct imds_user_data *user_data) {
if (user_data->status_code == AWS_HTTP_STATUS_CODE_401_UNAUTHORIZED) {
s_invalidate_cached_token_safely(user_data);
s_reset_scratch_user_data(user_data);
aws_retry_strategy_release_retry_token(user_data->retry_token);
aws_retry_token_release(user_data->retry_token);
if (s_get_resource_async_with_imds_token(user_data)) {
s_user_data_release(user_data);
}
Expand Down Expand Up @@ -687,7 +689,7 @@ static void s_on_stream_complete_fn(struct aws_http_stream *stream, int error_co
AWS_LOGF_ERROR(AWS_LS_IMDS_CLIENT, "id=%p: Stream completed, retries have been exhausted.", (void *)client);
imds_user_data->error_code = error_code;
}
} else if (aws_retry_strategy_token_record_success(imds_user_data->retry_token)) {
} else if (aws_retry_token_record_success(imds_user_data->retry_token)) {
AWS_LOGF_ERROR(
AWS_LS_IMDS_CLIENT,
"id=%p: Error while recording successful retry: %s",
Expand Down
16 changes: 10 additions & 6 deletions source/credentials_provider_sts.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static void s_clean_up_user_data(struct sts_creds_provider_user_data *user_data)
s_reset_request_specific_data(user_data);
aws_credentials_provider_release(user_data->provider);

aws_retry_strategy_release_retry_token(user_data->retry_token);
aws_retry_token_release(user_data->retry_token);
aws_mem_release(user_data->allocator, user_data);
}

Expand Down Expand Up @@ -364,7 +364,7 @@ static void s_on_stream_complete_fn(struct aws_http_stream *stream, int error_co
if (!error_code && http_response_code == AWS_HTTP_STATUS_CODE_200_OK) {
/* update the book keeping so we can let the retry strategy make determinations about when the service is
* healthy after an outage. */
if (aws_retry_strategy_token_record_success(provider_user_data->retry_token)) {
if (aws_retry_token_record_success(provider_user_data->retry_token)) {
AWS_LOGF_ERROR(
AWS_LS_AUTH_CREDENTIALS_PROVIDER,
"(id=%p): failed to register operation success: %s",
Expand Down Expand Up @@ -874,11 +874,15 @@ struct aws_credentials_provider *aws_credentials_provider_new_sts(

provider->shutdown_options = options->shutdown_options;

struct aws_exponential_backoff_retry_options retry_options = {
.el_group = options->bootstrap->event_loop_group,
.max_retries = s_max_retries,
struct aws_standard_retry_options retry_options = {
.backoff_retry_options =
{
.el_group = options->bootstrap->event_loop_group,
.max_retries = s_max_retries,
},
};
impl->retry_strategy = aws_retry_strategy_new_exponential_backoff(allocator, &retry_options);

impl->retry_strategy = aws_retry_strategy_new_standard(allocator, &retry_options);

if (!impl->retry_strategy) {
AWS_LOGF_ERROR(
Expand Down

0 comments on commit 78527d2

Please sign in to comment.