Skip to content

Commit

Permalink
Merge pull request #503 from alphagov/fix-periodic-reload
Browse files Browse the repository at this point in the history
Make route reload interval configurable with env var
  • Loading branch information
theseanything authored Dec 9, 2024
2 parents 42a55ab + 8748f5b commit 0d33284
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/load_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions lib/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Options struct {
BackendConnTimeout time.Duration
BackendHeaderTimeout time.Duration
LogFileName string
RouteReloadInterval time.Duration
}

type Backend struct {
Expand Down
25 changes: 14 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -119,6 +121,7 @@ func main() {
BackendConnTimeout: beConnTimeout,
BackendHeaderTimeout: beHeaderTimeout,
LogFileName: errorLogFile,
RouteReloadInterval: routeReloadInterval,
})
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 0d33284

Please sign in to comment.