Skip to content

Commit

Permalink
Merge pull request #43 from application-research/add-debug-endpoints
Browse files Browse the repository at this point in the history
Add debug endpoints
  • Loading branch information
10d9e committed Jun 7, 2023
2 parents a754d4b + c00e3df commit 0adf409
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
34 changes: 34 additions & 0 deletions api/debug_profiler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package api

import (
httpprof "net/http/pprof"
"runtime/pprof"
"time"

"github.com/application-research/edge-ur/core"
"github.com/labstack/echo/v4"
)

// ConfigureDebugRouter It configures the router to handle requests for node profiling
func ConfigureDebugProfileRouter(profilerGroup *echo.Group, node *core.LightNode) {

profilerGroup.GET("/pprof/:prof", func(c echo.Context) error {
httpprof.Handler(c.Param("prof")).ServeHTTP(c.Response().Writer, c.Request())
return nil
})

profilerGroup.GET("/cpuprofile", func(c echo.Context) error {
if err := pprof.StartCPUProfile(c.Response()); err != nil {
return err
}

defer pprof.StopCPUProfile()

select {
case <-c.Request().Context().Done():
return c.Request().Context().Err()
case <-time.After(time.Second * 30):
}
return nil
})
}
3 changes: 3 additions & 0 deletions api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func InitializeEchoRouterConfig(ln *core.LightNode) {
ConfigureHealthCheckRouter(defaultOpenRoute, ln)
ConfigureNodeInfoRouter(defaultOpenRoute, ln)

debugGroup := e.Group("/debug")
ConfigureDebugProfileRouter(debugGroup, ln)

apiGroup := e.Group("/api/v1")
apiGroup.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
Expand Down

0 comments on commit 0adf409

Please sign in to comment.