From 5b064e399f4df29358276fb011c1cf73a6b6c8ac Mon Sep 17 00:00:00 2001 From: JianBo He Date: Thu, 18 Jan 2024 17:29:23 +0800 Subject: [PATCH] chore: improve http connector logs format --- .../src/emqx_bridge_http_connector.erl | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/apps/emqx_bridge_http/src/emqx_bridge_http_connector.erl b/apps/emqx_bridge_http/src/emqx_bridge_http_connector.erl index 51375fc04..44c786751 100644 --- a/apps/emqx_bridge_http/src/emqx_bridge_http_connector.erl +++ b/apps/emqx_bridge_http/src/emqx_bridge_http_connector.erl @@ -251,6 +251,7 @@ start_pool(PoolName, PoolOpts) -> {error, {already_started, _}} -> ?SLOG(warning, #{ msg => "emqx_connector_on_start_already_started", + connector => PoolName, pool_name => PoolName }), ok; @@ -507,8 +508,8 @@ resolve_pool_worker(#{pool_name := PoolName} = State, Key) -> on_get_channels(ResId) -> emqx_bridge_v2:get_channels_for_connector(ResId). -on_get_status(_InstId, #{pool_name := PoolName, connect_timeout := Timeout} = State) -> - case do_get_status(PoolName, Timeout) of +on_get_status(InstId, #{pool_name := InstId, connect_timeout := Timeout} = State) -> + case do_get_status(InstId, Timeout) of ok -> connected; {error, still_connecting} -> @@ -524,12 +525,7 @@ do_get_status(PoolName, Timeout) -> case ehttpc:health_check(Worker, Timeout) of ok -> ok; - {error, Reason} = Error -> - ?SLOG(error, #{ - msg => "http_connector_get_status_failed", - reason => redact(Reason), - worker => Worker - }), + {error, _} = Error -> Error end end, @@ -540,14 +536,20 @@ do_get_status(PoolName, Timeout) -> case [E || {error, _} = E <- Results] of [] -> ok; - Errors -> - hd(Errors) + [{error, Reason} | _] -> + ?SLOG(info, #{ + msg => "health_check_failed", + reason => redact(Reason), + connector => PoolName + }), + {error, Reason} end catch exit:timeout -> - ?SLOG(error, #{ - msg => "http_connector_pmap_failed", - reason => timeout + ?SLOG(info, #{ + msg => "health_check_failed", + reason => timeout, + connector => PoolName }), {error, timeout} end.