Merge pull request #3398 from emqx/master

Auto-pull-request-by-2020-04-17
This commit is contained in:
tigercl 2020-04-17 20:59:41 +08:00 committed by GitHub
commit 0dace34937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 77 additions and 38 deletions

27
.github/ISSUE_TEMPLATE/bug-report.md vendored Normal file
View File

@ -0,0 +1,27 @@
---
name: Bug Report
about: Create a report to help us improve
title: ''
labels: BUG
assignees: tigercl
---
<!-- Please use this template while reporting a bug and provide as much info as possible. Thanks!-->
**What happened**:
**What you expected to happen**:
**How to reproduce it (as minimally and precisely as possible)**:
**Anything else we need to know?**:
**Environment**:
- EMQ X version (e.g. `emqx_ctl status`):
- Hardware configuration (e.g. `lscpu`):
- OS (e.g. `cat /etc/os-release`):
- Kernel (e.g. `uname -a`):
- Erlang/OTP version :
- Others:

View File

@ -0,0 +1,14 @@
---
name: Feature Request
about: Suggest an idea for this project
title: ''
labels: Feature
assignees: tigercl
---
<!-- Please only use this template for submitting enhancement requests -->
**What would you like to be added/modified**:
**Why is this needed**:

View File

@ -0,0 +1,10 @@
---
name: Support Needed
about: Asking a question about usages, docs or anything you're insterested in
title: ''
labels: Support
assignees: tigercl
---
**Please describe your problem in detail, if necessary, you can upload the log file through the attachment**:

View File

@ -2,7 +2,7 @@
{deps,
[{gproc, "0.8.0"},
{jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.2"}}},
{jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.4"}}},
{cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.7.1"}}},
{esockd, {git, "https://github.com/emqx/esockd", {tag, "5.6.1"}}},
{ekka, {git, "https://github.com/emqx/ekka", {tag, "0.7.2"}}},

View File

@ -105,7 +105,7 @@ init(_) ->
{ok, []}.
handle_event({set_alarm, {AlarmId, AlarmDesc = #alarm{timestamp = undefined}}}, State) ->
handle_event({set_alarm, {AlarmId, AlarmDesc#alarm{timestamp = erlang:system_time(second)}}}, State);
handle_event({set_alarm, {AlarmId, AlarmDesc#alarm{timestamp = erlang:system_time(millisecond)}}}, State);
handle_event({set_alarm, Alarm = {AlarmId, AlarmDesc}}, State) ->
?LOG(warning, "New Alarm: ~p, Alarm Info: ~p", [AlarmId, AlarmDesc]),
case encode_alarm(Alarm) of
@ -199,5 +199,5 @@ clear_alarm_(Id) ->
set_alarm_history(Id, Desc) ->
His = #alarm_history{id = Id,
desc = Desc,
clear_at = erlang:system_time(second)},
clear_at = erlang:system_time(millisecond)},
mnesia:dirty_write(?ALARM_HISTORY_TAB, His).

View File

@ -1138,21 +1138,18 @@ do_enhanced_auth(undefined, _AuthData, Channel) ->
do_enhanced_auth(_AuthMethod, undefined, Channel) ->
{error, emqx_reason_codes:connack_error(not_authorized), Channel};
do_enhanced_auth(AuthMethod, AuthData, Channel = #channel{auth_cache = Cache}) ->
case do_auth_check(AuthMethod, AuthData, Cache) of
ok -> {ok, #{}, Channel#channel{auth_cache = #{}}};
case run_hooks('client.enhanced_authenticate',[AuthMethod, AuthData, Cache]) of
{ok, <<>>} -> {ok, #{}, Channel#channel{auth_cache = #{}}};
{ok, NAuthData} ->
NProperties = #{'Authentication-Method' => AuthMethod, 'Authentication-Data' => NAuthData},
{ok, NProperties, Channel#channel{auth_cache = #{}}};
{continue, NAuthData, NCache} ->
NProperties = #{'Authentication-Method' => AuthMethod, 'Authentication-Data' => NAuthData},
{continue, NProperties, Channel#channel{auth_cache = NCache}};
{error, _Reason} ->
_ ->
{error, emqx_reason_codes:connack_error(not_authorized), Channel}
end.
do_auth_check(_AuthMethod, _AuthData, _AuthDataCache) ->
{error, not_authorized}.
%%--------------------------------------------------------------------
%% Process Topic Alias
@ -1345,7 +1342,7 @@ enrich_assigned_clientid(AckProps, #channel{conninfo = ConnInfo,
ensure_connected(Channel = #channel{conninfo = ConnInfo,
clientinfo = ClientInfo}) ->
NConnInfo = ConnInfo#{connected_at => erlang:system_time(second)},
NConnInfo = ConnInfo#{connected_at => erlang:system_time(millisecond)},
ok = run_hooks('client.connected', [ClientInfo, NConnInfo]),
Channel#channel{conninfo = NConnInfo,
conn_state = connected
@ -1422,7 +1419,7 @@ parse_topic_filters(TopicFilters) ->
ensure_disconnected(Reason, Channel = #channel{conninfo = ConnInfo,
clientinfo = ClientInfo}) ->
NConnInfo = ConnInfo#{disconnected_at => erlang:system_time(second)},
NConnInfo = ConnInfo#{disconnected_at => erlang:system_time(millisecond)},
ok = run_hooks('client.disconnected', [ClientInfo, Reason, NConnInfo]),
Channel#channel{conninfo = NConnInfo, conn_state = disconnected}.

View File

@ -126,7 +126,7 @@ get_commands() ->
help() ->
print("Usage: ~s~n", [?MODULE]),
[begin print("~80..-s~n", [""]), Mod:Cmd(usage) end
[begin print("~110..-s~n", [""]), Mod:Cmd(usage) end
|| {_, {Mod, Cmd}, _} <- ets:tab2list(?CMD_TAB)].
-spec(print(io:format()) -> ok).
@ -165,7 +165,7 @@ format_usage(CmdParams, Desc) ->
CmdLines = split_cmd(CmdParams),
DescLines = split_cmd(Desc),
lists:foldl(fun({CmdStr, DescStr}, Usage) ->
Usage ++ format("~-48s# ~s~n", [CmdStr, DescStr])
Usage ++ format("~-70s# ~s~n", [CmdStr, DescStr])
end, "", zip_cmd(CmdLines, DescLines)).
%%--------------------------------------------------------------------

View File

@ -520,11 +520,12 @@ reserved_idx('client.connect') -> 200;
reserved_idx('client.connack') -> 201;
reserved_idx('client.connected') -> 202;
reserved_idx('client.authenticate') -> 203;
reserved_idx('client.auth.anonymous') -> 204;
reserved_idx('client.check_acl') -> 205;
reserved_idx('client.subscribe') -> 206;
reserved_idx('client.unsubscribe') -> 207;
reserved_idx('client.disconnected') -> 208;
reserved_idx('client.enhanced_authenticate') -> 204;
reserved_idx('client.auth.anonymous') -> 205;
reserved_idx('client.check_acl') -> 206;
reserved_idx('client.subscribe') -> 207;
reserved_idx('client.unsubscribe') -> 208;
reserved_idx('client.disconnected') -> 209;
reserved_idx('session.created') -> 220;
reserved_idx('session.resumed') -> 221;

View File

@ -49,6 +49,7 @@
, unregister/1
, unregister_all/0
, is_registered/1
, all_registered_topics/0
]).
%% gen_server callbacks
@ -194,6 +195,9 @@ unregister_all() ->
is_registered(Topic) ->
ets:member(?TAB, Topic).
all_registered_topics() ->
[Topic || {Topic, _CRef} <- ets:tab2list(?TAB)].
%%--------------------------------------------------------------------
%% gen_server callbacks
%%--------------------------------------------------------------------

View File

@ -26,6 +26,7 @@
, unload/0
, unload/1
, reload/1
, find_module/1
, load_module/2
]).

View File

@ -168,7 +168,7 @@ init(#{zone := Zone}, #{receive_maximum := MaxInflight}) ->
awaiting_rel = #{},
max_awaiting_rel = get_env(Zone, max_awaiting_rel, 100),
await_rel_timeout = timer:seconds(get_env(Zone, await_rel_timeout, 300)),
created_at = erlang:system_time(second)
created_at = erlang:system_time(millisecond)
}.
%% @private init mq

View File

@ -120,7 +120,7 @@ t_handle_in_connect_auth_failed(_) ->
clean_start = true,
keepalive = 30,
properties = #{
'Authentication-Method' => "failed_auth_method",
'Authentication-Method' => <<"failed_auth_method">>,
'Authentication-Data' => <<"failed_auth_data">>
},
clientid = <<"clientid">>,
@ -131,7 +131,7 @@ t_handle_in_connect_auth_failed(_) ->
t_handle_in_continue_auth(_) ->
Properties = #{
'Authentication-Method' => "failed_auth_method",
'Authentication-Method' => <<"failed_auth_method">>,
'Authentication-Data' => <<"failed_auth_data">>
},
{shutdown, bad_authentication_method, ?CONNACK_PACKET(?RC_BAD_AUTHENTICATION_METHOD), _} =
@ -141,7 +141,7 @@ t_handle_in_continue_auth(_) ->
t_handle_in_re_auth(_) ->
Properties = #{
'Authentication-Method' => "failed_auth_method",
'Authentication-Method' => <<"failed_auth_method">>,
'Authentication-Data' => <<"failed_auth_data">>
},
{ok, [{outgoing, ?DISCONNECT_PACKET(?RC_BAD_AUTHENTICATION_METHOD)}, {close, bad_authentication_method}], _} =

View File

@ -76,24 +76,9 @@ t_print(_) ->
t_usage(_) ->
CmdParams1 = "emqx_cmd_1 param1 param2",
CmdDescr1 = "emqx_cmd_1 is a test command means nothing",
Output1 = "emqx_cmd_1 param1 param2 # emqx_cmd_1 is a test command means nothing\n",
% - usage/1,2 should return ok
ok = emqx_ctl:usage([{CmdParams1, CmdDescr1}, {CmdParams1, CmdDescr1}]),
ok = emqx_ctl:usage(CmdParams1, CmdDescr1),
% - check the output of the usage
mock_print(),
?assertEqual(Output1, emqx_ctl:usage(CmdParams1, CmdDescr1)),
?assertEqual([Output1, Output1], emqx_ctl:usage([{CmdParams1, CmdDescr1}, {CmdParams1, CmdDescr1}])),
% - for the commands or descriptions have multi-lines
CmdParams2 = "emqx_cmd_2 param1 param2",
CmdDescr2 = "emqx_cmd_2 is a test command\nmeans nothing",
Output2 = "emqx_cmd_2 param1 param2 # emqx_cmd_2 is a test command\n"
" ""# means nothing\n",
?assertEqual(Output2, emqx_ctl:usage(CmdParams2, CmdDescr2)),
?assertEqual([Output2, Output2], emqx_ctl:usage([{CmdParams2, CmdDescr2}, {CmdParams2, CmdDescr2}])),
unmock_print().
ok = emqx_ctl:usage(CmdParams1, CmdDescr1).
t_unexpected(_) ->
with_ctl_server(