From 487395fa925c73e3bc57facc2bcad4cc58316775 Mon Sep 17 00:00:00 2001 From: Alexey Date: Mon, 29 Mar 2021 15:53:32 +0300 Subject: [PATCH] FIX ED-64: request_timeout is not actually a connection option (#24) --- config/sys.config | 8 ++++---- src/bouncer_opa_client.erl | 12 ++++++------ test/bouncer_tests_SUITE.erl | 1 + 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/config/sys.config b/config/sys.config index d8cc1d7..530dbec 100644 --- a/config/sys.config +++ b/config/sys.config @@ -24,7 +24,9 @@ {opa, #{ %% Endpoint of the OPA service - endpoint => {{resolve, dns, "opa", #{pick => random}}, 8181}, + endpoint => {{resolve, dns, "opa", #{pick => random}}, 8181}, + % Timeout for making request and receiving response. (ms) + request_timeout => 1000, %% Pool options, see gunner_pool:pool_opts() pool_opts => #{ cleanup_interval => 1000, @@ -42,9 +44,7 @@ % Total timeout for estabilishing a connection. (ms) connect_timeout => 1000, % Timeout for domain lookup query. (ms) - domain_lookup_timeout => 1000, - % Timeout for making request and receiving response. (ms) - request_timeout => 1000 + domain_lookup_timeout => 1000 } } }}, diff --git a/src/bouncer_opa_client.erl b/src/bouncer_opa_client.erl index 01ab574..8a9e191 100644 --- a/src/bouncer_opa_client.erl +++ b/src/bouncer_opa_client.erl @@ -12,7 +12,8 @@ -type opts() :: #{ pool_opts := gunner:pool_opts(), - endpoint := endpoint() + endpoint := endpoint(), + request_timeout => timeout() }. -opaque client() :: #{ @@ -55,7 +56,7 @@ init(OpaClientOpts) -> }, Client = genlib_map:compact(#{ endpoint => maps:get(endpoint, OpaClientOpts), - request_timeout => get_request_timeout(PoolOpts), + request_timeout => get_request_timeout(OpaClientOpts), connect_timeout => get_connect_timeout(PoolOpts) }), {Client, ChildSpec}. @@ -135,10 +136,9 @@ make_gunner_opts(RequestTimeout, #{connect_timeout := ConnectTimeout}) -> make_gunner_opts(RequestTimeout, _Client) -> #{request_timeout => RequestTimeout}. --spec get_request_timeout(gunner:pool_opts()) -> timeout(). -get_request_timeout(PoolOpts) -> - ClientOpts = maps:get(connection_opts, PoolOpts, #{}), - maps:get(request_timeout, ClientOpts, ?DEFAULT_REQUEST_TIMEOUT). +-spec get_request_timeout(opts()) -> timeout(). +get_request_timeout(Opts) -> + maps:get(request_timeout, Opts, ?DEFAULT_REQUEST_TIMEOUT). -spec get_connect_timeout(gunner:pool_opts()) -> timeout() | undefined. get_connect_timeout(PoolOpts) -> diff --git a/test/bouncer_tests_SUITE.erl b/test/bouncer_tests_SUITE.erl index aa44800..75a2e6d 100644 --- a/test/bouncer_tests_SUITE.erl +++ b/test/bouncer_tests_SUITE.erl @@ -124,6 +124,7 @@ start_bouncer(Env, C) -> }}, {opa, #{ endpoint => ?OPA_ENDPOINT_RESOLVE, + request_timeout => 1000, pool_opts => #{ connection_opts => #{ transport => tcp