feat: hide resource_opts's request_timeout
This commit is contained in:
parent
a2aa6b4666
commit
2b99a9b988
|
@ -892,11 +892,18 @@ fill_defaults(Type, RawConf) ->
|
||||||
pack_bridge_conf(Type, RawConf) ->
|
pack_bridge_conf(Type, RawConf) ->
|
||||||
#{<<"bridges">> => #{bin(Type) => #{<<"foo">> => RawConf}}}.
|
#{<<"bridges">> => #{bin(Type) => #{<<"foo">> => RawConf}}}.
|
||||||
|
|
||||||
unpack_bridge_conf(Type, PackedConf) ->
|
%% Hide webhook's resource_opts.request_timeout from user.
|
||||||
#{<<"bridges">> := Bridges} = PackedConf,
|
filter_raw_conf(<<"webhook">>, RawConf0) ->
|
||||||
#{<<"foo">> := RawConf} = maps:get(bin(Type), Bridges),
|
emqx_utils_maps:deep_remove([<<"resource_opts">>, <<"request_timeout">>], RawConf0);
|
||||||
|
filter_raw_conf(_TypeBin, RawConf) ->
|
||||||
RawConf.
|
RawConf.
|
||||||
|
|
||||||
|
unpack_bridge_conf(Type, PackedConf) ->
|
||||||
|
TypeBin = bin(Type),
|
||||||
|
#{<<"bridges">> := Bridges} = PackedConf,
|
||||||
|
#{<<"foo">> := RawConf} = maps:get(TypeBin, Bridges),
|
||||||
|
filter_raw_conf(TypeBin, RawConf).
|
||||||
|
|
||||||
is_ok(ok) ->
|
is_ok(ok) ->
|
||||||
ok;
|
ok;
|
||||||
is_ok(OkResult = {ok, _}) ->
|
is_ok(OkResult = {ok, _}) ->
|
||||||
|
|
|
@ -178,7 +178,7 @@ create(Type, Name, Conf, Opts) ->
|
||||||
<<"emqx_bridge">>,
|
<<"emqx_bridge">>,
|
||||||
bridge_to_resource_type(Type),
|
bridge_to_resource_type(Type),
|
||||||
parse_confs(TypeBin, Name, Conf),
|
parse_confs(TypeBin, Name, Conf),
|
||||||
parse_opts(TypeBin, Conf, Opts)
|
parse_opts(Conf, Opts)
|
||||||
),
|
),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ recreate(Type, Name, Conf, Opts) ->
|
||||||
resource_id(Type, Name),
|
resource_id(Type, Name),
|
||||||
bridge_to_resource_type(Type),
|
bridge_to_resource_type(Type),
|
||||||
parse_confs(TypeBin, Name, Conf),
|
parse_confs(TypeBin, Name, Conf),
|
||||||
parse_opts(TypeBin, Conf, Opts)
|
parse_opts(Conf, Opts)
|
||||||
).
|
).
|
||||||
|
|
||||||
create_dry_run(Type, Conf0) ->
|
create_dry_run(Type, Conf0) ->
|
||||||
|
@ -402,15 +402,8 @@ bin(Bin) when is_binary(Bin) -> Bin;
|
||||||
bin(Str) when is_list(Str) -> list_to_binary(Str);
|
bin(Str) when is_list(Str) -> list_to_binary(Str);
|
||||||
bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8).
|
bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8).
|
||||||
|
|
||||||
parse_opts(Type, Conf, Opts0) ->
|
parse_opts(Conf, Opts0) ->
|
||||||
Opts1 = override_start_after_created(Conf, Opts0),
|
override_start_after_created(Conf, Opts0).
|
||||||
override_resource_request_timeout(Type, Conf, Opts1).
|
|
||||||
|
|
||||||
%% Put webhook's http request_timeout into the resource options
|
|
||||||
override_resource_request_timeout(<<"webhook">>, #{request_timeout := ReqTimeout}, Opts) ->
|
|
||||||
Opts#{request_timeout => ReqTimeout};
|
|
||||||
override_resource_request_timeout(_Type, _Conf, Opts) ->
|
|
||||||
Opts.
|
|
||||||
|
|
||||||
override_start_after_created(Config, Opts) ->
|
override_start_after_created(Config, Opts) ->
|
||||||
Enabled = maps:get(enable, Config, true),
|
Enabled = maps:get(enable, Config, true),
|
||||||
|
|
|
@ -223,6 +223,25 @@ node_name() ->
|
||||||
{"node", mk(binary(), #{desc => ?DESC("desc_node_name"), example => "emqx@127.0.0.1"})}.
|
{"node", mk(binary(), #{desc => ?DESC("desc_node_name"), example => "emqx@127.0.0.1"})}.
|
||||||
|
|
||||||
webhook_bridge_converter(Conf0, _HoconOpts) ->
|
webhook_bridge_converter(Conf0, _HoconOpts) ->
|
||||||
emqx_bridge_compatible_config:upgrade_pre_ee(
|
Conf1 = emqx_bridge_compatible_config:upgrade_pre_ee(
|
||||||
Conf0, fun emqx_bridge_compatible_config:webhook_maybe_upgrade/1
|
Conf0, fun emqx_bridge_compatible_config:webhook_maybe_upgrade/1
|
||||||
).
|
),
|
||||||
|
case Conf1 of
|
||||||
|
undefined ->
|
||||||
|
undefined;
|
||||||
|
_ ->
|
||||||
|
maps:map(
|
||||||
|
fun(_Name, Conf) ->
|
||||||
|
do_convert_webhook_config(Conf)
|
||||||
|
end,
|
||||||
|
Conf1
|
||||||
|
)
|
||||||
|
end.
|
||||||
|
|
||||||
|
%% We hide resource_opts.request_timeout from user.
|
||||||
|
do_convert_webhook_config(
|
||||||
|
#{<<"request_timeout">> := ReqT, <<"resource_opts">> := ResOpts} = Conf
|
||||||
|
) ->
|
||||||
|
Conf#{<<"resource_opts">> => ResOpts#{<<"request_timeout">> => ReqT}};
|
||||||
|
do_convert_webhook_config(Conf) ->
|
||||||
|
Conf.
|
||||||
|
|
|
@ -41,7 +41,7 @@ fields("get") ->
|
||||||
emqx_bridge_schema:status_fields() ++ fields("post");
|
emqx_bridge_schema:status_fields() ++ fields("post");
|
||||||
fields("creation_opts") ->
|
fields("creation_opts") ->
|
||||||
[
|
[
|
||||||
deprecated_request_timeout()
|
hidden_request_timeout()
|
||||||
| lists:filter(
|
| lists:filter(
|
||||||
fun({K, _V}) ->
|
fun({K, _V}) ->
|
||||||
not lists:member(K, unsupported_opts())
|
not lists:member(K, unsupported_opts())
|
||||||
|
@ -195,12 +195,12 @@ name_field() ->
|
||||||
method() ->
|
method() ->
|
||||||
enum([post, put, get, delete]).
|
enum([post, put, get, delete]).
|
||||||
|
|
||||||
deprecated_request_timeout() ->
|
hidden_request_timeout() ->
|
||||||
{request_timeout,
|
{request_timeout,
|
||||||
mk(
|
mk(
|
||||||
hoconsc:union([infinity, emqx_schema:duration_ms()]),
|
hoconsc:union([infinity, emqx_schema:duration_ms()]),
|
||||||
#{
|
#{
|
||||||
default => <<"15s">>,
|
required => false,
|
||||||
deprecated => {since, "5.0.26"}
|
importance => ?IMPORTANCE_HIDDEN
|
||||||
}
|
}
|
||||||
)}.
|
)}.
|
||||||
|
|
|
@ -1295,8 +1295,32 @@ t_inconsistent_webhook_request_timeouts(Config) ->
|
||||||
Config
|
Config
|
||||||
),
|
),
|
||||||
?assertNot(maps:is_key(<<"request_timeout">>, ResourceOpts)),
|
?assertNot(maps:is_key(<<"request_timeout">>, ResourceOpts)),
|
||||||
|
validate_resource_request_timeout(proplists:get_value(group, Config), 1000, Name),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
validate_resource_request_timeout(single, Timeout, Name) ->
|
||||||
|
SentData = #{payload => <<"Hello EMQX">>, timestamp => 1668602148000},
|
||||||
|
BridgeID = emqx_bridge_resource:bridge_id(?BRIDGE_TYPE_HTTP, Name),
|
||||||
|
ResId = emqx_bridge_resource:resource_id(<<"webhook">>, Name),
|
||||||
|
?check_trace(
|
||||||
|
begin
|
||||||
|
{ok, Res} =
|
||||||
|
?wait_async_action(
|
||||||
|
emqx_bridge:send_message(BridgeID, SentData),
|
||||||
|
#{?snk_kind := async_query},
|
||||||
|
1000
|
||||||
|
),
|
||||||
|
?assertMatch({ok, #{id := ResId, query_opts := #{timeout := Timeout}}}, Res)
|
||||||
|
end,
|
||||||
|
fun(Trace0) ->
|
||||||
|
Trace = ?of_kind(async_query, Trace0),
|
||||||
|
?assertMatch([#{query_opts := #{timeout := Timeout}}], Trace),
|
||||||
|
ok
|
||||||
|
end
|
||||||
|
);
|
||||||
|
validate_resource_request_timeout(_Cluster, _Timeout, _Name) ->
|
||||||
|
ignore.
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
request(Method, URL, Config) ->
|
request(Method, URL, Config) ->
|
||||||
|
|
|
@ -73,7 +73,7 @@ webhook_config_test() ->
|
||||||
}
|
}
|
||||||
} = check(Conf3),
|
} = check(Conf3),
|
||||||
?assertEqual(60_000, RequestTime),
|
?assertEqual(60_000, RequestTime),
|
||||||
?assertNot(maps:is_key(<<"requst_timeout">>, ResourceOpts)),
|
?assertMatch(#{<<"request_timeout">> := 60_000}, ResourceOpts),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
up(#{<<"bridges">> := Bridges0} = Conf0) ->
|
up(#{<<"bridges">> := Bridges0} = Conf0) ->
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
We deprecated the request_timeout in resource_option of the webhook to keep it consistent with the http request_timeout of the webhook.
|
We hide the request_timeout in resource_option of the webhook to keep it consistent with the http request_timeout of the webhook.
|
||||||
From now on, when configuring a webhook through API or configuration files,
|
From now on, when configuring a webhook through API or configuration files,
|
||||||
it is no longer necessary to configure the request_timeout of the resource. Only configuring the http request_timeout is sufficient, and the request_timeout in the resource will automatically be consistent with the http request_timeout.
|
it is no longer necessary to configure the request_timeout of the resource. Only configuring the http request_timeout is sufficient, and the request_timeout in the resource will automatically be consistent with the http request_timeout.
|
||||||
|
|
Loading…
Reference in New Issue