Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change mqtt.max_packet_size type from string to bytesize #11438

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions apps/emqx/src/emqx_schema.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
-type timeout_duration_s() :: 0..?MAX_INT_TIMEOUT_S.
-type timeout_duration_ms() :: 0..?MAX_INT_TIMEOUT_MS.
-type bytesize() :: integer().
-type mqtt_max_packet_size() :: 1..?MAX_INT_MQTT_PACKET_SIZE.
-type wordsize() :: bytesize().
-type percent() :: float().
-type file() :: string().
Expand All @@ -73,7 +72,6 @@
-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({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({percent/0, emqx_schema, to_percent}).
-typerefl_from_string({comma_separated_list/0, emqx_schema, to_comma_separated_list}).
Expand All @@ -93,6 +91,7 @@

-export([
validate_heap_size/1,
validate_packet_size/1,
user_lookup_fun_tr/2,
validate_alarm_actions/1,
validate_keepalive_multiplier/1,
Expand Down Expand Up @@ -154,7 +153,6 @@
timeout_duration_s/0,
timeout_duration_ms/0,
bytesize/0,
mqtt_max_packet_size/0,
wordsize/0,
percent/0,
file/0,
Expand Down Expand Up @@ -2618,6 +2616,16 @@ validate_heap_size(Siz) when is_integer(Siz) ->
validate_heap_size(_SizStr) ->
{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
is_number(Multiplier) andalso Multiplier >= 1.0 andalso Multiplier =< 65535.0
->
Expand Down Expand Up @@ -3380,9 +3388,10 @@ mqtt_general() ->
)},
{"max_packet_size",
sc(
mqtt_max_packet_size(),
bytesize(),
#{
default => <<"1MB">>,
validator => fun ?MODULE:validate_packet_size/1,
desc => ?DESC(mqtt_max_packet_size)
}
)},
Expand Down
4 changes: 2 additions & 2 deletions apps/emqx_dashboard/src/emqx_dashboard.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{application, emqx_dashboard, [
{description, "EMQX Web Dashboard"},
% strict semver, bump manually!
{vsn, "5.0.25"},
{vsn, "5.0.26"},
{modules, []},
{registered, [emqx_dashboard_sup]},
{applications, [kernel, stdlib, mnesia, minirest, emqx, emqx_ctl, emqx_bridge_http]},
Expand All @@ -12,6 +12,6 @@
{maintainers, ["EMQX Team <contact@emqx.io>"]},
{links, [
{"Homepage", "https://emqx.io/"},
{"Github", "https://github.com/emqx/emqx-dashboard"}
{"Github", "https://github.com/emqx/emqx-dashboard5"}
]}
]}.
2 changes: 0 additions & 2 deletions apps/emqx_dashboard/src/emqx_dashboard_swagger.erl
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,6 @@ typename_to_spec("timeout()", _Mod) ->
};
typename_to_spec("bytesize()", _Mod) ->
#{type => string, example => <<"32MB">>};
typename_to_spec("mqtt_max_packet_size()", _Mod) ->
#{type => string, example => <<"32MB">>};
typename_to_spec("wordsize()", _Mod) ->
#{type => string, example => <<"1024KB">>};
typename_to_spec("map()", _Mod) ->
Expand Down
2 changes: 1 addition & 1 deletion apps/emqx_opentelemetry/src/emqx_opentelemetry.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, emqx_opentelemetry, [
{description, "OpenTelemetry for EMQX Broker"},
{vsn, "0.1.0"},
{vsn, "0.1.1"},
{registered, []},
{mod, {emqx_otel_app, []}},
{applications, [kernel, stdlib, emqx]},
Expand Down
4 changes: 2 additions & 2 deletions apps/emqx_opentelemetry/src/emqx_otel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ get_vm_gauge(Name) ->
[{emqx_mgmt:vm_stats(Name), #{}}].

get_cluster_gauge('node.running') ->
length(emqx:cluster_nodes(running));
[{length(emqx:cluster_nodes(running)), #{}}];
get_cluster_gauge('node.stopped') ->
length(emqx:cluster_nodes(stopped)).
[{length(emqx:cluster_nodes(stopped)), #{}}].

get_metric_counter(Name) ->
[{emqx_metrics:val(Name), #{}}].
Expand Down
2 changes: 2 additions & 0 deletions changes/ce/feat-11438.en.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion rel/i18n/emqx_schema.hocon
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ sysmon_vm_process_low_watermark.label:
"""Process low watermark"""

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:
"""Max Packet Size"""
Expand Down