diff --git a/lib/load_routes.go b/lib/load_routes.go index 51ae561a..ebf6d325 100644 --- a/lib/load_routes.go +++ b/lib/load_routes.go @@ -151,7 +151,7 @@ func (rt *Router) listenForContentStoreUpdates(ctx context.Context) error { func (rt *Router) PeriodicCSRouteUpdates() { tick := time.Tick(5 * time.Second) for range tick { - if time.Since(rt.csLastAttemptReloadTime) > time.Minute { + if time.Since(rt.csLastAttemptReloadTime) > rt.opts.RouteReloadInterval { // This is a non-blocking send, if there is already a notification to reload we don't need to send another one select { case rt.CsReloadChan <- true: diff --git a/lib/router.go b/lib/router.go index fa7baae6..56aa2ab9 100644 --- a/lib/router.go +++ b/lib/router.go @@ -63,6 +63,7 @@ type Options struct { BackendConnTimeout time.Duration BackendHeaderTimeout time.Duration LogFileName string + RouteReloadInterval time.Duration } type Backend struct { diff --git a/main.go b/main.go index e15ef4e7..a6164bf4 100644 --- a/main.go +++ b/main.go @@ -37,6 +37,7 @@ ROUTER_BACKEND_CONNECT_TIMEOUT=1s Connect timeout when connecting to backends ROUTER_BACKEND_HEADER_TIMEOUT=15s Timeout for backend response headers to be returned ROUTER_FRONTEND_READ_TIMEOUT=60s See https://cs.opensource.google/go/go/+/master:src/net/http/server.go?q=symbol:ReadTimeout ROUTER_FRONTEND_WRITE_TIMEOUT=60s See https://cs.opensource.google/go/go/+/master:src/net/http/server.go?q=symbol:WriteTimeout +ROUTER_ROUTE_RELOAD_INTERVAL=1m Interval for periodic route reloads ` fmt.Fprintf(os.Stderr, helpstring, router.VersionInfo(), os.Args[0]) const ErrUsage = 64 @@ -87,17 +88,18 @@ func main() { router.EnableDebugOutput = os.Getenv("ROUTER_DEBUG") != "" var ( - pubAddr = getenv("ROUTER_PUBADDR", ":8080") - apiAddr = getenv("ROUTER_APIADDR", ":8081") - mongoURL = getenv("ROUTER_MONGO_URL", "127.0.0.1") - mongoDBName = getenv("ROUTER_MONGO_DB", "router") - mongoPollInterval = getenvDuration("ROUTER_MONGO_POLL_INTERVAL", "2s") - errorLogFile = getenv("ROUTER_ERROR_LOG", "STDERR") - tlsSkipVerify = os.Getenv("ROUTER_TLS_SKIP_VERIFY") != "" - beConnTimeout = getenvDuration("ROUTER_BACKEND_CONNECT_TIMEOUT", "1s") - beHeaderTimeout = getenvDuration("ROUTER_BACKEND_HEADER_TIMEOUT", "20s") - feReadTimeout = getenvDuration("ROUTER_FRONTEND_READ_TIMEOUT", "60s") - feWriteTimeout = getenvDuration("ROUTER_FRONTEND_WRITE_TIMEOUT", "60s") + pubAddr = getenv("ROUTER_PUBADDR", ":8080") + apiAddr = getenv("ROUTER_APIADDR", ":8081") + mongoURL = getenv("ROUTER_MONGO_URL", "127.0.0.1") + mongoDBName = getenv("ROUTER_MONGO_DB", "router") + mongoPollInterval = getenvDuration("ROUTER_MONGO_POLL_INTERVAL", "2s") + errorLogFile = getenv("ROUTER_ERROR_LOG", "STDERR") + tlsSkipVerify = os.Getenv("ROUTER_TLS_SKIP_VERIFY") != "" + beConnTimeout = getenvDuration("ROUTER_BACKEND_CONNECT_TIMEOUT", "1s") + beHeaderTimeout = getenvDuration("ROUTER_BACKEND_HEADER_TIMEOUT", "20s") + feReadTimeout = getenvDuration("ROUTER_FRONTEND_READ_TIMEOUT", "60s") + feWriteTimeout = getenvDuration("ROUTER_FRONTEND_WRITE_TIMEOUT", "60s") + routeReloadInterval = getenvDuration("ROUTER_ROUTE_RELOAD_INTERVAL", "1m") ) log.Printf("using frontend read timeout: %v", feReadTimeout) @@ -119,6 +121,7 @@ func main() { BackendConnTimeout: beConnTimeout, BackendHeaderTimeout: beHeaderTimeout, LogFileName: errorLogFile, + RouteReloadInterval: routeReloadInterval, }) if err != nil { log.Fatal(err)