improve: rename quota option name

This commit is contained in:
JianBo He 2020-09-02 15:19:59 +08:00 committed by tigercl
parent 4233ef4e85
commit f6b35d63f2
2 changed files with 32 additions and 28 deletions

View File

@ -863,25 +863,29 @@ zone.external.enable_flapping_detect = off
##
## Value: Number,Duration
## Example: 100 messages per 10 seconds.
#zone.external.rate_limit.conn_messages_in = 100, 10s
#zone.external.rate_limit.conn_messages_in = 100,10s
## Bytes limit for a external MQTT connections.
##
## Value: Number,Duration
## Example: 100KB incoming per 10 seconds.
#zone.external.rate_limit.conn_bytes_in = 100KB, 10s
#zone.external.rate_limit.conn_bytes_in = 100KB,10s
## Messages quota for the external MQTT connections. This value
## consumed by the number of PUBLISH message forwarding times.
##
## This option allows you to configure up to 2 parameters that are split by '|'.
## The former represents the quota per connection, while the latter represents
## the quota for all external zone's connections.
## Messages quota for the each of external MQTT connection.
## This value consumed by the number of recipient on a message.
##
## Value: Number, Duration
##
## Example: 100 messaegs per 1s and 200000 messages per 1s in zone
#zone.external.quota.routing.messages = 100,1s | 200000,1s
## Example: 100 messaegs per 1s
#zone.external.quota.conn_messages_routing = 100,1s
## Messages quota for the all of external MQTT connections.
## This value consumed by the number of recipient on a message.
##
## Value: Number, Duration
##
## Example: 200000 messaegs per 1s
#zone.external.quota.overall_messages_routing = 200000,1s
## All the topics will be prefixed with the mountpoint path if this option is enabled.
##

View File

@ -997,15 +997,19 @@ end}.
{default, off}
]}.
{mapping, "zone.$name.rate_limit.messages_in", "emqx.zones", [
{mapping, "zone.$name.rate_limit.conn_messages_in", "emqx.zones", [
{datatype, string}
]}.
{mapping, "zone.$name.rate_limit.bytes_in", "emqx.zones", [
{mapping, "zone.$name.rate_limit.conn_bytes_in", "emqx.zones", [
{datatype, string}
]}.
{mapping, "zone.$name.quota.routing.messages", "emqx.zones", [
{mapping, "zone.$name.quota.conn_messages_routing", "emqx.zones", [
{datatype, string}
]}.
{mapping, "zone.$name.quota.overall_messages_routing", "emqx.zones", [
{datatype, string}
]}.
@ -1118,15 +1122,10 @@ end}.
{ratelimit, {conn_messages_in, Ratelimit(Val)}};
(["rate_limit", "conn_bytes_in"], Val) ->
{ratelimit, {conn_bytes_in, Ratelimit(Val)}};
(["quota", "routing", "messages"], Val) ->
Policy = case string:tokens(Val, "|") of
[T] ->
[{conn_messages_routing, Ratelimit(T)}];
[T1, T2] ->
[{conn_messages_routing, Ratelimit(T1)},
{overall_messages_routing, Ratelimit(T2)}]
end,
{quota, Policy};
(["quota", "conn_messages_routing"], Val) ->
{quota, {conn_messages_routing, Ratelimit(Val)}};
(["quota", "overall_messages_routing"], Val) ->
{quota, {overall_messages_routing, Ratelimit(Val)}};
([Opt], Val) ->
{list_to_atom(Opt), Val}
end,
@ -1137,9 +1136,10 @@ end}.
maps:update_with(list_to_atom(Name),
fun(Opts) ->
case NVal of
{ratelimit, Rl} ->
Rls = proplists:get_value(ratelimit, Opts, []),
lists:keystore(ratelimit, 1, Opts, {ratelimit, [Rl|Rls]});
{Key, Rl} when Key == ratelimit;
Key == quota ->
Rls = proplists:get_value(Key, Opts, []),
lists:keystore(Key, 1, Opts, {Key, [Rl|Rls]});
_ ->
[NVal|Opts]
end