Skip to content

Commit

Permalink
Only log if not credentials are found
Browse files Browse the repository at this point in the history
Today we log all failed providers, even if one
suceeds later. This is verbose and can often be
confusing. This PR makes it so we only log in
case of failures.
  • Loading branch information
josevalim committed Nov 14, 2023
1 parent 57e4512 commit acfcf53
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
19 changes: 11 additions & 8 deletions src/aws_credentials.erl
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,27 @@ fetch_credentials(Options) ->
{ok, Credentials, ExpirationTime} ->
Tref = setup_update_callback(ExpirationTime),
{ok, Credentials, Tref};
{error, 'no_credentials'} when ShouldCatch ->
{error, 'no_credentials'} ->
?LOG_INFO("No credentials available~n",
[],
#{domain => [aws_credentials]}),
{ok, undefined, setup_callback(?RETRY_DELAY)};
{error, ErrorLog} when is_list(ErrorLog) andalso ShouldCatch ->
?LOG_INFO("No credentials available~n",
[],
#{domain => [aws_credentials]}),
[?LOG_ERROR(String, Args, Metadata) || {String, Args, Metadata} <- ErrorLog],
{ok, undefined, setup_callback(?RETRY_DELAY)}
{ok, undefined_or_fail(ShouldCatch), setup_callback(?RETRY_DELAY)};
{error, ErrorLog} when is_list(ErrorLog) ->
Metadata = #{domain => [aws_credentials]},
?LOG_INFO("No credentials available~n", [], Metadata),
[?LOG_ERROR("Provider ~p reports ~p", [Provider, Error], Metadata)
|| {Provider, Error} <- ErrorLog],
{ok, undefined_or_fail(ShouldCatch), setup_callback(?RETRY_DELAY)}
catch E:R:ST when ShouldCatch ->
?LOG_INFO("aws_credentials ignoring exception ~p:~p (~p)~n",
[E, R, ST],
#{domain => [aws_credentials]}),
{ok, undefined, setup_callback(?RETRY_DELAY)}
end.

undefined_or_fail(true) -> true;
undefined_or_fail(false) -> error(no_credentials).

-spec setup_update_callback('infinity' | binary() | integer()) -> reference().
setup_update_callback(infinity) -> ok;
setup_update_callback(Expires) when is_binary(Expires) ->
Expand Down
6 changes: 1 addition & 5 deletions src/aws_credentials_provider.erl
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ evaluate_providers([], _Options, Errors) when is_list(Errors) ->
evaluate_providers([ Provider | Providers ], Options, Errors) ->
case Provider:fetch(Options) of
{error, _} = Error ->
String = "Provider ~p reports ~p",
Args = [Provider, Error],
Metadata = #{domain => [aws_credentials]},
aws_credentials:log_error(String, Args, Metadata),
evaluate_providers(Providers, Options, [{String, Args, Metadata} | Errors]);
evaluate_providers(Providers, Options, [{Provider, Error} | Errors]);
{ok, Credentials, Expiration} ->
{ok, Credentials, Expiration}
end.
Expand Down

0 comments on commit acfcf53

Please sign in to comment.