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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -163,11 +163,11 @@ fields("message_without_payload") ->
{msgid, mk(integer(), #{desc => <<"Message Id (MQTT message id hash)">>})},
{node, mk(binary(), #{desc => <<"The node where message from">>})},
{publish_at, mk(binary(), #{desc => <<"Client publish message time, rfc 3339">>})},
{delayed_interval, mk(integer(), #{desc => <<"Delayed interval, second">>})},
{delayed_remaining, mk(integer(), #{desc => <<"Delayed remaining, second">>})},
{delayed_interval, mk(pos_integer(), #{desc => <<"Delayed interval, second">>})},
{delayed_remaining, mk(non_neg_integer(), #{desc => <<"Delayed remaining, second">>})},
{expected_at, mk(binary(), #{desc => <<"Expect publish time, rfc 3339">>})},
{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_username, mk(binary(), #{desc => <<"From Username">>})}
];

View File

@ -53,7 +53,7 @@ fields("rule_info") ->
})}
] ++ 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") ->
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})}
@ -83,39 +83,39 @@ fields("rule_test") ->
];
fields("metrics") ->
[ {"sql.matched", sc(integer(), #{
[ {"sql.matched", sc(non_neg_integer(), #{
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.max", sc(float(), #{desc => "The max rate of matched, times/second"})}
, {"sql.matched.rate.last5m", sc(float(),
#{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.failed", sc(integer(), #{desc => "How much times the SQL is failed"})}
, {"sql.failed.exception", sc(integer(), #{
, {"sql.passed", sc(non_neg_integer(), #{desc => "How much times the SQL is passed"})}
, {"sql.failed", sc(non_neg_integer(), #{desc => "How much times the SQL is failed"})}
, {"sql.failed.exception", sc(non_neg_integer(), #{
desc => "How much times the SQL is failed due to exceptions. "
"This may because of a crash when calling a SQL function, or "
"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."
})}
, {"outputs.total", sc(integer(), #{
, {"outputs.total", sc(non_neg_integer(), #{
desc => "How much times the outputs are called by the rule. "
"This value may several times of 'sql.matched', depending on the "
"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."
})}
, {"outputs.failed", sc(integer(), #{
, {"outputs.failed", sc(non_neg_integer(), #{
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 "
"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."
})}
];

View File

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