Skip to content

Commit

Permalink
Refactor debug routes in controller package and improve debug configu…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
andrasbacsai committed Oct 29, 2024
1 parent 8b7d21b commit d6e6afd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
43 changes: 23 additions & 20 deletions pkg/api/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,47 @@ func (c *Controller) GetEngine() *gin.Engine {
}

func (c *Controller) SetupRoutes() {
c.setupHealthRoutes()
c.setupCoreRoutes()
c.setupContainerRoutes()
c.setupMemoryRoutes()
c.setupCpuRoutes()
}

func (c *Controller) setupHealthRoutes() {
c.ginE.GET("/api/health", func(c *gin.Context) {
c.String(200, "ok")
func (c *Controller) setupCoreRoutes() {
c.ginE.GET("/api/health", func(ctx *gin.Context) {
ctx.String(200, "ok")
})
c.ginE.GET("/api/version", func(ctx *gin.Context) {
ctx.String(200, c.config.Version)
})
}

// TODO: Implement c.setupPushRoutes()
func (c *Controller) SetupDebugRoutes() {
c.setupDebugRoutes()
debugGroup := c.ginE.Group("/debug")
debugGroup.GET("/pprof", func(c *gin.Context) {
pprof.Index(c.Writer, c.Request)
debugGroup.GET("/pprof", func(ctx *gin.Context) {
pprof.Index(ctx.Writer, ctx.Request)
})
debugGroup.GET("/cmdline", func(c *gin.Context) {
pprof.Cmdline(c.Writer, c.Request)
debugGroup.GET("/cmdline", func(ctx *gin.Context) {
pprof.Cmdline(ctx.Writer, ctx.Request)
})
debugGroup.GET("/profile", func(c *gin.Context) {
pprof.Profile(c.Writer, c.Request)
debugGroup.GET("/profile", func(ctx *gin.Context) {
pprof.Profile(ctx.Writer, ctx.Request)
})
debugGroup.GET("/symbol", func(c *gin.Context) {
pprof.Symbol(c.Writer, c.Request)
debugGroup.GET("/symbol", func(ctx *gin.Context) {
pprof.Symbol(ctx.Writer, ctx.Request)
})
debugGroup.GET("/trace", func(c *gin.Context) {
pprof.Trace(c.Writer, c.Request)
debugGroup.GET("/trace", func(ctx *gin.Context) {
pprof.Trace(ctx.Writer, ctx.Request)
})
debugGroup.GET("/heap", func(c *gin.Context) {
pprof.Handler("heap").ServeHTTP(c.Writer, c.Request)
debugGroup.GET("/heap", func(ctx *gin.Context) {
pprof.Handler("heap").ServeHTTP(ctx.Writer, ctx.Request)
})
debugGroup.GET("/goroutine", func(c *gin.Context) {
pprof.Handler("goroutine").ServeHTTP(c.Writer, c.Request)
debugGroup.GET("/goroutine", func(ctx *gin.Context) {
pprof.Handler("goroutine").ServeHTTP(ctx.Writer, ctx.Request)
})
debugGroup.GET("/block", func(c *gin.Context) {
pprof.Handler("block").ServeHTTP(c.Writer, c.Request)
debugGroup.GET("/block", func(ctx *gin.Context) {
pprof.Handler("block").ServeHTTP(ctx.Writer, ctx.Request)
})
}
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package config

const Version = "0.0.14"

type Config struct {
Version string
Debug bool
RefreshRateSeconds int
PushEnabled bool
Expand All @@ -17,6 +20,7 @@ type Config struct {

func NewDefaultConfig() *Config {
return &Config{
Version: Version,
Debug: false,
RefreshRateSeconds: 5,
PushEnabled: true,
Expand Down

0 comments on commit d6e6afd

Please sign in to comment.