fix: `emqx_ctl traces ...` command args
* use second time as trace `start_at` and `end_at` * default trace time duration 30min to same as api created * prevent format line broken
This commit is contained in:
parent
8d6652f162
commit
0788f2f197
|
@ -457,7 +457,7 @@ trace(["list"]) ->
|
|||
lists:foreach(
|
||||
fun(Trace) ->
|
||||
#{type := Type, filter := Filter, level := Level, dst := Dst} = Trace,
|
||||
emqx_ctl:print("Trace(~s=~s, level=~s, destination=~p)~n", [Type, Filter, Level, Dst])
|
||||
emqx_ctl:print("Trace(~s=~s, level=~s, destination=~0p)~n", [Type, Filter, Level, Dst])
|
||||
end,
|
||||
emqx_trace_handler:running()
|
||||
);
|
||||
|
@ -529,7 +529,7 @@ traces(["list"]) ->
|
|||
log_size := LogSize
|
||||
} = Trace,
|
||||
emqx_ctl:print(
|
||||
"Trace(~s: ~s=~s, ~s, LogSize:~p)~n",
|
||||
"Trace(~s: ~s=~s, ~s, LogSize:~0p)~n",
|
||||
[Name, Type, maps:get(Type, Trace), Status, LogSize]
|
||||
)
|
||||
end,
|
||||
|
@ -542,7 +542,7 @@ traces(["stop", Name]) ->
|
|||
traces(["delete", Name]) ->
|
||||
trace_cluster_del(Name);
|
||||
traces(["start", Name, Operation, Filter]) ->
|
||||
traces(["start", Name, Operation, Filter, "900"]);
|
||||
traces(["start", Name, Operation, Filter, "1800"]);
|
||||
traces(["start", Name, Operation, Filter0, DurationS]) ->
|
||||
case trace_type(Operation, Filter0) of
|
||||
{ok, Type, Filter} -> trace_cluster_on(Name, Type, Filter, DurationS);
|
||||
|
@ -559,14 +559,14 @@ traces(_) ->
|
|||
]).
|
||||
|
||||
trace_cluster_on(Name, Type, Filter, DurationS0) ->
|
||||
Now = emqx_trace:now_second(),
|
||||
DurationS = list_to_integer(DurationS0),
|
||||
Now = erlang:system_time(second),
|
||||
Trace = #{
|
||||
name => list_to_binary(Name),
|
||||
type => atom_to_binary(Type),
|
||||
Type => list_to_binary(Filter),
|
||||
start_at => list_to_binary(calendar:system_time_to_rfc3339(Now)),
|
||||
end_at => list_to_binary(calendar:system_time_to_rfc3339(Now + DurationS))
|
||||
name => bin(Name),
|
||||
type => Type,
|
||||
Type => bin(Filter),
|
||||
start_at => Now,
|
||||
end_at => Now + DurationS
|
||||
},
|
||||
case emqx_trace:create(Trace) of
|
||||
{ok, _} ->
|
||||
|
@ -579,19 +579,19 @@ trace_cluster_on(Name, Type, Filter, DurationS0) ->
|
|||
end.
|
||||
|
||||
trace_cluster_del(Name) ->
|
||||
case emqx_trace:delete(list_to_binary(Name)) of
|
||||
case emqx_trace:delete(bin(Name)) of
|
||||
ok -> emqx_ctl:print("Del cluster_trace ~s successfully~n", [Name]);
|
||||
{error, Error} -> emqx_ctl:print("[error] Del cluster_trace ~s: ~p~n", [Name, Error])
|
||||
end.
|
||||
|
||||
trace_cluster_off(Name) ->
|
||||
case emqx_trace:update(list_to_binary(Name), false) of
|
||||
case emqx_trace:update(bin(Name), false) of
|
||||
ok -> emqx_ctl:print("Stop cluster_trace ~s successfully~n", [Name]);
|
||||
{error, Error} -> emqx_ctl:print("[error] Stop cluster_trace ~s: ~p~n", [Name, Error])
|
||||
end.
|
||||
|
||||
trace_type("client", ClientId) -> {ok, clientid, list_to_binary(ClientId)};
|
||||
trace_type("topic", Topic) -> {ok, topic, list_to_binary(Topic)};
|
||||
trace_type("client", ClientId) -> {ok, clientid, bin(ClientId)};
|
||||
trace_type("topic", Topic) -> {ok, topic, bin(Topic)};
|
||||
trace_type("ip_address", IP) -> {ok, ip_address, IP};
|
||||
trace_type(_, _) -> error.
|
||||
|
||||
|
|
|
@ -157,6 +157,31 @@ t_traces(_Config) ->
|
|||
%% traces delete <Name> # Delete trace in cluster
|
||||
ok.
|
||||
|
||||
t_traces_client(_Config) ->
|
||||
TraceC = "TraceNameClientID",
|
||||
emqx_ctl:run_command(["traces", "start", TraceC, "client", "ClientID"]),
|
||||
emqx_ctl:run_command(["traces", "stop", TraceC]),
|
||||
emqx_ctl:run_command(["traces", "delete", TraceC]).
|
||||
|
||||
t_traces_client_with_duration(_Config) ->
|
||||
TraceC = "TraceNameClientID",
|
||||
Duration = "1000",
|
||||
emqx_ctl:run_command(["traces", "start", TraceC, "client", "ClientID", Duration]),
|
||||
emqx_ctl:run_command(["traces", "stop", TraceC]),
|
||||
emqx_ctl:run_command(["traces", "delete", TraceC]).
|
||||
|
||||
t_traces_topic(_Config) ->
|
||||
TraceT = "TraceNameTopic",
|
||||
emqx_ctl:run_command(["traces", "start", TraceT, "topic", "a/b"]),
|
||||
emqx_ctl:run_command(["traces", "stop", TraceT]),
|
||||
emqx_ctl:run_command(["traces", "delete", TraceT]).
|
||||
|
||||
t_traces_ip(_Config) ->
|
||||
TraceI = "TraceNameIP",
|
||||
emqx_ctl:run_command(["traces", "start", TraceI, "ip_address", "127.0.0.1"]),
|
||||
emqx_ctl:run_command(["traces", "stop", TraceI]),
|
||||
emqx_ctl:run_command(["traces", "delete", TraceI]).
|
||||
|
||||
t_listeners(_Config) ->
|
||||
%% listeners # List listeners
|
||||
emqx_ctl:run_command(["listeners"]),
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fixing `emqx_ctl traces` command.
|
Loading…
Reference in New Issue