style: make elvis happy

This commit is contained in:
JimMoen 2021-11-11 14:16:15 +08:00
parent 37cdd429b2
commit 9b17757ae8
1 changed files with 99 additions and 49 deletions

View File

@ -67,8 +67,8 @@
, {<<"gte_connected_at">>, timestamp} , {<<"gte_connected_at">>, timestamp}
, {<<"lte_connected_at">>, timestamp}]}). , {<<"lte_connected_at">>, timestamp}]}).
-define(query_fun, {?MODULE, query}). -define(QUERY_FUN, {?MODULE, query}).
-define(format_fun, {?MODULE, format_channel_info}). -define(FORMAT_FUN, {?MODULE, format_channel_info}).
-define(CLIENT_ID_NOT_FOUND, -define(CLIENT_ID_NOT_FOUND,
<<"{\"code\": \"RESOURCE_NOT_FOUND\", \"reason\": \"Client id not found\"}">>). <<"{\"code\": \"RESOURCE_NOT_FOUND\", \"reason\": \"Client id not found\"}">>).
@ -101,43 +101,80 @@ schemas() ->
properties(client) -> properties(client) ->
[ [
{awaiting_rel_cnt, integer, <<"v4 api name [awaiting_rel] Number of awaiting PUBREC packet">>}, {awaiting_rel_cnt, integer,
{awaiting_rel_max, integer, <<"v4 api name [max_awaiting_rel]. Maximum allowed number of awaiting PUBREC packet">>}, <<"v4 api name [awaiting_rel] Number of awaiting PUBREC packet">>},
{clean_start, boolean, <<"Indicate whether the client is using a brand new session">>}, {awaiting_rel_max, integer,
{clientid, string , <<"Client identifier">>}, <<"v4 api name [max_awaiting_rel]. Maximum allowed number of awaiting PUBREC packet">>},
{connected, boolean, <<"Whether the client is connected">>}, {clean_start, boolean,
{connected_at, string , <<"Client connection time, rfc3339">>}, <<"Indicate whether the client is using a brand new session">>},
{created_at, string , <<"Session creation time, rfc3339">>}, {clientid, string ,
{disconnected_at, string , <<"Client offline time, This field is only valid and returned when connected is false, rfc3339">>}, <<"Client identifier">>},
{expiry_interval, integer, <<"Session expiration interval, with the unit of second">>}, {connected, boolean,
{heap_size, integer, <<"Process heap size with the unit of byte">>}, <<"Whether the client is connected">>},
{inflight_cnt, integer, <<"Current length of inflight">>}, {connected_at, string ,
{inflight_max, integer, <<"v4 api name [max_inflight]. Maximum length of inflight">>}, <<"Client connection time, rfc3339">>},
{ip_address, string , <<"Client's IP address">>}, {created_at, string ,
{port, integer, <<"Client's port">>}, <<"Session creation time, rfc3339">>},
{is_bridge, boolean, <<"Indicates whether the client is connectedvia bridge">>}, {disconnected_at, string ,
{keepalive, integer, <<"keepalive time, with the unit of second">>}, <<"Client offline time. It's Only valid and returned when connected is false, rfc3339">>},
{mailbox_len, integer, <<"Process mailbox size">>}, {expiry_interval, integer,
{mqueue_dropped, integer, <<"Number of messages dropped by the message queue due to exceeding the length">>}, <<"Session expiration interval, with the unit of second">>},
{mqueue_len, integer, <<"Current length of message queue">>}, {heap_size, integer,
{mqueue_max, integer, <<"v4 api name [max_mqueue]. Maximum length of message queue">>}, <<"Process heap size with the unit of byte">>},
{node, string , <<"Name of the node to which the client is connected">>}, {inflight_cnt, integer,
{proto_name, string , <<"Client protocol name">>}, <<"Current length of inflight">>},
{proto_ver, integer, <<"Protocol version used by the client">>}, {inflight_max, integer,
{recv_cnt, integer, <<"Number of TCP packets received">>}, <<"v4 api name [max_inflight]. Maximum length of inflight">>},
{recv_msg, integer, <<"Number of PUBLISH packets received">>}, {ip_address, string ,
{recv_oct, integer, <<"Number of bytes received by EMQ X Broker (the same below)">>}, <<"Client's IP address">>},
{recv_pkt, integer, <<"Number of MQTT packets received">>}, {port, integer,
{reductions, integer, <<"Erlang reduction">>}, <<"Client's port">>},
{send_cnt, integer, <<"Number of TCP packets sent">>}, {is_bridge, boolean,
{send_msg, integer, <<"Number of PUBLISH packets sent">>}, <<"Indicates whether the client is connectedvia bridge">>},
{send_oct, integer, <<"Number of bytes sent">>}, {keepalive, integer,
{send_pkt, integer, <<"Number of MQTT packets sent">>}, <<"keepalive time, with the unit of second">>},
{subscriptions_cnt, integer, <<"Number of subscriptions established by this client.">>}, {mailbox_len, integer,
{subscriptions_max, integer, <<"v4 api name [max_subscriptions] Maximum number of subscriptions allowed by this client">>}, <<"Process mailbox size">>},
{username, string , <<"User name of client when connecting">>}, {mqueue_dropped, integer,
{will_msg, string , <<"Client will message">>}, <<"Number of messages dropped by the message queue due to exceeding the length">>},
{zone, string , <<"Indicate the configuration group used by the client">>} {mqueue_len, integer,
<<"Current length of message queue">>},
{mqueue_max, integer,
<<"v4 api name [max_mqueue]. Maximum length of message queue">>},
{node, string ,
<<"Name of the node to which the client is connected">>},
{proto_name, string ,
<<"Client protocol name">>},
{proto_ver, integer,
<<"Protocol version used by the client">>},
{recv_cnt, integer,
<<"Number of TCP packets received">>},
{recv_msg, integer,
<<"Number of PUBLISH packets received">>},
{recv_oct, integer,
<<"Number of bytes received by EMQ X Broker (the same below)">>},
{recv_pkt, integer,
<<"Number of MQTT packets received">>},
{reductions, integer,
<<"Erlang reduction">>},
{send_cnt, integer,
<<"Number of TCP packets sent">>},
{send_msg, integer,
<<"Number of PUBLISH packets sent">>},
{send_oct, integer,
<<"Number of bytes sent">>},
{send_pkt, integer,
<<"Number of MQTT packets sent">>},
{subscriptions_cnt, integer,
<<"Number of subscriptions established by this client.">>},
{subscriptions_max, integer,
<<"v4 api name [max_subscriptions] Maximum number of subscriptions allowed by this client">>},
{username, string ,
<<"User name of client when connecting">>},
{will_msg, string ,
<<"Client will message">>},
{zone, string ,
<<"Indicate the configuration group used by the client">>}
]; ];
properties(authz_cache) -> properties(authz_cache) ->
[ [
@ -197,7 +234,9 @@ clients_api() ->
name => conn_state, name => conn_state,
in => query, in => query,
required => false, required => false,
description => <<"The current connection status of the client, the possible values are connected,idle,disconnected">>, description =>
<<"The current connection status of the client, ",
"the possible values are connected,idle,disconnected">>,
schema => #{type => string, enum => [connected, idle, disconnected]} schema => #{type => string, enum => [connected, idle, disconnected]}
}, },
#{ #{
@ -211,7 +250,9 @@ clients_api() ->
name => proto_name, name => proto_name,
in => query, in => query,
required => false, required => false,
description => <<"Client protocol name, the possible values are MQTT,CoAP,LwM2M,MQTT-SN">>, description =>
<<"Client protocol name, ",
"the possible values are MQTT,CoAP,LwM2M,MQTT-SN">>,
schema => #{type => string, enum => ['MQTT', 'CoAP', 'LwM2M', 'MQTT-SN']} schema => #{type => string, enum => ['MQTT', 'CoAP', 'LwM2M', 'MQTT-SN']}
}, },
#{ #{
@ -239,34 +280,43 @@ clients_api() ->
name => gte_created_at, name => gte_created_at,
in => query, in => query,
required => false, required => false,
description => <<"Search client session creation time by greater than or equal method, rfc3339 or timestamp(millisecond)">>, description =>
<<"Search client session creation time by greater than or equal method, "
"rfc3339 or timestamp(millisecond)">>,
schema => #{type => string} schema => #{type => string}
}, },
#{ #{
name => lte_created_at, name => lte_created_at,
in => query, in => query,
required => false, required => false,
description => <<"Search client session creation time by less than or equal method, rfc3339 or timestamp(millisecond)">>, description =>
<<"Search client session creation time by less than or equal method, ",
"rfc3339 or timestamp(millisecond)">>,
schema => #{type => string} schema => #{type => string}
}, },
#{ #{
name => gte_connected_at, name => gte_connected_at,
in => query, in => query,
required => false, required => false,
description => <<"Search client connection creation time by greater than or equal method, rfc3339 or timestamp(millisecond)">>, description =>
<<"Search client connection creation time by greater than or equal method, ",
"rfc3339 or timestamp(millisecond)">>,
schema => #{type => string} schema => #{type => string}
}, },
#{ #{
name => lte_connected_at, name => lte_connected_at,
in => query, in => query,
required => false, required => false,
description => <<"Search client connection creation time by less than or equal method, rfc3339 or timestamp(millisecond) ">>, description =>
<<"Search client connection creation time by less than or equal method, ",
"rfc3339 or timestamp(millisecond) ">>,
schema => #{type => string} schema => #{type => string}
} }
], ],
responses => #{ responses => #{
<<"200">> => emqx_mgmt_util:array_schema(client, <<"List clients 200 OK">>), <<"200">> => emqx_mgmt_util:array_schema(client, <<"List clients 200 OK">>),
<<"400">> => emqx_mgmt_util:error_schema(<<"Invalid parameters">>, ['INVALID_PARAMETER'])}}}, <<"400">> => emqx_mgmt_util:error_schema( <<"Invalid parameters">>
, ['INVALID_PARAMETER'])}}},
{"/clients", Metadata, clients}. {"/clients", Metadata, clients}.
client_api() -> client_api() ->
@ -436,18 +486,18 @@ list(Params) ->
case maps:get(<<"node">>, Params, undefined) of case maps:get(<<"node">>, Params, undefined) of
undefined -> undefined ->
Response = emqx_mgmt_api:cluster_query(Params, Tab, Response = emqx_mgmt_api:cluster_query(Params, Tab,
QuerySchema, ?query_fun), QuerySchema, ?QUERY_FUN),
emqx_mgmt_util:generate_response(Response); emqx_mgmt_util:generate_response(Response);
Node1 -> Node1 ->
Node = binary_to_atom(Node1, utf8), Node = binary_to_atom(Node1, utf8),
ParamsWithoutNode = maps:without([<<"node">>], Params), ParamsWithoutNode = maps:without([<<"node">>], Params),
Response = emqx_mgmt_api:node_query(Node, ParamsWithoutNode, Response = emqx_mgmt_api:node_query(Node, ParamsWithoutNode,
Tab, QuerySchema, ?query_fun), Tab, QuerySchema, ?QUERY_FUN),
emqx_mgmt_util:generate_response(Response) emqx_mgmt_util:generate_response(Response)
end. end.
lookup(#{clientid := ClientID}) -> lookup(#{clientid := ClientID}) ->
case emqx_mgmt:lookup_client({clientid, ClientID}, ?format_fun) of case emqx_mgmt:lookup_client({clientid, ClientID}, ?FORMAT_FUN) of
[] -> [] ->
{404, ?CLIENT_ID_NOT_FOUND}; {404, ?CLIENT_ID_NOT_FOUND};
ClientInfo -> ClientInfo ->