summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVy Hong <vhong@amazon.com>2021-10-06 17:27:08 -0700
committermergify-bot <noreply@mergify.io>2021-10-14 22:07:22 +0000
commitf04973b7952f76eeae59a68f37a53ea608ace866 (patch)
treef0ea6d14fe7a2a870c7f7737a385d816372daab9
parent8c1d85c4f529685210b86450614df603bee3737c (diff)
downloadrabbitmq-server-git-mergify/bp/v3.8.x/pr-3580.tar.gz
Log response body of failed AWS requestsmergify/bp/v3.8.x/pr-3580
(cherry picked from commit a1a22b2a3c7c756b0c3e692d1a1a9e1876bb9ea9) (cherry picked from commit 85f477112a42a0388bc91c9250281a5fba9c0e8b) # Conflicts: # deps/rabbitmq_aws/src/rabbitmq_aws.erl
-rw-r--r--deps/rabbitmq_aws/src/rabbitmq_aws.erl20
-rw-r--r--deps/rabbitmq_aws/test/src/rabbitmq_aws_tests.erl8
2 files changed, 23 insertions, 5 deletions
diff --git a/deps/rabbitmq_aws/src/rabbitmq_aws.erl b/deps/rabbitmq_aws/src/rabbitmq_aws.erl
index 03ca3c29f8..99c82d5aec 100644
--- a/deps/rabbitmq_aws/src/rabbitmq_aws.erl
+++ b/deps/rabbitmq_aws/src/rabbitmq_aws.erl
@@ -546,19 +546,33 @@ 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
+<<<<<<< HEAD
{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)
+>>>>>>> 85f477112a (Log response body of failed AWS requests)
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),