From a436c410259c285926839b79c01a888ed52b3737 Mon Sep 17 00:00:00 2001 From: Zaid Albirawi Date: Tue, 20 Jun 2023 10:08:19 -0400 Subject: [PATCH] [TT-9196] fix dashboard client timeout (#5176) Dashboard client on the gateway side has a hardcoded 30 seconds and times out when dealing with larger amounts of APIs and Policies. Instead of the 30 seconds we can parametrize that value and allow the customer to determine the amount they are comfortable with. ## Description ## Related Issue https://tyktech.atlassian.net/browse/TT-9196 ## Motivation and Context ## How This Has Been Tested ## Screenshots (if appropriate) ## Types of changes - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why (cherry picked from commit d73dfa01dd5100a6584ae415cef0d6702b75b3cd) --- cli/linter/schema.json | 3 +++ config/config.go | 3 +++ gateway/dashboard_register.go | 13 +++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cli/linter/schema.json b/cli/linter/schema.json index b21db87facc..9f34d515c34 100644 --- a/cli/linter/schema.json +++ b/cli/linter/schema.json @@ -303,6 +303,9 @@ "connection_string": { "type": "string" }, + "connection_timeout": { + "type": "integer" + }, "node_is_segmented": { "type": "boolean" }, diff --git a/config/config.go b/config/config.go index 5d0b86d45fa..a124ff03afa 100644 --- a/config/config.go +++ b/config/config.go @@ -89,6 +89,9 @@ type DBAppConfOptionsConfig struct { // Set the URL to your Dashboard instance (or a load balanced instance). The URL needs to be formatted as: `http://dashboard_host:port` ConnectionString string `json:"connection_string"` + // Set the timeout for your Dashboard connection. Defaults to 30 seconds. In seconds. + ConnectionTimeout int `json:"connection_timeout"` + // Set to `true` to enable filtering (sharding) of APIs. NodeIsSegmented bool `json:"node_is_segmented"` diff --git a/gateway/dashboard_register.go b/gateway/dashboard_register.go index 8c2336016c0..bbeae7b9b8f 100644 --- a/gateway/dashboard_register.go +++ b/gateway/dashboard_register.go @@ -60,11 +60,20 @@ var dashClient *http.Client func (gw *Gateway) initialiseClient() *http.Client { if dashClient == nil { + conf := gw.GetConfig() + timeout := conf.DBAppConfOptions.ConnectionTimeout + + // I don't think this is the appropriate place for this. I recommend we look at + // something like https://github.com/mcuadros/go-defaults to normalize all our defaults. + if timeout < 1 { + timeout = 30 + } + dashClient = &http.Client{ - Timeout: 30 * time.Second, + Timeout: time.Duration(timeout) * time.Second, } - if gw.GetConfig().HttpServerOptions.UseSSL { + if conf.HttpServerOptions.UseSSL { // Setup HTTPS client tlsConfig := &tls.Config{ InsecureSkipVerify: gw.GetConfig().HttpServerOptions.SSLInsecureSkipVerify,