diff options
author | Vy Hong <vhong@amazon.com> | 2021-10-06 17:27:08 -0700 |
---|---|---|
committer | mergify-bot <noreply@mergify.io> | 2021-10-14 21:59:44 +0000 |
commit | 85f477112a42a0388bc91c9250281a5fba9c0e8b (patch) | |
tree | 65d9f617c1077d3969fe4d3ee73d8840f4b3646f | |
parent | 0980eb883705b6fc71e4e092a329593083c32327 (diff) | |
download | rabbitmq-server-git-85f477112a42a0388bc91c9250281a5fba9c0e8b.tar.gz |
Log response body of failed AWS requests
(cherry picked from commit a1a22b2a3c7c756b0c3e692d1a1a9e1876bb9ea9)
-rw-r--r-- | deps/rabbitmq_aws/src/rabbitmq_aws.erl | 23 | ||||
-rw-r--r-- | deps/rabbitmq_aws/test/src/rabbitmq_aws_tests.erl | 8 |
2 files changed, 20 insertions, 11 deletions
diff --git a/deps/rabbitmq_aws/src/rabbitmq_aws.erl b/deps/rabbitmq_aws/src/rabbitmq_aws.erl index f132ee1a9b..476539b441 100644 --- a/deps/rabbitmq_aws/src/rabbitmq_aws.erl +++ b/deps/rabbitmq_aws/src/rabbitmq_aws.erl @@ -546,19 +546,24 @@ api_get_request(Service, Path) -> api_get_request_with_retries(Service, Path, ?MAX_RETRIES, ?LINEAR_BACK_OFF_MILLIS). - -spec api_get_request_with_retries(string(), path(), integer(), integer()) -> result(). - %% @doc Invoke an API call to an AWS service with retries. - %% @end +-spec api_get_request_with_retries(string(), path(), integer(), integer()) -> result(). +%% @doc Invoke an API call to an AWS service with retries. +%% @end api_get_request_with_retries(_, _, 0, _) -> rabbit_log:warning("Request to AWS service has failed after ~b retries", [?MAX_RETRIES]), {error, "AWS service is unavailable"}; api_get_request_with_retries(Service, Path, Retries, WaitTimeBetweenRetries) -> ensure_credentials_valid(), case get(Service, Path) of - {ok, {_Headers, Payload}} -> rabbit_log:debug("AWS request: ~s~nResponse: ~p", [Path, Payload]), - {ok, Payload}; - {error, {credentials, _}} -> {error, credentials}; - {error, Message, _} -> rabbit_log:warning("Error occurred ~s~nWill retry AWS request, remaining retries: ~b", [Message, Retries]), - timer:sleep(WaitTimeBetweenRetries), - api_get_request_with_retries(Service, Path, Retries - 1, WaitTimeBetweenRetries) + {ok, {_Headers, Payload}} -> rabbit_log:debug("AWS request: ~s~nResponse: ~p", [Path, Payload]), + {ok, Payload}; + {error, {credentials, _}} -> {error, credentials}; + {error, Message, Response} -> rabbit_log:warning("Error occurred: ~s", [Message]), + case Response of + {_, Payload} -> rabbit_log:warning("Failed AWS request: ~s~nResponse: ~p", [Path, Payload]); + _ -> ok + end, + rabbit_log:warning("Will retry AWS request, remaining retries: ~b", [Retries]), + timer:sleep(WaitTimeBetweenRetries), + api_get_request_with_retries(Service, Path, Retries - 1, WaitTimeBetweenRetries) end. diff --git a/deps/rabbitmq_aws/test/src/rabbitmq_aws_tests.erl b/deps/rabbitmq_aws/test/src/rabbitmq_aws_tests.erl index 0d23df4324..a6bf8b8c52 100644 --- a/deps/rabbitmq_aws/test/src/rabbitmq_aws_tests.erl +++ b/deps/rabbitmq_aws/test/src/rabbitmq_aws_tests.erl @@ -485,7 +485,7 @@ api_get_request_test_() -> secret_access_key = "ExpiredAccessKey", region = "us-east-1", expiration = {{3016, 4, 1}, {12, 0, 0}}}, - meck:expect(httpc, request, 4, {error, "invalid input"}), + meck:expect(httpc, request, 4, {error, "network error"}), {ok, Pid} = rabbitmq_aws:start_link(), rabbitmq_aws:set_region("us-east-1"), rabbitmq_aws:set_credentials(State), @@ -501,7 +501,11 @@ api_get_request_test_() -> secret_access_key = "ExpiredAccessKey", region = "us-east-1", expiration = {{3016, 4, 1}, {12, 0, 0}}}, - meck:expect(httpc, request, 4, meck:seq([{error, "invalid input"}, {ok, {{"HTTP/1.0", 200, "OK"}, [{"content-type", "application/json"}], "{\"data\": \"value\"}"}}])), + meck:expect(httpc, request, 4, meck:seq([ + {error, "network error"}, + {ok, {{"HTTP/1.0", 500, "OK"}, [{"content-type", "application/json"}], "{\"error\": \"server error\"}"}}, + {ok, {{"HTTP/1.0", 200, "OK"}, [{"content-type", "application/json"}], "{\"data\": \"value\"}"}} + ])), {ok, Pid} = rabbitmq_aws:start_link(), rabbitmq_aws:set_region("us-east-1"), rabbitmq_aws:set_credentials(State), |