Merge pull request #13480 from zhongwencool/rule-engine-log-tag
feat: Rule engine log tag
This commit is contained in:
commit
a2bed1efb8
|
@ -128,3 +128,4 @@
|
|||
|
||||
-define(KEY_PATH, [rule_engine, rules]).
|
||||
-define(RULE_PATH(RULE), [rule_engine, rules, RULE]).
|
||||
-define(TAG, "RULE").
|
||||
|
|
|
@ -134,7 +134,15 @@ republish(
|
|||
},
|
||||
_Args
|
||||
) ->
|
||||
?SLOG(error, #{msg => "recursive_republish_detected", topic => Topic});
|
||||
?SLOG(
|
||||
error,
|
||||
#{
|
||||
msg => "recursive_republish_detected",
|
||||
topic => Topic,
|
||||
rule_id => RuleId
|
||||
},
|
||||
#{tag => ?TAG}
|
||||
);
|
||||
republish(
|
||||
Selected,
|
||||
#{metadata := #{rule_id := RuleId}} = Env,
|
||||
|
@ -311,6 +319,8 @@ render_pub_props(UserPropertiesTemplate, Selected, Env) ->
|
|||
rule_id => emqx_utils_maps:deep_get([metadata, rule_id], ENV, undefined),
|
||||
reason => REASON,
|
||||
property => K
|
||||
}#{
|
||||
tag => ?TAG
|
||||
}
|
||||
)
|
||||
).
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
-include_lib("typerefl/include/types.hrl").
|
||||
-include_lib("hocon/include/hoconsc.hrl").
|
||||
-include_lib("emqx/include/logger.hrl").
|
||||
-include("rule_engine.hrl").
|
||||
|
||||
-export([check_params/2]).
|
||||
|
||||
|
@ -36,10 +37,14 @@ check_params(Params, Tag) ->
|
|||
#{Tag := Checked} -> {ok, Checked}
|
||||
catch
|
||||
throw:Reason ->
|
||||
?SLOG(error, #{
|
||||
?SLOG(
|
||||
info,
|
||||
#{
|
||||
msg => "check_rule_params_failed",
|
||||
reason => Reason
|
||||
}),
|
||||
},
|
||||
#{tag => ?TAG}
|
||||
),
|
||||
{error, Reason}
|
||||
end.
|
||||
|
||||
|
|
|
@ -437,15 +437,15 @@ handle_call({delete_rule, Rule}, _From, State) ->
|
|||
ok = do_delete_rule(Rule),
|
||||
{reply, ok, State};
|
||||
handle_call(Req, _From, State) ->
|
||||
?SLOG(error, #{msg => "unexpected_call", request => Req}),
|
||||
?SLOG(error, #{msg => "unexpected_call", request => Req}, #{tag => ?TAG}),
|
||||
{reply, ignored, State}.
|
||||
|
||||
handle_cast(Msg, State) ->
|
||||
?SLOG(error, #{msg => "unexpected_cast", request => Msg}),
|
||||
?SLOG(error, #{msg => "unexpected_cast", request => Msg}, #{tag => ?TAG}),
|
||||
{noreply, State}.
|
||||
|
||||
handle_info(Info, State) ->
|
||||
?SLOG(error, #{msg => "unexpected_info", request => Info}),
|
||||
?SLOG(error, #{msg => "unexpected_info", request => Info}, #{tag => ?TAG}),
|
||||
{noreply, State}.
|
||||
|
||||
terminate(_Reason, _State) ->
|
||||
|
|
|
@ -388,11 +388,15 @@ param_path_id() ->
|
|||
{ok, #{post_config_update := #{emqx_rule_engine := Rule}}} ->
|
||||
{201, format_rule_info_resp(Rule)};
|
||||
{error, Reason} ->
|
||||
?SLOG(error, #{
|
||||
?SLOG(
|
||||
info,
|
||||
#{
|
||||
msg => "create_rule_failed",
|
||||
id => Id,
|
||||
rule_id => Id,
|
||||
reason => Reason
|
||||
}),
|
||||
},
|
||||
#{tag => ?TAG}
|
||||
),
|
||||
{400, #{code => 'BAD_REQUEST', message => ?ERR_BADARGS(Reason)}}
|
||||
end
|
||||
end
|
||||
|
@ -448,11 +452,15 @@ param_path_id() ->
|
|||
{ok, #{post_config_update := #{emqx_rule_engine := Rule}}} ->
|
||||
{200, format_rule_info_resp(Rule)};
|
||||
{error, Reason} ->
|
||||
?SLOG(error, #{
|
||||
?SLOG(
|
||||
info,
|
||||
#{
|
||||
msg => "update_rule_failed",
|
||||
id => Id,
|
||||
rule_id => Id,
|
||||
reason => Reason
|
||||
}),
|
||||
},
|
||||
#{tag => ?TAG}
|
||||
),
|
||||
{400, #{code => 'BAD_REQUEST', message => ?ERR_BADARGS(Reason)}}
|
||||
end;
|
||||
'/rules/:id'(delete, #{bindings := #{id := Id}}) ->
|
||||
|
@ -463,11 +471,15 @@ param_path_id() ->
|
|||
{ok, _} ->
|
||||
{204};
|
||||
{error, Reason} ->
|
||||
?SLOG(error, #{
|
||||
?SLOG(
|
||||
error,
|
||||
#{
|
||||
msg => "delete_rule_failed",
|
||||
id => Id,
|
||||
rule_id => Id,
|
||||
reason => Reason
|
||||
}),
|
||||
},
|
||||
#{tag => ?TAG}
|
||||
),
|
||||
{500, #{code => 'INTERNAL_ERROR', message => ?ERR_BADARGS(Reason)}}
|
||||
end;
|
||||
not_found ->
|
||||
|
@ -587,10 +599,15 @@ get_rule_metrics(Id) ->
|
|||
NodeMetrics = [format_metrics(Node, Metrics) || {Node, {ok, Metrics}} <- NodeResults],
|
||||
NodeErrors = [Result || Result = {_Node, {NOk, _}} <- NodeResults, NOk =/= ok],
|
||||
NodeErrors == [] orelse
|
||||
?SLOG(warning, #{
|
||||
?SLOG(
|
||||
warning,
|
||||
#{
|
||||
msg => "rpc_get_rule_metrics_errors",
|
||||
rule_id => Id,
|
||||
errors => NodeErrors
|
||||
}),
|
||||
},
|
||||
#{tag => ?TAG}
|
||||
),
|
||||
NodeMetrics.
|
||||
|
||||
format_metrics(Node, #{
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
-module(emqx_rule_sqltester).
|
||||
|
||||
-include_lib("emqx/include/logger.hrl").
|
||||
-include("rule_engine.hrl").
|
||||
|
||||
-export([
|
||||
test/1,
|
||||
|
@ -127,10 +128,15 @@ test(#{sql := Sql, context := Context}) ->
|
|||
end
|
||||
end;
|
||||
{error, Reason} ->
|
||||
?SLOG(debug, #{
|
||||
?SLOG(
|
||||
debug,
|
||||
#{
|
||||
msg => "rulesql_parse_error",
|
||||
detail => Reason
|
||||
}),
|
||||
sql => Sql,
|
||||
reason => Reason
|
||||
},
|
||||
#{tag => ?TAG}
|
||||
),
|
||||
{error, Reason}
|
||||
end.
|
||||
|
||||
|
|
Loading…
Reference in New Issue