feat: log resource_id

This commit is contained in:
zhongwencool 2024-07-16 15:51:10 +08:00
parent 0a04b1ad6e
commit e148d903e8
5 changed files with 20 additions and 13 deletions

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*-
{application, emqx_bridge_mqtt, [
{description, "EMQX MQTT Broker Bridge"},
{vsn, "0.2.2"},
{vsn, "0.2.3"},
{registered, []},
{applications, [
kernel,

View File

@ -207,7 +207,7 @@ start_mqtt_clients(ResourceId, Conf) ->
start_mqtt_clients(ResourceId, Conf, ClientOpts).
start_mqtt_clients(ResourceId, StartConf, ClientOpts) ->
PoolName = <<ResourceId/binary>>,
PoolName = ResourceId,
#{
pool_size := PoolSize
} = StartConf,
@ -227,7 +227,7 @@ start_mqtt_clients(ResourceId, StartConf, ClientOpts) ->
on_stop(ResourceId, State) ->
?SLOG(info, #{
msg => "stopping_mqtt_connector",
connector => ResourceId
resource_id => ResourceId
}),
%% on_stop can be called with State = undefined
StateMap =
@ -271,7 +271,7 @@ on_query(
on_query(ResourceId, {_ChannelId, Msg}, #{}) ->
?SLOG(error, #{
msg => "forwarding_unavailable",
connector => ResourceId,
resource_id => ResourceId,
message => Msg,
reason => "Egress is not configured"
}).
@ -298,7 +298,7 @@ on_query_async(
on_query_async(ResourceId, {_ChannelId, Msg}, _Callback, #{}) ->
?SLOG(error, #{
msg => "forwarding_unavailable",
connector => ResourceId,
resource_id => ResourceId,
message => Msg,
reason => "Egress is not configured"
}).
@ -463,8 +463,10 @@ connect(Options) ->
{ok, Pid} ->
connect(Pid, Name);
{error, Reason} = Error ->
?SLOG(error, #{
IsDryRun = emqx_resource:is_dry_run(Name),
?SLOG(?LOG_LEVEL(IsDryRun), #{
msg => "client_start_failed",
resource_id => Name,
config => emqx_utils:redact(ClientOpts),
reason => Reason
}),
@ -508,10 +510,11 @@ connect(Pid, Name) ->
{ok, _Props} ->
{ok, Pid};
{error, Reason} = Error ->
?SLOG(warning, #{
IsDryRun = emqx_resource:is_dry_run(Name),
?SLOG(?LOG_LEVEL(IsDryRun), #{
msg => "ingress_client_connect_failed",
reason => Reason,
name => Name
resource_id => Name
}),
_ = catch emqtt:stop(Pid),
Error

View File

@ -159,5 +159,6 @@
%% See `hocon_tconf`
-define(TEST_ID_PREFIX, "t_probe_").
-define(RES_METRICS, resource_metrics).
-define(LOG_LEVEL(_L_), case _L_ of true -> info; false -> warning end).
-define(RESOURCE_ALLOCATION_TAB, emqx_resource_allocations).

View File

@ -340,7 +340,7 @@ remove_local(ResId) ->
Error ->
%% Only log, the ResId worker is always removed in manager's remove action.
?SLOG(warning, #{
msg => "remove_local_resource_failed",
msg => "remove_resource_failed",
error => Error,
resource_id => ResId
}),

View File

@ -26,6 +26,7 @@
]).
-include_lib("emqx/include/logger.hrl").
-include("emqx_resource.hrl").
-ifndef(TEST).
-define(HEALTH_CHECK_TIMEOUT, 15000).
@ -44,9 +45,10 @@ start(Name, Mod, Options) ->
start(Name, Mod, Options);
{error, Reason} ->
NReason = parse_reason(Reason),
?SLOG(error, #{
IsDryRun = emqx_resource:is_dry_run(Name),
?SLOG(?LOG_LEVEL(IsDryRun), #{
msg => "start_ecpool_error",
pool_name => Name,
resource_id => Name,
reason => NReason
}),
{error, {start_pool_failed, Name, NReason}}
@ -59,9 +61,10 @@ stop(Name) ->
{error, not_found} ->
ok;
{error, Reason} ->
?SLOG(error, #{
IsDryRun = emqx_resource:is_dry_run(Name),
?SLOG(?LOG_LEVEL(IsDryRun), #{
msg => "stop_ecpool_failed",
pool_name => Name,
resource_id => Name,
reason => Reason
}),
error({stop_pool_failed, Name, Reason})