Skip to content

Commit

Permalink
Merge branch 'main' into remove-mongo-db
Browse files Browse the repository at this point in the history
  • Loading branch information
theseanything committed Dec 9, 2024
2 parents 36427fb + 0d33284 commit 041b6f3
Show file tree
Hide file tree
Showing 25 changed files with 160 additions and 174 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/alphagov/router
go 1.22.5

require (
github.com/getsentry/sentry-go v0.29.1
github.com/getsentry/sentry-go v0.30.0
github.com/jackc/pgx/v5 v5.7.1
github.com/onsi/ginkgo/v2 v2.22.0
github.com/onsi/gomega v1.36.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/getsentry/sentry-go v0.29.1 h1:DyZuChN8Hz3ARxGVV8ePaNXh1dQ7d76AiB117xcREwA=
github.com/getsentry/sentry-go v0.29.1/go.mod h1:x3AtIzN01d6SiWkderzaH28Tm0lgkafpJ5Bm3li39O0=
github.com/getsentry/sentry-go v0.30.0 h1:lWUwDnY7sKHaVIoZ9wYqRHJ5iEmoc0pqcRqFkosKzBo=
github.com/getsentry/sentry-go v0.30.0/go.mod h1:WU9B9/1/sHDqeV8T+3VwwbjeR5MSXs/6aqG3mqZrezA=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down
15 changes: 9 additions & 6 deletions lib/load_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,14 @@ func (rt *Router) listenForContentStoreUpdates(ctx context.Context) error {
}

func (rt *Router) PeriodicCSRouteUpdates() {
tick := time.Tick(time.Minute)
tick := time.Tick(5 * time.Second)
for range tick {
// 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:
default:
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:
default:
}
}
}
}
Expand Down Expand Up @@ -185,6 +187,8 @@ func (rt *Router) reloadCsRoutes(pool PgxIface) {
timer.ObserveDuration()
}()

rt.csLastAttemptReloadTime = time.Now()

logInfo("router: reloading routes from content store")
newmux := triemux.NewMux()

Expand All @@ -202,5 +206,4 @@ func (rt *Router) reloadCsRoutes(pool PgxIface) {

logInfo(fmt.Sprintf("router: reloaded %d routes from content store", routeCount))
routesCountMetric.WithLabelValues("content-store").Set(float64(routeCount))

}
16 changes: 9 additions & 7 deletions lib/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ const (
// Router is a wrapper around an HTTP multiplexer (trie.Mux) which retrieves its
// routes from a postgres database.
type Router struct {
backends map[string]http.Handler
csMux *triemux.Mux
lock sync.RWMutex
logger logger.Logger
opts Options
CsReloadChan chan bool
pool *pgxpool.Pool
backends map[string]http.Handler
csMux *triemux.Mux
lock sync.RWMutex
logger logger.Logger
opts Options
CsReloadChan chan bool
pool *pgxpool.Pool
csLastAttemptReloadTime time.Time
}

type Options struct {
BackendConnTimeout time.Duration
BackendHeaderTimeout time.Duration
LogFileName string
RouteReloadInterval time.Duration
}

// RegisterMetrics registers Prometheus metrics from the router module and the
Expand Down
19 changes: 11 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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 @@ -84,14 +85,15 @@ func main() {

router.EnableDebugOutput = os.Getenv("ROUTER_DEBUG") != ""
var (
pubAddr = getenv("ROUTER_PUBADDR", ":8080")
apiAddr = getenv("ROUTER_APIADDR", ":8081")
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")
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 @@ -110,6 +112,7 @@ func main() {
BackendConnTimeout: beConnTimeout,
BackendHeaderTimeout: beHeaderTimeout,
LogFileName: errorLogFile,
RouteReloadInterval: routeReloadInterval,
})
if err != nil {
log.Fatal(err)
Expand Down
6 changes: 6 additions & 0 deletions vendor/github.com/getsentry/sentry-go/.craft.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/getsentry/sentry-go/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions vendor/github.com/getsentry/sentry-go/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/getsentry/sentry-go/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions vendor/github.com/getsentry/sentry-go/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions vendor/github.com/getsentry/sentry-go/hub.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions vendor/github.com/getsentry/sentry-go/interfaces.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions vendor/github.com/getsentry/sentry-go/metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 041b6f3

Please sign in to comment.