fix(limiter): move default connection setting into schema

This commit is contained in:
firest 2022-06-15 14:57:49 +08:00
parent fa99b65c91
commit c147743895
4 changed files with 17 additions and 19 deletions

View File

@ -1,13 +1,11 @@
listeners.tcp.default { listeners.tcp.default {
bind = "0.0.0.0:1883" bind = "0.0.0.0:1883"
max_connections = 1024000 max_connections = 1024000
limiter.connection = default
} }
listeners.ssl.default { listeners.ssl.default {
bind = "0.0.0.0:8883" bind = "0.0.0.0:8883"
max_connections = 512000 max_connections = 512000
limiter.connection = default
ssl_options { ssl_options {
keyfile = "{{ platform_etc_dir }}/certs/key.pem" keyfile = "{{ platform_etc_dir }}/certs/key.pem"
certfile = "{{ platform_etc_dir }}/certs/cert.pem" certfile = "{{ platform_etc_dir }}/certs/cert.pem"
@ -18,14 +16,12 @@ listeners.ssl.default {
listeners.ws.default { listeners.ws.default {
bind = "0.0.0.0:8083" bind = "0.0.0.0:8083"
max_connections = 1024000 max_connections = 1024000
limiter.connection = default
websocket.mqtt_path = "/mqtt" websocket.mqtt_path = "/mqtt"
} }
listeners.wss.default { listeners.wss.default {
bind = "0.0.0.0:8084" bind = "0.0.0.0:8084"
max_connections = 512000 max_connections = 512000
limiter.connection = default
websocket.mqtt_path = "/mqtt" websocket.mqtt_path = "/mqtt"
ssl_options { ssl_options {
keyfile = "{{ platform_etc_dir }}/certs/key.pem" keyfile = "{{ platform_etc_dir }}/certs/key.pem"
@ -38,7 +34,6 @@ listeners.wss.default {
# enabled = false # enabled = false
# bind = "0.0.0.0:14567" # bind = "0.0.0.0:14567"
# max_connections = 1024000 # max_connections = 1024000
# limiter.connection = default
# keyfile = "{{ platform_etc_dir }}/certs/key.pem" # keyfile = "{{ platform_etc_dir }}/certs/key.pem"
# certfile = "{{ platform_etc_dir }}/certs/cert.pem" # certfile = "{{ platform_etc_dir }}/certs/cert.pem"
#} #}

View File

@ -1,11 +0,0 @@
limiter {
connection {
rate = "1000/s"
bucket {
default {
rate = "1000/s"
capacity = 1000
}
}
}
}

View File

@ -31,7 +31,7 @@
get_bucket_cfg_path/2, get_bucket_cfg_path/2,
desc/1, desc/1,
types/0, types/0,
infinity_value/0, infinity_value/0
]). ]).
-define(KILOBYTE, 1024). -define(KILOBYTE, 1024).
@ -89,7 +89,7 @@ fields(limiter) ->
{Type, {Type,
?HOCON(?R_REF(limiter_opts), #{ ?HOCON(?R_REF(limiter_opts), #{
desc => ?DESC(Type), desc => ?DESC(Type),
default => #{} default => make_limiter_default(Type)
})} })}
|| Type <- types() || Type <- types()
]; ];
@ -321,3 +321,17 @@ apply_unit("kb", Val) -> Val * ?KILOBYTE;
apply_unit("mb", Val) -> Val * ?KILOBYTE * ?KILOBYTE; apply_unit("mb", Val) -> Val * ?KILOBYTE * ?KILOBYTE;
apply_unit("gb", Val) -> Val * ?KILOBYTE * ?KILOBYTE * ?KILOBYTE; apply_unit("gb", Val) -> Val * ?KILOBYTE * ?KILOBYTE * ?KILOBYTE;
apply_unit(Unit, _) -> throw("invalid unit:" ++ Unit). apply_unit(Unit, _) -> throw("invalid unit:" ++ Unit).
make_limiter_default(connection) ->
#{
<<"rate">> => <<"1000/s">>,
<<"bucket">> => #{
<<"default">> =>
#{
<<"rate">> => <<"1000/s">>,
<<"capacity">> => 1000
}
}
};
make_limiter_default(_) ->
#{}.

View File

@ -1613,7 +1613,7 @@ base_listener(Bind) ->
map("ratelimit_name", emqx_limiter_schema:bucket_name()), map("ratelimit_name", emqx_limiter_schema:bucket_name()),
#{ #{
desc => ?DESC(base_listener_limiter), desc => ?DESC(base_listener_limiter),
default => #{} default => #{<<"connection">> => <<"default">>}
} }
)} )}
]. ].