Skip to content

Commit

Permalink
setup timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
absorbb committed Aug 8, 2023
1 parent 9814c58 commit 5e097f6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
9 changes: 4 additions & 5 deletions bulkerapp/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,10 @@ func (a *Context) InitContext(settings *appbase.AppSettings) error {

router := NewRouter(a)
a.server = &http.Server{
Addr: fmt.Sprintf("0.0.0.0:%d", a.config.HTTPPort),
Handler: router.Engine(),
ReadTimeout: time.Second * 1800,
ReadHeaderTimeout: time.Second * 60,
IdleTimeout: time.Second * 65,
Addr: fmt.Sprintf("0.0.0.0:%d", a.config.HTTPPort),
Handler: router.Engine(),
ReadTimeout: time.Minute * 30,
IdleTimeout: time.Minute * 5,
}
metricsServer := NewMetricsServer(a.config)
a.metricsServer = metricsServer
Expand Down
28 changes: 16 additions & 12 deletions bulkerapp/app/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/jitsucom/bulker/jitsubase/utils"
"github.com/jitsucom/bulker/jitsubase/uuid"
jsoniter "github.com/json-iterator/go"
timeout "github.com/vearne/gin-timeout"
"io"
"net/http"
"regexp"
Expand Down Expand Up @@ -55,12 +56,23 @@ func NewRouter(appContext *Context) *Router {
fastStore: appContext.fastStore,
}
engine := router.Engine()
engine.POST("/post/:destinationId", router.EventsHandler)
fast := engine.Group("")
fast.Use(timeout.Timeout(timeout.WithTimeout(10 * time.Second)))
fast.POST("/post/:destinationId", router.EventsHandler)
fast.POST("/ingest", router.IngestHandler)
fast.POST("/test", router.TestConnectionHandler)
fast.GET("/log/:eventType/:actorId", router.EventsLogHandler)
fast.GET("/ready", func(c *gin.Context) {
if router.topicManager.IsReady() {
c.Status(http.StatusOK)
} else {
logging.Errorf("Health check: FAILED")
c.AbortWithStatus(http.StatusServiceUnavailable)
}
})

engine.POST("/bulk/:destinationId", router.BulkHandler)
engine.POST("/test", router.TestConnectionHandler)
engine.POST("/ingest", router.IngestHandler)
engine.GET("/failed/:destinationId", router.FailedHandler)
engine.GET("/log/:eventType/:actorId", router.EventsLogHandler)

//engine.GET("/debug/pprof/profile", gin.WrapF(pprof.Profile))
//engine.GET("/debug/pprof/heap", gin.WrapF(pprof.Handler("heap").ServeHTTP))
Expand All @@ -73,14 +85,6 @@ func NewRouter(appContext *Context) *Router {
//engine.GET("/debug/pprof/mutex", gin.WrapF(pprof.Handler("mutex").ServeHTTP))
//engine.GET("/debug/pprof", gin.WrapF(pprof.Index))

engine.GET("/ready", func(c *gin.Context) {
if router.topicManager.IsReady() {
c.Status(http.StatusOK)
} else {
logging.Errorf("Health check: FAILED")
c.AbortWithStatus(http.StatusServiceUnavailable)
}
})
return router
}

Expand Down
1 change: 1 addition & 0 deletions bulkerapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.20
require (
github.com/confluentinc/confluent-kafka-go/v2 v2.1.1
github.com/gin-gonic/gin v1.9.1
github.com/vearne/gin-timeout v0.1.7
github.com/go-co-op/gocron v1.27.1
github.com/gomodule/redigo v1.8.9
github.com/hashicorp/go-multierror v1.1.1
Expand Down

0 comments on commit 5e097f6

Please sign in to comment.