fix: bad integer, bad qos; TODO: gateway api * 2

This commit is contained in:
DDDHuang 2022-04-14 18:56:03 +08:00
parent 92eaf403f1
commit 82ce6ae9f9
10 changed files with 65 additions and 104 deletions

View File

@ -107,7 +107,7 @@ fields(sampler) ->
Samplers = Samplers =
[{SamplerName, hoconsc:mk(integer(), #{desc => swagger_desc(SamplerName)})} [{SamplerName, hoconsc:mk(integer(), #{desc => swagger_desc(SamplerName)})}
|| SamplerName <- ?SAMPLER_LIST], || SamplerName <- ?SAMPLER_LIST],
[{time_stamp, hoconsc:mk(integer(), #{desc => <<"Timestamp">>})} | Samplers]; [{time_stamp, hoconsc:mk(non_neg_integer(), #{desc => <<"Timestamp">>})} | Samplers];
fields(sampler_current) -> fields(sampler_current) ->
[{SamplerName, hoconsc:mk(integer(), #{desc => swagger_desc(SamplerName)})} [{SamplerName, hoconsc:mk(integer(), #{desc => swagger_desc(SamplerName)})}

View File

@ -284,12 +284,12 @@ fields(gateway_overview) ->
)}, )},
{max_connections, {max_connections,
mk( mk(
integer(), pos_integer(),
#{desc => <<"The Gateway allowed maximum connections/clients">>} #{desc => <<"The Gateway allowed maximum connections/clients">>}
)}, )},
{current_connections, {current_connections,
mk( mk(
integer(), non_neg_integer(),
#{desc => <<"The Gateway current connected connections/clients">>} #{desc => <<"The Gateway current connected connections/clients">>}
)}, )},
{listeners, {listeners,
@ -410,11 +410,11 @@ convert_listener_struct(Schema) ->
), ),
lists:keystore(listeners, 1, Schema1, {listeners, ListenerSchema}). lists:keystore(listeners, 1, Schema1, {listeners, ListenerSchema}).
remove_listener_and_authn(Schmea) -> remove_listener_and_authn(Schema) ->
lists:keydelete( lists:keydelete(
authentication, authentication,
1, 1,
lists:keydelete(listeners, 1, Schmea) lists:keydelete(listeners, 1, Schema)
). ).
listeners_schema(?R_REF(_Mod, tcp_listeners)) -> listeners_schema(?R_REF(_Mod, tcp_listeners)) ->

View File

@ -392,21 +392,21 @@ format_channel_info({_, Infos, Stats} = R) ->
{heap_size, Stats, 0}, {heap_size, Stats, 0},
{reductions, Stats, 0} {reductions, Stats, 0}
], ],
eval(FetchX ++ extra_feilds(R)). eval(FetchX ++ extra_fields(R)).
extra_feilds({_, Infos, _Stats} = R) -> extra_fields({_, Infos, _Stats} = R) ->
extra_feilds( extra_fields(
maps:get(protocol, maps:get(clientinfo, Infos)), maps:get(protocol, maps:get(clientinfo, Infos)),
R R
). ).
extra_feilds(lwm2m, {_, Infos, _Stats}) -> extra_fields(lwm2m, {_, Infos, _Stats}) ->
ClientInfo = maps:get(clientinfo, Infos, #{}), ClientInfo = maps:get(clientinfo, Infos, #{}),
[ [
{endpoint_name, ClientInfo}, {endpoint_name, ClientInfo},
{lifetime, ClientInfo} {lifetime, ClientInfo}
]; ];
extra_feilds(_, _) -> extra_fields(_, _) ->
[]. [].
eval(Ls) -> eval(Ls) ->
@ -495,7 +495,7 @@ schema("/gateway/:name/clients/:clientid/subscriptions") ->
#{ #{
200 => emqx_dashboard_swagger:schema_with_examples( 200 => emqx_dashboard_swagger:schema_with_examples(
hoconsc:array(ref(subscription)), hoconsc:array(ref(subscription)),
examples_subsctiption_list() examples_subscription_list()
) )
} }
) )
@ -506,14 +506,14 @@ schema("/gateway/:name/clients/:clientid/subscriptions") ->
parameters => params_client_insta(), parameters => params_client_insta(),
'requestBody' => emqx_dashboard_swagger:schema_with_examples( 'requestBody' => emqx_dashboard_swagger:schema_with_examples(
ref(subscription), ref(subscription),
examples_subsctiption() examples_subscription()
), ),
responses => responses =>
?STANDARD_RESP( ?STANDARD_RESP(
#{ #{
201 => emqx_dashboard_swagger:schema_with_examples( 201 => emqx_dashboard_swagger:schema_with_examples(
ref(subscription), ref(subscription),
examples_subsctiption() examples_subscription()
) )
} }
) )
@ -1089,7 +1089,7 @@ examples_client() ->
} }
}. }.
examples_subsctiption_list() -> examples_subscription_list() ->
#{ #{
general_subscription_list => general_subscription_list =>
#{ #{
@ -1103,7 +1103,7 @@ examples_subsctiption_list() ->
} }
}. }.
examples_subsctiption() -> examples_subscription() ->
#{ #{
general_subscription => general_subscription =>
#{ #{

View File

@ -627,10 +627,12 @@ fields(tcp_listener_opts) ->
{high_watermark, mk(binary(), #{})}, {high_watermark, mk(binary(), #{})},
{nodelay, mk(boolean(), #{})}, {nodelay, mk(boolean(), #{})},
{reuseaddr, boolean()}, {reuseaddr, boolean()},
%% TODO: duri
{send_timeout, binary()}, {send_timeout, binary()},
{send_timeout_close, boolean()} {send_timeout_close, boolean()}
]; ];
fields(ssl_listener_opts) -> fields(ssl_listener_opts) ->
%% TODO: maybe use better ssl options schema from emqx_ssl_lib or somewhere
[ [
{cacertfile, binary()}, {cacertfile, binary()},
{certfile, binary()}, {certfile, binary()},
@ -762,7 +764,7 @@ common_listener_opts() ->
required => false, required => false,
desc => desc =>
<< <<
"The Mounpoint for clients of the listener. " "The Mountpoint for clients of the listener. "
"The gateway-level mountpoint configuration can be overloaded " "The gateway-level mountpoint configuration can be overloaded "
"when it is not null or empty string" "when it is not null or empty string"
>> >>
@ -774,7 +776,7 @@ common_listener_opts() ->
emqx_authn_schema:authenticator_type(), emqx_authn_schema:authenticator_type(),
#{ #{
required => {false, recursively}, required => {false, recursively},
desc => <<"The authenticatior for this listener">> desc => <<"The authenticator for this listener">>
} }
)} )}
] ++ emqx_gateway_schema:proxy_protocol_opts(). ] ++ emqx_gateway_schema:proxy_protocol_opts().

View File

@ -28,9 +28,9 @@
-include_lib("typerefl/include/types.hrl"). -include_lib("typerefl/include/types.hrl").
-type ip_port() :: tuple(). -type ip_port() :: tuple().
-type duration() :: integer(). -type duration() :: non_neg_integer().
-type duration_s() :: integer(). -type duration_s() :: non_neg_integer().
-type bytesize() :: integer(). -type bytesize() :: pos_integer().
-type comma_separated_list() :: list(). -type comma_separated_list() :: list().
-typerefl_from_string({ip_port/0, emqx_schema, to_ip_port}). -typerefl_from_string({ip_port/0, emqx_schema, to_ip_port}).
@ -117,7 +117,7 @@ fields(stomp_frame) ->
[ [
{max_headers, {max_headers,
sc( sc(
integer(), non_neg_integer(),
#{ #{
default => 10, default => 10,
desc => "The maximum number of Header" desc => "The maximum number of Header"
@ -125,7 +125,7 @@ fields(stomp_frame) ->
)}, )},
{max_headers_length, {max_headers_length,
sc( sc(
integer(), non_neg_integer(),
#{ #{
default => 1024, default => 1024,
desc => "The maximum string length of the Header Value" desc => "The maximum string length of the Header Value"

View File

@ -264,4 +264,4 @@ properties() ->
]. ].
m(K, Desc) -> m(K, Desc) ->
{K, mk(integer(), #{desc => Desc})}. {K, mk(non_neg_integer(), #{desc => Desc})}.

View File

@ -63,72 +63,29 @@ fields(aggregate) ->
, example => false})} , example => false})}
]; ];
fields(node_stats_data) -> fields(node_stats_data) ->
[ { 'channels.count' [
, mk( integer(), #{ desc => <<"sessions.count">> stats_schema('channels.count', <<"sessions.count">>),
, example => 0})} stats_schema('channels.max', <<"session.max">>),
, { 'channels.max' stats_schema('connections.count', <<"Number of current connections">>),
, mk( integer(), #{ desc => <<"session.max">> stats_schema('connections.max', <<"Historical maximum number of connections">>),
, example => 0})} stats_schema('delayed.count', <<"Number of delayed messages">>),
, { 'connections.count' stats_schema('delayed.max', <<"Historical maximum number of delayed messages">>),
, mk( integer(), #{ desc => <<"Number of current connections">> stats_schema('live_connections.count', <<"Number of current live connections">>),
, example => 0})} stats_schema('live_connections.max', <<"Historical maximum number of live connections">>),
, { 'connections.max' stats_schema('retained.count', <<"Number of currently retained messages">>),
, mk( integer(), #{ desc => <<"Historical maximum number of connections">> stats_schema('retained.max', <<"Historical maximum number of retained messages">>),
, example => 0})} stats_schema('sessions.count', <<"Number of current sessions">>),
, { 'delayed.count' stats_schema('sessions.max', <<"Historical maximum number of sessions">>),
, mk( integer(), #{ desc => <<"Number of delayed messages">> stats_schema('suboptions.count', <<"subscriptions.count">>),
, example => 0})} stats_schema('suboptions.max', <<"subscriptions.max">>),
, { 'delayed.max' stats_schema('subscribers.count', <<"Number of current subscribers">>),
, mk( integer(), #{ desc => <<"Historical maximum number of delayed messages">> stats_schema('subscribers.max', <<"Historical maximum number of subscribers">>),
, example => 0})} stats_schema('subscriptions.count', <<"Number of current subscriptions, including shared subscriptions">>),
, { 'live_connections.count' stats_schema('subscriptions.max', <<"Historical maximum number of subscriptions">>),
, mk( integer(), #{ desc => <<"Number of current live connections">> stats_schema('subscriptions.shared.count', <<"Number of current shared subscriptions">>),
, example => 0})} stats_schema('subscriptions.shared.max', <<"Historical maximum number of shared subscriptions">>),
, { 'live_connections.max' stats_schema('topics.count', <<"Number of current topics">>),
, mk( integer(), #{ desc => <<"Historical maximum number of live connections">> stats_schema('topics.max', <<"Historical maximum number of topics">>)
, example => 0})}
, { 'retained.count'
, mk( integer(), #{ desc => <<"Number of currently retained messages">>
, example => 0})}
, { 'retained.max'
, mk( integer(), #{ desc => <<"Historical maximum number of retained messages">>
, example => 0})}
, { 'sessions.count'
, mk( integer(), #{ desc => <<"Number of current sessions">>
, example => 0})}
, { 'sessions.max'
, mk( integer(), #{ desc => <<"Historical maximum number of sessions">>
, example => 0})}
, { 'suboptions.count'
, mk( integer(), #{ desc => <<"subscriptions.count">>
, example => 0})}
, { 'suboptions.max'
, mk( integer(), #{ desc => <<"subscriptions.max">>
, example => 0})}
, { 'subscribers.count'
, mk( integer(), #{ desc => <<"Number of current subscribers">>
, example => 0})}
, { 'subscribers.max'
, mk( integer(), #{ desc => <<"Historical maximum number of subscribers">>
, example => 0})}
, { 'subscriptions.count'
, mk( integer(), #{ desc => <<"Number of current subscriptions, including shared subscriptions">>
, example => 0})}
, { 'subscriptions.max'
, mk( integer(), #{ desc => <<"Historical maximum number of subscriptions">>
, example => 0})}
, { 'subscriptions.shared.count'
, mk( integer(), #{ desc => <<"Number of current shared subscriptions">>
, example => 0})}
, { 'subscriptions.shared.max'
, mk( integer(), #{ desc => <<"Historical maximum number of shared subscriptions">>
, example => 0})}
, { 'topics.count'
, mk( integer(), #{ desc => <<"Number of current topics">>
, example => 0})}
, { 'topics.max'
, mk( integer(), #{ desc => <<"Historical maximum number of topics">>
, example => 0})}
]; ];
fields(aggergate_data) -> fields(aggergate_data) ->
[ { node [ { node
@ -136,6 +93,8 @@ fields(aggergate_data) ->
, example => <<"emqx@127.0.0.1">>})} , example => <<"emqx@127.0.0.1">>})}
] ++ fields(node_stats_data). ] ++ fields(node_stats_data).
stats_schema(Name, Desc) ->
{Name, mk(non_neg_integer(), #{desc => Desc, example => 0})}.
%%%============================================================================================== %%%==============================================================================================
%% api apply %% api apply

View File

@ -163,11 +163,11 @@ fields("message_without_payload") ->
{msgid, mk(integer(), #{desc => <<"Message Id (MQTT message id hash)">>})}, {msgid, mk(integer(), #{desc => <<"Message Id (MQTT message id hash)">>})},
{node, mk(binary(), #{desc => <<"The node where message from">>})}, {node, mk(binary(), #{desc => <<"The node where message from">>})},
{publish_at, mk(binary(), #{desc => <<"Client publish message time, rfc 3339">>})}, {publish_at, mk(binary(), #{desc => <<"Client publish message time, rfc 3339">>})},
{delayed_interval, mk(integer(), #{desc => <<"Delayed interval, second">>})}, {delayed_interval, mk(pos_integer(), #{desc => <<"Delayed interval, second">>})},
{delayed_remaining, mk(integer(), #{desc => <<"Delayed remaining, second">>})}, {delayed_remaining, mk(non_neg_integer(), #{desc => <<"Delayed remaining, second">>})},
{expected_at, mk(binary(), #{desc => <<"Expect publish time, rfc 3339">>})}, {expected_at, mk(binary(), #{desc => <<"Expect publish time, rfc 3339">>})},
{topic, mk(binary(), #{desc => <<"Topic">>, example => <<"/sys/#">>})}, {topic, mk(binary(), #{desc => <<"Topic">>, example => <<"/sys/#">>})},
{qos, mk(binary(), #{desc => <<"QoS">>})}, {qos, mk(emqx_schema:qos(), #{desc => <<"QoS">>})},
{from_clientid, mk(binary(), #{desc => <<"From ClientId">>})}, {from_clientid, mk(binary(), #{desc => <<"From ClientId">>})},
{from_username, mk(binary(), #{desc => <<"From Username">>})} {from_username, mk(binary(), #{desc => <<"From Username">>})}
]; ];

View File

@ -53,7 +53,7 @@ fields("rule_info") ->
})} })}
] ++ fields("rule_creation"); ] ++ fields("rule_creation");
%% TODO: we can delete this API if the Dashboard not denpends on it %% TODO: we can delete this API if the Dashboard not depends on it
fields("rule_events") -> fields("rule_events") ->
ETopics = [binary_to_atom(emqx_rule_events:event_topic(E)) || E <- emqx_rule_events:event_names()], ETopics = [binary_to_atom(emqx_rule_events:event_topic(E)) || E <- emqx_rule_events:event_names()],
[ {"event", sc(hoconsc:enum(ETopics), #{desc => "The event topics", required => true})} [ {"event", sc(hoconsc:enum(ETopics), #{desc => "The event topics", required => true})}
@ -83,39 +83,39 @@ fields("rule_test") ->
]; ];
fields("metrics") -> fields("metrics") ->
[ {"sql.matched", sc(integer(), #{ [ {"sql.matched", sc(non_neg_integer(), #{
desc => "How much times the FROM clause of the SQL is matched." desc => "How much times the FROM clause of the SQL is matched."
})} })}
, {"sql.matched.rate", sc(float(), #{desc => "The rate of matched, times/second"})} , {"sql.matched.rate", sc(float(), #{desc => "The rate of matched, times/second"})}
, {"sql.matched.rate.max", sc(float(), #{desc => "The max rate of matched, times/second"})} , {"sql.matched.rate.max", sc(float(), #{desc => "The max rate of matched, times/second"})}
, {"sql.matched.rate.last5m", sc(float(), , {"sql.matched.rate.last5m", sc(float(),
#{desc => "The average rate of matched in last 5 minutes, times/second"})} #{desc => "The average rate of matched in last 5 minutes, times/second"})}
, {"sql.passed", sc(integer(), #{desc => "How much times the SQL is passed"})} , {"sql.passed", sc(non_neg_integer(), #{desc => "How much times the SQL is passed"})}
, {"sql.failed", sc(integer(), #{desc => "How much times the SQL is failed"})} , {"sql.failed", sc(non_neg_integer(), #{desc => "How much times the SQL is failed"})}
, {"sql.failed.exception", sc(integer(), #{ , {"sql.failed.exception", sc(non_neg_integer(), #{
desc => "How much times the SQL is failed due to exceptions. " desc => "How much times the SQL is failed due to exceptions. "
"This may because of a crash when calling a SQL function, or " "This may because of a crash when calling a SQL function, or "
"trying to do arithmetic operation on undefined variables" "trying to do arithmetic operation on undefined variables"
})} })}
, {"sql.failed.unknown", sc(integer(), #{ , {"sql.failed.unknown", sc(non_neg_integer(), #{
desc => "How much times the SQL is failed due to an unknown error." desc => "How much times the SQL is failed due to an unknown error."
})} })}
, {"outputs.total", sc(integer(), #{ , {"outputs.total", sc(non_neg_integer(), #{
desc => "How much times the outputs are called by the rule. " desc => "How much times the outputs are called by the rule. "
"This value may several times of 'sql.matched', depending on the " "This value may several times of 'sql.matched', depending on the "
"number of the outputs of the rule." "number of the outputs of the rule."
})} })}
, {"outputs.success", sc(integer(), #{ , {"outputs.success", sc(non_neg_integer(), #{
desc => "How much times the rule success to call the outputs." desc => "How much times the rule success to call the outputs."
})} })}
, {"outputs.failed", sc(integer(), #{ , {"outputs.failed", sc(non_neg_integer(), #{
desc => "How much times the rule failed to call the outputs." desc => "How much times the rule failed to call the outputs."
})} })}
, {"outputs.failed.out_of_service", sc(integer(), #{ , {"outputs.failed.out_of_service", sc(non_neg_integer(), #{
desc => "How much times the rule failed to call outputs due to the output is " desc => "How much times the rule failed to call outputs due to the output is "
"out of service. For example, a bridge is disabled or stopped." "out of service. For example, a bridge is disabled or stopped."
})} })}
, {"outputs.failed.unknown", sc(integer(), #{ , {"outputs.failed.unknown", sc(non_neg_integer(), #{
desc => "How much times the rule failed to call outputs due to to an unknown error." desc => "How much times the rule failed to call outputs due to to an unknown error."
})} })}
]; ];

View File

@ -19,7 +19,7 @@ fields("slow_subs") ->
"300s", "300s",
"The eviction time of the record, which in the statistics record table.")} "The eviction time of the record, which in the statistics record table.")}
, {top_k_num, , {top_k_num,
sc(integer(), sc(pos_integer(),
10, 10,
"The maximum number of records in the slow subscription statistics record table.")} "The maximum number of records in the slow subscription statistics record table.")}
, {stats_type, , {stats_type,