Merge pull request #11438 from zhongwencool/max-packet-size-validate

feat: change mqtt.max_packet_size type from string to bytesize
This commit is contained in:
zhongwencool 2023-08-14 20:31:25 +08:00 committed by GitHub
commit b2d5bae7c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 12 deletions

View File

@ -46,7 +46,6 @@
-type timeout_duration_s() :: 0..?MAX_INT_TIMEOUT_S. -type timeout_duration_s() :: 0..?MAX_INT_TIMEOUT_S.
-type timeout_duration_ms() :: 0..?MAX_INT_TIMEOUT_MS. -type timeout_duration_ms() :: 0..?MAX_INT_TIMEOUT_MS.
-type bytesize() :: integer(). -type bytesize() :: integer().
-type mqtt_max_packet_size() :: 1..?MAX_INT_MQTT_PACKET_SIZE.
-type wordsize() :: bytesize(). -type wordsize() :: bytesize().
-type percent() :: float(). -type percent() :: float().
-type file() :: string(). -type file() :: string().
@ -73,7 +72,6 @@
-typerefl_from_string({timeout_duration_s/0, emqx_schema, to_timeout_duration_s}). -typerefl_from_string({timeout_duration_s/0, emqx_schema, to_timeout_duration_s}).
-typerefl_from_string({timeout_duration_ms/0, emqx_schema, to_timeout_duration_ms}). -typerefl_from_string({timeout_duration_ms/0, emqx_schema, to_timeout_duration_ms}).
-typerefl_from_string({bytesize/0, emqx_schema, to_bytesize}). -typerefl_from_string({bytesize/0, emqx_schema, to_bytesize}).
-typerefl_from_string({mqtt_max_packet_size/0, emqx_schema, to_bytesize}).
-typerefl_from_string({wordsize/0, emqx_schema, to_wordsize}). -typerefl_from_string({wordsize/0, emqx_schema, to_wordsize}).
-typerefl_from_string({percent/0, emqx_schema, to_percent}). -typerefl_from_string({percent/0, emqx_schema, to_percent}).
-typerefl_from_string({comma_separated_list/0, emqx_schema, to_comma_separated_list}). -typerefl_from_string({comma_separated_list/0, emqx_schema, to_comma_separated_list}).
@ -93,6 +91,7 @@
-export([ -export([
validate_heap_size/1, validate_heap_size/1,
validate_packet_size/1,
user_lookup_fun_tr/2, user_lookup_fun_tr/2,
validate_alarm_actions/1, validate_alarm_actions/1,
validate_keepalive_multiplier/1, validate_keepalive_multiplier/1,
@ -154,7 +153,6 @@
timeout_duration_s/0, timeout_duration_s/0,
timeout_duration_ms/0, timeout_duration_ms/0,
bytesize/0, bytesize/0,
mqtt_max_packet_size/0,
wordsize/0, wordsize/0,
percent/0, percent/0,
file/0, file/0,
@ -2618,6 +2616,16 @@ validate_heap_size(Siz) when is_integer(Siz) ->
validate_heap_size(_SizStr) -> validate_heap_size(_SizStr) ->
{error, invalid_heap_size}. {error, invalid_heap_size}.
validate_packet_size(Siz) when is_integer(Siz) andalso Siz < 1 ->
{error, #{reason => max_mqtt_packet_size_too_small, minimum => 1}};
validate_packet_size(Siz) when is_integer(Siz) andalso Siz > ?MAX_INT_MQTT_PACKET_SIZE ->
Max = integer_to_list(round(?MAX_INT_MQTT_PACKET_SIZE / 1024 / 1024)) ++ "M",
{error, #{reason => max_mqtt_packet_size_too_large, maximum => Max}};
validate_packet_size(Siz) when is_integer(Siz) ->
ok;
validate_packet_size(_SizStr) ->
{error, invalid_packet_size}.
validate_keepalive_multiplier(Multiplier) when validate_keepalive_multiplier(Multiplier) when
is_number(Multiplier) andalso Multiplier >= 1.0 andalso Multiplier =< 65535.0 is_number(Multiplier) andalso Multiplier >= 1.0 andalso Multiplier =< 65535.0
-> ->
@ -3380,9 +3388,10 @@ mqtt_general() ->
)}, )},
{"max_packet_size", {"max_packet_size",
sc( sc(
mqtt_max_packet_size(), bytesize(),
#{ #{
default => <<"1MB">>, default => <<"1MB">>,
validator => fun ?MODULE:validate_packet_size/1,
desc => ?DESC(mqtt_max_packet_size) desc => ?DESC(mqtt_max_packet_size)
} }
)}, )},

View File

@ -2,7 +2,7 @@
{application, emqx_dashboard, [ {application, emqx_dashboard, [
{description, "EMQX Web Dashboard"}, {description, "EMQX Web Dashboard"},
% strict semver, bump manually! % strict semver, bump manually!
{vsn, "5.0.25"}, {vsn, "5.0.26"},
{modules, []}, {modules, []},
{registered, [emqx_dashboard_sup]}, {registered, [emqx_dashboard_sup]},
{applications, [kernel, stdlib, mnesia, minirest, emqx, emqx_ctl, emqx_bridge_http]}, {applications, [kernel, stdlib, mnesia, minirest, emqx, emqx_ctl, emqx_bridge_http]},
@ -12,6 +12,6 @@
{maintainers, ["EMQX Team <contact@emqx.io>"]}, {maintainers, ["EMQX Team <contact@emqx.io>"]},
{links, [ {links, [
{"Homepage", "https://emqx.io/"}, {"Homepage", "https://emqx.io/"},
{"Github", "https://github.com/emqx/emqx-dashboard"} {"Github", "https://github.com/emqx/emqx-dashboard5"}
]} ]}
]}. ]}.

View File

@ -856,8 +856,6 @@ typename_to_spec("timeout()", _Mod) ->
}; };
typename_to_spec("bytesize()", _Mod) -> typename_to_spec("bytesize()", _Mod) ->
#{type => string, example => <<"32MB">>}; #{type => string, example => <<"32MB">>};
typename_to_spec("mqtt_max_packet_size()", _Mod) ->
#{type => string, example => <<"32MB">>};
typename_to_spec("wordsize()", _Mod) -> typename_to_spec("wordsize()", _Mod) ->
#{type => string, example => <<"1024KB">>}; #{type => string, example => <<"1024KB">>};
typename_to_spec("map()", _Mod) -> typename_to_spec("map()", _Mod) ->

View File

@ -1,6 +1,6 @@
{application, emqx_opentelemetry, [ {application, emqx_opentelemetry, [
{description, "OpenTelemetry for EMQX Broker"}, {description, "OpenTelemetry for EMQX Broker"},
{vsn, "0.1.0"}, {vsn, "0.1.1"},
{registered, []}, {registered, []},
{mod, {emqx_otel_app, []}}, {mod, {emqx_otel_app, []}},
{applications, [kernel, stdlib, emqx]}, {applications, [kernel, stdlib, emqx]},

View File

@ -150,9 +150,9 @@ get_vm_gauge(Name) ->
[{emqx_mgmt:vm_stats(Name), #{}}]. [{emqx_mgmt:vm_stats(Name), #{}}].
get_cluster_gauge('node.running') -> get_cluster_gauge('node.running') ->
length(emqx:cluster_nodes(running)); [{length(emqx:cluster_nodes(running)), #{}}];
get_cluster_gauge('node.stopped') -> get_cluster_gauge('node.stopped') ->
length(emqx:cluster_nodes(stopped)). [{length(emqx:cluster_nodes(stopped)), #{}}].
get_metric_counter(Name) -> get_metric_counter(Name) ->
[{emqx_metrics:val(Name), #{}}]. [{emqx_metrics:val(Name), #{}}].

View File

@ -0,0 +1,2 @@
Changed the type of the `mqtt.mqx_packet_size` from string to byteSize to better represent the valid numeric range.
Strings will still be accepted for backwards compatibility.

View File

@ -1369,7 +1369,7 @@ sysmon_vm_process_low_watermark.label:
"""Process low watermark""" """Process low watermark"""
mqtt_max_packet_size.desc: mqtt_max_packet_size.desc:
"""Maximum MQTT packet size allowed.""" """Maximum MQTT packet size allowed. Default: 1 MB, Maximum: 256 MB"""
mqtt_max_packet_size.label: mqtt_max_packet_size.label:
"""Max Packet Size""" """Max Packet Size"""