Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clients): fix expiry_interval unit error #9637

Merged
merged 5 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/emqx_management/src/emqx_management.app.src
Expand Up @@ -2,7 +2,7 @@
{application, emqx_management, [
{description, "EMQX Management API and CLI"},
% strict semver, bump manually!
{vsn, "5.0.10"},
{vsn, "5.0.11"},
{modules, []},
{registered, [emqx_management_sup]},
{applications, [kernel, stdlib, emqx_plugins, minirest, emqx]},
Expand Down
17 changes: 5 additions & 12 deletions apps/emqx_management/src/emqx_mgmt_api_clients.erl
Expand Up @@ -65,7 +65,6 @@
{<<"ip_address">>, ip},
{<<"conn_state">>, atom},
{<<"clean_start">>, atom},
{<<"proto_name">>, binary},
{<<"proto_ver">>, integer},
{<<"like_clientid">>, binary},
{<<"like_username">>, binary},
Expand Down Expand Up @@ -145,14 +144,6 @@ schema("/clients") ->
required => false,
description => <<"Whether the client uses a new session">>
})},
{proto_name,
zmstone marked this conversation as resolved.
Show resolved Hide resolved
hoconsc:mk(hoconsc:enum(['MQTT', 'CoAP', 'LwM2M', 'MQTT-SN']), #{
in => query,
required => false,
description =>
<<"Client protocol name, ",
"the possible values are MQTT,CoAP,LwM2M,MQTT-SN">>
})},
{proto_ver,
hoconsc:mk(binary(), #{
in => query,
Expand Down Expand Up @@ -830,8 +821,6 @@ ms(ip_address, X) ->
#{conninfo => #{peername => {X, '_'}}};
ms(clean_start, X) ->
#{conninfo => #{clean_start => X}};
ms(proto_name, X) ->
#{conninfo => #{proto_name => X}};
ms(proto_ver, X) ->
#{conninfo => #{proto_ver => X}};
ms(connected_at, X) ->
Expand Down Expand Up @@ -879,7 +868,8 @@ format_channel_info(WhichNode, {_, ClientInfo0, ClientStats}) ->
ClientInfoMap2 = maps:put(node, Node, ClientInfoMap1),
ClientInfoMap3 = maps:put(ip_address, IpAddress, ClientInfoMap2),
ClientInfoMap4 = maps:put(port, Port, ClientInfoMap3),
ClientInfoMap = maps:put(connected, Connected, ClientInfoMap4),
ClientInfoMap5 = convert_expiry_interval_unit(ClientInfoMap4),
ClientInfoMap = maps:put(connected, Connected, ClientInfoMap5),

RemoveList =
[
Expand Down Expand Up @@ -949,6 +939,9 @@ peername_dispart({Addr, Port}) ->
%% PortBinary = integer_to_binary(Port),
{AddrBinary, Port}.

convert_expiry_interval_unit(ClientInfoMap = #{expiry_interval := Interval}) ->
ClientInfoMap#{expiry_interval := Interval div 1000}.

format_authz_cache({{PubSub, Topic}, {AuthzResult, Timestamp}}) ->
#{
access => PubSub,
Expand Down
6 changes: 5 additions & 1 deletion apps/emqx_management/test/emqx_mgmt_api_clients_SUITE.erl
Expand Up @@ -44,7 +44,10 @@ t_clients(_) ->
AuthHeader = emqx_mgmt_api_test_util:auth_header_(),

{ok, C1} = emqtt:start_link(#{
username => Username1, clientid => ClientId1, proto_ver => v5
username => Username1,
clientid => ClientId1,
proto_ver => v5,
properties => #{'Session-Expiry-Interval' => 120}
}),
{ok, _} = emqtt:connect(C1),
{ok, C2} = emqtt:start_link(#{username => Username2, clientid => ClientId2}),
Expand All @@ -70,6 +73,7 @@ t_clients(_) ->
Client1Response = emqx_json:decode(Client1, [return_maps]),
?assertEqual(Username1, maps:get(<<"username">>, Client1Response)),
?assertEqual(ClientId1, maps:get(<<"clientid">>, Client1Response)),
?assertEqual(120, maps:get(<<"expiry_interval">>, Client1Response)),

%% delete /clients/:clientid kickout
Client2Path = emqx_mgmt_api_test_util:api_path(["clients", binary_to_list(ClientId2)]),
Expand Down
1 change: 1 addition & 0 deletions changes/v5.0.14/fix-9637.en.md
@@ -0,0 +1 @@
Fix the expiry_interval fields of the clients HTTP API to measure in seconds.
1 change: 1 addition & 0 deletions changes/v5.0.14/fix-9637.zh.md
@@ -0,0 +1 @@
修复 clients HTTP API 下的 expiry_interval 字段的时间单位为秒。