Merge pull request #12678 from kjellwinblad/kjell/dynamo_bridge/fix/error_log/EMQX-11934
fix: return error reason from dynamo connector status check
This commit is contained in:
commit
9d21372ff0
|
@ -178,14 +178,34 @@ on_batch_query(InstanceId, [{_ChannelId, _} | _] = Query, State) ->
|
|||
on_batch_query(_InstanceId, Query, _State) ->
|
||||
{error, {unrecoverable_error, {invalid_request, Query}}}.
|
||||
|
||||
on_get_status(_InstanceId, #{pool_name := Pool}) ->
|
||||
Health = emqx_resource_pool:health_check_workers(
|
||||
Pool, {emqx_bridge_dynamo_connector_client, is_connected, []}
|
||||
),
|
||||
status_result(Health).
|
||||
health_check_timeout() ->
|
||||
15000.
|
||||
|
||||
status_result(_Status = true) -> ?status_connected;
|
||||
status_result(_Status = false) -> ?status_connecting.
|
||||
on_get_status(_InstanceId, #{pool_name := Pool} = State) ->
|
||||
Health = emqx_resource_pool:health_check_workers(
|
||||
Pool,
|
||||
{emqx_bridge_dynamo_connector_client, is_connected, [
|
||||
emqx_resource_pool:health_check_timeout()
|
||||
]},
|
||||
health_check_timeout(),
|
||||
#{return_values => true}
|
||||
),
|
||||
case Health of
|
||||
{error, timeout} ->
|
||||
{?status_connecting, State, <<"timeout_while_checking_connection">>};
|
||||
{ok, Results} ->
|
||||
status_result(Results, State)
|
||||
end.
|
||||
|
||||
status_result(Results, State) ->
|
||||
case lists:filter(fun(Res) -> Res =/= true end, Results) of
|
||||
[] when Results =:= [] ->
|
||||
?status_connecting;
|
||||
[] ->
|
||||
?status_connected;
|
||||
[{false, Error} | _] ->
|
||||
{?status_connecting, State, Error}
|
||||
end.
|
||||
|
||||
%%========================================================================================
|
||||
%% Helper fns
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
%% API
|
||||
-export([
|
||||
start_link/1,
|
||||
is_connected/1,
|
||||
is_connected/2,
|
||||
query/4
|
||||
]).
|
||||
|
||||
|
@ -27,20 +27,15 @@
|
|||
-export([execute/2]).
|
||||
-endif.
|
||||
|
||||
%% The default timeout for DynamoDB REST API calls is 10 seconds,
|
||||
%% but this value for `gen_server:call` is 5s,
|
||||
%% so we should pass the timeout to `gen_server:call`
|
||||
-define(HEALTH_CHECK_TIMEOUT, 10000).
|
||||
|
||||
%%%===================================================================
|
||||
%%% API
|
||||
%%%===================================================================
|
||||
is_connected(Pid) ->
|
||||
is_connected(Pid, Timeout) ->
|
||||
try
|
||||
gen_server:call(Pid, is_connected, ?HEALTH_CHECK_TIMEOUT)
|
||||
gen_server:call(Pid, is_connected, Timeout)
|
||||
catch
|
||||
_:_ ->
|
||||
false
|
||||
_:Error ->
|
||||
{false, Error}
|
||||
end.
|
||||
|
||||
query(Pid, Table, Query, Templates) ->
|
||||
|
@ -76,8 +71,8 @@ handle_call(is_connected, _From, State) ->
|
|||
case erlcloud_ddb2:list_tables([{limit, 1}]) of
|
||||
{ok, _} ->
|
||||
true;
|
||||
_ ->
|
||||
false
|
||||
Error ->
|
||||
{false, Error}
|
||||
end,
|
||||
{reply, IsConnected, State};
|
||||
handle_call({query, Table, Query, Templates}, _From, State) ->
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
The DynamoDB connector now explicitly reports the error reason upon connection failure. This update addresses the previous limitation where connection failures did not result in any explanation.
|
Loading…
Reference in New Issue