Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
-export([to_json/2, content_types_provided/2]).
-export([variances/2]).

-include_lib("kernel/include/logger.hrl").

-include("rabbit_mgmt.hrl").
-include_lib("rabbitmq_management_agent/include/rabbit_mgmt_records.hrl").

Expand All @@ -34,16 +36,15 @@ to_json(ReqData, Context) ->
Limit = rabbit_misc:get_env(rabbit, connection_max, infinity),
case ActiveConns < Limit of
true ->
rabbit_mgmt_util:reply(
#{status => ok,
limit => Limit,
connections => ActiveConns}, ReqData, Context);
rabbit_mgmt_util:reply(#{status => ok}, ReqData, Context);
false ->
?LOG_WARNING(
"Node connection limit is reached. Active connections: ~w, "
"limit: ~w",
[ActiveConns, Limit]),
Body = #{
status => failed,
reason => <<"node connection limit is reached">>,
limit => Limit,
connections => ActiveConns
reason => <<"node connection limit is reached">>
},
{Response, ReqData1, Context1} = rabbit_mgmt_util:reply(
Body, ReqData, Context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
-export([to_json/2, content_types_provided/2]).
-export([variances/2]).

-include_lib("kernel/include/logger.hrl").

-include("rabbit_mgmt.hrl").
-include_lib("rabbitmq_management_agent/include/rabbit_mgmt_records.hrl").

Expand All @@ -33,8 +35,8 @@ content_types_provided(ReqData, Context) ->

to_json(ReqData, Context) ->
case check() of
{ok, Body} ->
rabbit_mgmt_util:reply(Body, ReqData, Context);
ok ->
rabbit_mgmt_util:reply(#{status => ok}, ReqData, Context);
{error, Body} ->
{Response, ReqData1, Context1} = rabbit_mgmt_util:reply(
Body, ReqData, Context),
Expand Down Expand Up @@ -62,13 +64,14 @@ check() ->
Limit = rabbit_misc:get_env(rabbit, connection_max, infinity),
case ActiveConns < Limit of
true ->
{ok, #{status => ok,
limit => Limit,
connections => ActiveConns}};
ok;
false ->
?LOG_WARNING(
"Node connection limit is reached. Active "
"connections: ~w, limit: ~w",
[ActiveConns, Limit]),
{error, #{status => failed,
reason => <<"node connection limit is reached">>,
limit => Limit,
connections => ActiveConns}}
end;
[] ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,6 @@ below_node_connection_limit_test(Config) ->
Path = "/health/checks/below-node-connection-limit",
Check0 = http_get(Config, Path, ?OK),
?assertEqual(<<"ok">>, maps:get(status, Check0)),
?assertEqual(0, maps:get(connections, Check0)),
?assertEqual(<<"infinity">>, maps:get(limit, Check0)),

%% Set the connection limit low and open 'limit' connections.
Limit = 10,
Expand All @@ -489,8 +487,6 @@ below_node_connection_limit_test(Config) ->

Body0 = http_get_failed(Config, Path),
?assertEqual(<<"failed">>, maps:get(<<"status">>, Body0)),
?assertEqual(10, maps:get(<<"limit">>, Body0)),
?assertEqual(10, maps:get(<<"connections">>, Body0)),

%% Clean up the connections and reset the limit.
[catch rabbit_ct_client_helpers:close_connection(C) || C <- Connections],
Expand Down Expand Up @@ -519,8 +515,6 @@ ready_to_serve_clients_test(Config) ->

Body1 = http_get_failed(Config, Path),
?assertEqual(<<"failed">>, maps:get(<<"status">>, Body1)),
?assertEqual(10, maps:get(<<"limit">>, Body1)),
?assertEqual(10, maps:get(<<"connections">>, Body1)),

%% Clean up the connections and reset the limit.
[catch rabbit_ct_client_helpers:close_connection(C) || C <- Connections],
Expand Down