Merge pull request #8314 from lafirest/feat/exhook_tcp_opts

Feat/exhook tcp opts
This commit is contained in:
JianBo He 2022-06-27 11:26:02 +08:00 committed by GitHub
commit 08976c6946
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 8 deletions

View File

@ -47,3 +47,20 @@ exhook.server.default.url = http://127.0.0.1:9000
#exhook.server.default.ssl.cacertfile = {{ platform_etc_dir }}/certs/cacert.pem #exhook.server.default.ssl.cacertfile = {{ platform_etc_dir }}/certs/cacert.pem
#exhook.server.default.ssl.certfile = {{ platform_etc_dir }}/certs/cert.pem #exhook.server.default.ssl.certfile = {{ platform_etc_dir }}/certs/cert.pem
#exhook.server.default.ssl.keyfile = {{ platform_etc_dir }}/certs/key.pem #exhook.server.default.ssl.keyfile = {{ platform_etc_dir }}/certs/key.pem
## Enables/disables periodic transmission on a connected socket when no other data is exchanged.
## If the other end does not respond, the connection is considered broken and an error message is sent to the controlling process.
##
## Default: true
#exhook.server.default.socket_options.keepalive = true
## If true, option TCP_NODELAY is turned on for the socket, which means that also small amounts of data are sent immediately.
##
## Default: true
#exhook.server.default.socket_options.nodelay = true
## The minimum size of the receive buffer to use for the socket.
#exhook.server.default.socket_options.recbuf = 64KB
## The minimum size of the send buffer to use for the socket.
#exhook.server.default.socket_options.sndbuf = 16KB

View File

@ -47,12 +47,42 @@ end}.
{datatype, string} {datatype, string}
]}. ]}.
{mapping, "exhook.server.$name.socket_options.keepalive", "emqx_exhook.servers", [
{default, true},
{datatype, {enum, [true, false]}}
]}.
{mapping, "exhook.server.$name.socket_options.nodelay", "emqx_exhook.servers", [
{default, true},
{datatype, {enum, [true, false]}}
]}.
{mapping, "exhook.server.$name.socket_options.recbuf", "emqx_exhook.servers", [
{datatype, bytesize}
]}.
{mapping, "exhook.server.$name.socket_options.sndbuf", "emqx_exhook.servers", [
{datatype, bytesize}
]}.
{translation, "emqx_exhook.servers", fun(Conf) -> {translation, "emqx_exhook.servers", fun(Conf) ->
Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end, Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end,
MkSockOpts = fun(Prefix, Conf) ->
{socket_options,
Filter([{Opt,
cuttlefish:conf_get(Prefix ++ ".socket_options." ++ atom_to_list(Opt),
Conf,
undefined)}
|| Opt <- [keepalive, nodelay, recbuf, sndbuf]])}
end,
ServerOptions = fun(Prefix) -> ServerOptions = fun(Prefix) ->
case http_uri:parse(cuttlefish:conf_get(Prefix ++ ".url", Conf)) of case http_uri:parse(cuttlefish:conf_get(Prefix ++ ".url", Conf)) of
{ok, {http, _, Host, Port, _, _}} -> {ok, {http, _, Host, Port, _, _}} ->
[{scheme, http}, {host, Host}, {port, Port}]; [{scheme, http}, {host, Host}, {port, Port},
MkSockOpts(Prefix, Conf)
];
{ok, {https, _, Host, Port, _, _}} -> {ok, {https, _, Host, Port, _, _}} ->
[{scheme, https}, {host, Host}, {port, Port}, [{scheme, https}, {host, Host}, {port, Port},
{ssl_options, {ssl_options,
@ -60,10 +90,13 @@ end}.
{certfile, cuttlefish:conf_get(Prefix ++ ".ssl.certfile", Conf, undefined)}, {certfile, cuttlefish:conf_get(Prefix ++ ".ssl.certfile", Conf, undefined)},
{keyfile, cuttlefish:conf_get(Prefix ++ ".ssl.keyfile", Conf, undefined)}, {keyfile, cuttlefish:conf_get(Prefix ++ ".ssl.keyfile", Conf, undefined)},
{cacertfile, cuttlefish:conf_get(Prefix ++ ".ssl.cacertfile", Conf, undefined)} {cacertfile, cuttlefish:conf_get(Prefix ++ ".ssl.cacertfile", Conf, undefined)}
])}]; ])},
MkSockOpts(Prefix, Conf)
];
_ -> error(invalid_server_options) _ -> error(invalid_server_options)
end end
end, end,
[{list_to_atom(Name), ServerOptions("exhook.server." ++ Name)} [{list_to_atom(Name), ServerOptions("exhook.server." ++ Name)}
|| {["exhook", "server", Name, "url"], _} <- cuttlefish_variable:filter_by_prefix("exhook.server", Conf)] || {["exhook", "server", Name, "url"], _} <- cuttlefish_variable:filter_by_prefix("exhook.server", Conf)]
end}. end}.

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{application, emqx_exhook, {application, emqx_exhook,
[{description, "EMQ X Extension for Hook"}, [{description, "EMQ X Extension for Hook"},
{vsn, "4.3.5"}, {vsn, "4.3.6"},
{modules, []}, {modules, []},
{registered, []}, {registered, []},
{mod, {emqx_exhook_app, []}}, {mod, {emqx_exhook_app, []}},

View File

@ -1,6 +1,8 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{VSN, {VSN,
[ [ {"4.3.5", [
{load_module, emqx_exhook_server, brutal_purge, soft_purge, []}
]},
{"4.3.4", [ {"4.3.4", [
{load_module, emqx_exhook_sup, brutal_purge, soft_purge, []}, {load_module, emqx_exhook_sup, brutal_purge, soft_purge, []},
{load_module, emqx_exhook_server, brutal_purge, soft_purge, []}, {load_module, emqx_exhook_server, brutal_purge, soft_purge, []},
@ -14,7 +16,9 @@
]}, ]},
{<<".*">>, []} {<<".*">>, []}
], ],
[ [ {"4.3.5", [
{load_module, emqx_exhook_server, brutal_purge, soft_purge, []}
]},
{"4.3.4", [ {"4.3.4", [
{load_module, emqx_exhook_sup, brutal_purge, soft_purge, []}, {load_module, emqx_exhook_sup, brutal_purge, soft_purge, []},
{load_module, emqx_exhook_server, brutal_purge, soft_purge, []}, {load_module, emqx_exhook_server, brutal_purge, soft_purge, []},

View File

@ -124,13 +124,16 @@ channel_opts(Opts) ->
Host = proplists:get_value(host, Opts), Host = proplists:get_value(host, Opts),
Port = proplists:get_value(port, Opts), Port = proplists:get_value(port, Opts),
SvrAddr = format_http_uri(Scheme, Host, Port), SvrAddr = format_http_uri(Scheme, Host, Port),
SockOpts = proplists:get_value(socket_options, Opts),
ClientOpts = case Scheme of ClientOpts = case Scheme of
https -> https ->
SslOpts = lists:keydelete(ssl, 1, proplists:get_value(ssl_options, Opts, [])), SslOpts = lists:keydelete(ssl, 1, proplists:get_value(ssl_options, Opts, [])),
#{gun_opts => #{gun_opts =>
#{transport => ssl, #{transport => ssl,
transport_opts => SslOpts}}; transport_opts => SockOpts ++ SslOpts}};
_ -> #{} _ ->
#{gun_opts =>
#{transport_opts => SockOpts}}
end, end,
{SvrAddr, ClientOpts}. {SvrAddr, ClientOpts}.

View File

@ -46,7 +46,8 @@ set_special_cfgs(emqx) ->
application:set_env(emqx, allow_anonymous, false), application:set_env(emqx, allow_anonymous, false),
application:set_env(emqx, enable_acl_cache, false), application:set_env(emqx, enable_acl_cache, false),
application:set_env(emqx, plugins_loaded_file, undefined), application:set_env(emqx, plugins_loaded_file, undefined),
application:set_env(emqx, modules_loaded_file, undefined); application:set_env(emqx, modules_loaded_file, undefined),
application:set_env(ekka, cluster_name, ?OTHER_CLUSTER_NAME_ATOM);
set_special_cfgs(emqx_exhook) -> set_special_cfgs(emqx_exhook) ->
ok. ok.