From 6efaee5b4fc7fc8cffa05279c1860fcead3c2279 Mon Sep 17 00:00:00 2001 From: Alex Ellis Date: Mon, 5 Mar 2018 12:29:13 +0000 Subject: [PATCH] Add upstream_timeout as env-var Signed-off-by: Alex Ellis --- gateway/handlers/forwarding_proxy.go | 3 ++- gateway/server.go | 2 +- gateway/types/readconfig.go | 11 +++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/gateway/handlers/forwarding_proxy.go b/gateway/handlers/forwarding_proxy.go index f1003fd9..1c5df00f 100644 --- a/gateway/handlers/forwarding_proxy.go +++ b/gateway/handlers/forwarding_proxy.go @@ -65,7 +65,8 @@ func forwardRequest(w http.ResponseWriter, r *http.Request, proxyClient *http.Cl defer r.Body.Close() upstreamReq.Body = r.Body } - ctx, cancel := context.WithTimeout(context.Background(), timeout-time.Second*1) + + ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() res, resErr := proxyClient.Do(upstreamReq.WithContext(ctx)) diff --git a/gateway/server.go b/gateway/server.go index 1c9a15d9..159ee66f 100644 --- a/gateway/server.go +++ b/gateway/server.go @@ -40,7 +40,7 @@ func main() { servicePollInterval := time.Second * 5 - reverseProxy := types.NewHTTPClientReverseProxy(config.FunctionsProviderURL, config.ReadTimeout) + reverseProxy := types.NewHTTPClientReverseProxy(config.FunctionsProviderURL, config.UpstreamTimeout) faasHandlers.Proxy = internalHandlers.MakeForwardingProxyHandler(reverseProxy, &metricsOptions) faasHandlers.RoutelessProxy = internalHandlers.MakeForwardingProxyHandler(reverseProxy, &metricsOptions) diff --git a/gateway/types/readconfig.go b/gateway/types/readconfig.go index 08535b8d..f52b8917 100644 --- a/gateway/types/readconfig.go +++ b/gateway/types/readconfig.go @@ -58,11 +58,11 @@ func (ReadConfig) Read(hasEnv HasEnv) GatewayConfig { PrometheusPort: 9090, } - readTimeout := parseIntOrDurationValue(hasEnv.Getenv("read_timeout"), time.Second*8) - writeTimeout := parseIntOrDurationValue(hasEnv.Getenv("write_timeout"), time.Second*8) + defaultDuration := time.Second * 8 - cfg.ReadTimeout = readTimeout - cfg.WriteTimeout = writeTimeout + cfg.ReadTimeout = parseIntOrDurationValue(hasEnv.Getenv("read_timeout"), defaultDuration) + cfg.WriteTimeout = parseIntOrDurationValue(hasEnv.Getenv("write_timeout"), defaultDuration) + cfg.UpstreamTimeout = parseIntOrDurationValue(hasEnv.Getenv("upstream_timeout"), defaultDuration) if len(hasEnv.Getenv("functions_provider_url")) > 0 { var err error @@ -114,6 +114,9 @@ type GatewayConfig struct { // HTTP timeout for writing a response from functions. WriteTimeout time.Duration + // UpstreamTimeout maximum duration of HTTP call to upstream URL + UpstreamTimeout time.Duration + // URL for alternate functions provider. FunctionsProviderURL *url.URL