Merge pull request #10821 from thalesmg/fix-webhook-bridge-req-timeout-r50
fix(webhook): keep `resource_opts.request_timeout` for webhook bridge (r5.0)
This commit is contained in:
commit
772a4575ca
|
@ -922,9 +922,6 @@ fill_defaults(Type, RawConf) ->
|
||||||
pack_bridge_conf(Type, RawConf) ->
|
pack_bridge_conf(Type, RawConf) ->
|
||||||
#{<<"bridges">> => #{bin(Type) => #{<<"foo">> => RawConf}}}.
|
#{<<"bridges">> => #{bin(Type) => #{<<"foo">> => RawConf}}}.
|
||||||
|
|
||||||
%% Hide webhook's resource_opts.request_timeout from user.
|
|
||||||
filter_raw_conf(<<"webhook">>, RawConf0) ->
|
|
||||||
emqx_utils_maps:deep_remove([<<"resource_opts">>, <<"request_timeout">>], RawConf0);
|
|
||||||
filter_raw_conf(_TypeBin, RawConf) ->
|
filter_raw_conf(_TypeBin, RawConf) ->
|
||||||
RawConf.
|
RawConf.
|
||||||
|
|
||||||
|
|
|
@ -311,7 +311,6 @@ parse_confs(
|
||||||
url := Url,
|
url := Url,
|
||||||
method := Method,
|
method := Method,
|
||||||
headers := Headers,
|
headers := Headers,
|
||||||
request_timeout := ReqTimeout,
|
|
||||||
max_retries := Retry
|
max_retries := Retry
|
||||||
} = Conf
|
} = Conf
|
||||||
) ->
|
) ->
|
||||||
|
@ -325,6 +324,10 @@ parse_confs(
|
||||||
Reason1 = emqx_utils:readable_error_msg(Reason),
|
Reason1 = emqx_utils:readable_error_msg(Reason),
|
||||||
invalid_data(<<"Invalid URL: ", Url1/binary, ", details: ", Reason1/binary>>)
|
invalid_data(<<"Invalid URL: ", Url1/binary, ", details: ", Reason1/binary>>)
|
||||||
end,
|
end,
|
||||||
|
RequestTimeout = emqx_utils_maps:deep_get(
|
||||||
|
[resource_opts, request_timeout],
|
||||||
|
Conf
|
||||||
|
),
|
||||||
Conf#{
|
Conf#{
|
||||||
base_url => BaseUrl1,
|
base_url => BaseUrl1,
|
||||||
request =>
|
request =>
|
||||||
|
@ -333,7 +336,7 @@ parse_confs(
|
||||||
method => Method,
|
method => Method,
|
||||||
body => maps:get(body, Conf, undefined),
|
body => maps:get(body, Conf, undefined),
|
||||||
headers => Headers,
|
headers => Headers,
|
||||||
request_timeout => ReqTimeout,
|
request_timeout => RequestTimeout,
|
||||||
max_retries => Retry
|
max_retries => Retry
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -251,25 +251,6 @@ 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) ->
|
||||||
Conf1 = emqx_bridge_compatible_config:upgrade_pre_ee(
|
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.
|
|
||||||
|
|
|
@ -40,15 +40,12 @@ fields("put") ->
|
||||||
fields("get") ->
|
fields("get") ->
|
||||||
emqx_bridge_schema:status_fields() ++ fields("post");
|
emqx_bridge_schema:status_fields() ++ fields("post");
|
||||||
fields("creation_opts") ->
|
fields("creation_opts") ->
|
||||||
[
|
lists:filter(
|
||||||
hidden_request_timeout()
|
fun({K, _V}) ->
|
||||||
| lists:filter(
|
not lists:member(K, unsupported_opts())
|
||||||
fun({K, _V}) ->
|
end,
|
||||||
not lists:member(K, unsupported_opts())
|
emqx_resource_schema:fields("creation_opts")
|
||||||
end,
|
).
|
||||||
emqx_resource_schema:fields("creation_opts")
|
|
||||||
)
|
|
||||||
].
|
|
||||||
|
|
||||||
desc("config") ->
|
desc("config") ->
|
||||||
?DESC("desc_config");
|
?DESC("desc_config");
|
||||||
|
@ -144,6 +141,7 @@ request_config() ->
|
||||||
emqx_schema:duration_ms(),
|
emqx_schema:duration_ms(),
|
||||||
#{
|
#{
|
||||||
default => <<"15s">>,
|
default => <<"15s">>,
|
||||||
|
deprecated => {since, "v5.0.26"},
|
||||||
desc => ?DESC("config_request_timeout")
|
desc => ?DESC("config_request_timeout")
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
|
@ -166,8 +164,7 @@ unsupported_opts() ->
|
||||||
[
|
[
|
||||||
enable_batch,
|
enable_batch,
|
||||||
batch_size,
|
batch_size,
|
||||||
batch_time,
|
batch_time
|
||||||
request_timeout
|
|
||||||
].
|
].
|
||||||
|
|
||||||
%%======================================================================================
|
%%======================================================================================
|
||||||
|
@ -194,13 +191,3 @@ name_field() ->
|
||||||
|
|
||||||
method() ->
|
method() ->
|
||||||
enum([post, put, get, delete]).
|
enum([post, put, get, delete]).
|
||||||
|
|
||||||
hidden_request_timeout() ->
|
|
||||||
{request_timeout,
|
|
||||||
mk(
|
|
||||||
hoconsc:union([infinity, emqx_schema:duration_ms()]),
|
|
||||||
#{
|
|
||||||
required => false,
|
|
||||||
importance => ?IMPORTANCE_HIDDEN
|
|
||||||
}
|
|
||||||
)}.
|
|
||||||
|
|
|
@ -1390,18 +1390,20 @@ t_inconsistent_webhook_request_timeouts(Config) ->
|
||||||
<<"resource_opts">> => #{<<"request_timeout">> => <<"2s">>}
|
<<"resource_opts">> => #{<<"request_timeout">> => <<"2s">>}
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
{ok, 201, #{
|
%% root request_timeout is deprecated for bridge.
|
||||||
<<"request_timeout">> := <<"1s">>,
|
{ok, 201,
|
||||||
<<"resource_opts">> := ResourceOpts
|
#{
|
||||||
}} =
|
<<"resource_opts">> := ResourceOpts
|
||||||
|
} = Response} =
|
||||||
request_json(
|
request_json(
|
||||||
post,
|
post,
|
||||||
uri(["bridges"]),
|
uri(["bridges"]),
|
||||||
BadBridgeParams,
|
BadBridgeParams,
|
||||||
Config
|
Config
|
||||||
),
|
),
|
||||||
?assertNot(maps:is_key(<<"request_timeout">>, ResourceOpts)),
|
?assertNot(maps:is_key(<<"request_timeout">>, Response)),
|
||||||
validate_resource_request_timeout(proplists:get_value(group, Config), 1000, Name),
|
?assertMatch(#{<<"request_timeout">> := <<"2s">>}, ResourceOpts),
|
||||||
|
validate_resource_request_timeout(proplists:get_value(group, Config), 2000, Name),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_cluster_later_join_metrics(Config) ->
|
t_cluster_later_join_metrics(Config) ->
|
||||||
|
|
|
@ -65,15 +65,13 @@ webhook_config_test() ->
|
||||||
<<"the_name">> :=
|
<<"the_name">> :=
|
||||||
#{
|
#{
|
||||||
<<"method">> := get,
|
<<"method">> := get,
|
||||||
<<"request_timeout">> := RequestTime,
|
|
||||||
<<"resource_opts">> := ResourceOpts,
|
<<"resource_opts">> := ResourceOpts,
|
||||||
<<"body">> := <<"${payload}">>
|
<<"body">> := <<"${payload}">>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} = check(Conf3),
|
} = check(Conf3),
|
||||||
?assertEqual(60_000, RequestTime),
|
?assertMatch(#{<<"request_timeout">> := infinity}, ResourceOpts),
|
||||||
?assertMatch(#{<<"request_timeout">> := 60_000}, ResourceOpts),
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
up(#{<<"bridges">> := Bridges0} = Conf0) ->
|
up(#{<<"bridges">> := Bridges0} = Conf0) ->
|
||||||
|
@ -196,7 +194,7 @@ full_webhook_v5019_hocon() ->
|
||||||
" pool_type = \"random\"\n"
|
" pool_type = \"random\"\n"
|
||||||
" request_timeout = \"1m\"\n"
|
" request_timeout = \"1m\"\n"
|
||||||
" resource_opts = {\n"
|
" resource_opts = {\n"
|
||||||
" request_timeout = \"7s\"\n"
|
" request_timeout = \"infinity\"\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
" ssl {\n"
|
" ssl {\n"
|
||||||
" ciphers = \"\"\n"
|
" ciphers = \"\"\n"
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-define(DEFAULT_PIPELINE_SIZE, 100).
|
-define(DEFAULT_PIPELINE_SIZE, 100).
|
||||||
|
-define(DEFAULT_REQUEST_TIMEOUT_MS, 30_000).
|
||||||
|
|
||||||
%%=====================================================================
|
%%=====================================================================
|
||||||
%% Hocon schema
|
%% Hocon schema
|
||||||
|
@ -477,7 +478,7 @@ preprocess_request(
|
||||||
path => emqx_plugin_libs_rule:preproc_tmpl(Path),
|
path => emqx_plugin_libs_rule:preproc_tmpl(Path),
|
||||||
body => maybe_preproc_tmpl(body, Req),
|
body => maybe_preproc_tmpl(body, Req),
|
||||||
headers => wrap_auth_header(preproc_headers(Headers)),
|
headers => wrap_auth_header(preproc_headers(Headers)),
|
||||||
request_timeout => maps:get(request_timeout, Req, 30000),
|
request_timeout => maps:get(request_timeout, Req, ?DEFAULT_REQUEST_TIMEOUT_MS),
|
||||||
max_retries => maps:get(max_retries, Req, 2)
|
max_retries => maps:get(max_retries, Req, 2)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue