From 9b17757ae8e01bfd0b1cb73a5f03d82fd95fee68 Mon Sep 17 00:00:00 2001 From: JimMoen Date: Thu, 11 Nov 2021 14:16:15 +0800 Subject: [PATCH] style: make elvis happy --- .../src/emqx_mgmt_api_clients.erl | 148 ++++++++++++------ 1 file changed, 99 insertions(+), 49 deletions(-) diff --git a/apps/emqx_management/src/emqx_mgmt_api_clients.erl b/apps/emqx_management/src/emqx_mgmt_api_clients.erl index f1374aa26..2314c0b47 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_clients.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_clients.erl @@ -67,8 +67,8 @@ , {<<"gte_connected_at">>, timestamp} , {<<"lte_connected_at">>, timestamp}]}). --define(query_fun, {?MODULE, query}). --define(format_fun, {?MODULE, format_channel_info}). +-define(QUERY_FUN, {?MODULE, query}). +-define(FORMAT_FUN, {?MODULE, format_channel_info}). -define(CLIENT_ID_NOT_FOUND, <<"{\"code\": \"RESOURCE_NOT_FOUND\", \"reason\": \"Client id not found\"}">>). @@ -101,43 +101,80 @@ schemas() -> properties(client) -> [ - {awaiting_rel_cnt, integer, <<"v4 api name [awaiting_rel] Number of awaiting PUBREC packet">>}, - {awaiting_rel_max, integer, <<"v4 api name [max_awaiting_rel]. Maximum allowed number of awaiting PUBREC packet">>}, - {clean_start, boolean, <<"Indicate whether the client is using a brand new session">>}, - {clientid, string , <<"Client identifier">>}, - {connected, boolean, <<"Whether the client is connected">>}, - {connected_at, string , <<"Client connection time, rfc3339">>}, - {created_at, string , <<"Session creation time, rfc3339">>}, - {disconnected_at, string , <<"Client offline time, This field is only valid and returned when connected is false, rfc3339">>}, - {expiry_interval, integer, <<"Session expiration interval, with the unit of second">>}, - {heap_size, integer, <<"Process heap size with the unit of byte">>}, - {inflight_cnt, integer, <<"Current length of inflight">>}, - {inflight_max, integer, <<"v4 api name [max_inflight]. Maximum length of inflight">>}, - {ip_address, string , <<"Client's IP address">>}, - {port, integer, <<"Client's port">>}, - {is_bridge, boolean, <<"Indicates whether the client is connectedvia bridge">>}, - {keepalive, integer, <<"keepalive time, with the unit of second">>}, - {mailbox_len, integer, <<"Process mailbox size">>}, - {mqueue_dropped, integer, <<"Number of messages dropped by the message queue due to exceeding the length">>}, - {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">>} + {awaiting_rel_cnt, integer, + <<"v4 api name [awaiting_rel] Number of awaiting PUBREC packet">>}, + {awaiting_rel_max, integer, + <<"v4 api name [max_awaiting_rel]. Maximum allowed number of awaiting PUBREC packet">>}, + {clean_start, boolean, + <<"Indicate whether the client is using a brand new session">>}, + {clientid, string , + <<"Client identifier">>}, + {connected, boolean, + <<"Whether the client is connected">>}, + {connected_at, string , + <<"Client connection time, rfc3339">>}, + {created_at, string , + <<"Session creation time, rfc3339">>}, + {disconnected_at, string , + <<"Client offline time. It's Only valid and returned when connected is false, rfc3339">>}, + {expiry_interval, integer, + <<"Session expiration interval, with the unit of second">>}, + {heap_size, integer, + <<"Process heap size with the unit of byte">>}, + {inflight_cnt, integer, + <<"Current length of inflight">>}, + {inflight_max, integer, + <<"v4 api name [max_inflight]. Maximum length of inflight">>}, + {ip_address, string , + <<"Client's IP address">>}, + {port, integer, + <<"Client's port">>}, + {is_bridge, boolean, + <<"Indicates whether the client is connectedvia bridge">>}, + {keepalive, integer, + <<"keepalive time, with the unit of second">>}, + {mailbox_len, integer, + <<"Process mailbox size">>}, + {mqueue_dropped, integer, + <<"Number of messages dropped by the message queue due to exceeding the length">>}, + {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) -> [ @@ -197,7 +234,9 @@ clients_api() -> name => conn_state, in => query, 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]} }, #{ @@ -211,7 +250,9 @@ clients_api() -> name => proto_name, in => query, 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']} }, #{ @@ -239,34 +280,43 @@ clients_api() -> name => gte_created_at, in => query, 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} }, #{ name => lte_created_at, in => query, 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} }, #{ name => gte_connected_at, in => query, 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} }, #{ name => lte_connected_at, in => query, 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} } ], responses => #{ <<"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}. client_api() -> @@ -436,18 +486,18 @@ list(Params) -> case maps:get(<<"node">>, Params, undefined) of undefined -> Response = emqx_mgmt_api:cluster_query(Params, Tab, - QuerySchema, ?query_fun), + QuerySchema, ?QUERY_FUN), emqx_mgmt_util:generate_response(Response); Node1 -> Node = binary_to_atom(Node1, utf8), ParamsWithoutNode = maps:without([<<"node">>], Params), Response = emqx_mgmt_api:node_query(Node, ParamsWithoutNode, - Tab, QuerySchema, ?query_fun), + Tab, QuerySchema, ?QUERY_FUN), emqx_mgmt_util:generate_response(Response) end. 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}; ClientInfo ->