Skip to content

Commit

Permalink
fix(BUX-460): change pprof methods to get in replace of patch (#401)
Browse files Browse the repository at this point in the history
* fix: change pprof methods to get in replace of patch

* feat: update tests
  • Loading branch information
wregulski authored Jan 10, 2024
1 parent f87eb85 commit cb4e9f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
19 changes: 9 additions & 10 deletions actions/base/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type Action struct {

// RegisterRoutes register all the package specific routes
func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, services *config.AppServices) {

// Load the actions and set the services
action := &Action{actions.Action{AppConfig: appConfig, Services: services}}

Expand All @@ -32,15 +31,15 @@ func RegisterRoutes(router *apirouter.Router, appConfig *config.AppConfig, servi

// Debugging (shows all the Go profiler information)
if action.AppConfig.DebugProfiling {
router.HTTPRouter.HandlerFunc(http.MethodPatch, "/debug/pprof/", pprof.Index)
router.HTTPRouter.HandlerFunc(http.MethodPatch, "/debug/pprof/cmdline", pprof.Cmdline)
router.HTTPRouter.HandlerFunc(http.MethodPatch, "/debug/pprof/profile", pprof.Profile)
router.HTTPRouter.HandlerFunc(http.MethodPatch, "/debug/pprof/symbol", pprof.Symbol)
router.HTTPRouter.HandlerFunc(http.MethodPatch, "/debug/pprof/trace", pprof.Trace)
router.HTTPRouter.Handler(http.MethodPatch, "/debug/pprof/goroutine", pprof.Handler("goroutine"))
router.HTTPRouter.Handler(http.MethodPatch, "/debug/pprof/heap", pprof.Handler("heap"))
router.HTTPRouter.Handler(http.MethodPatch, "/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
router.HTTPRouter.Handler(http.MethodPatch, "/debug/pprof/block", pprof.Handler("block"))
router.HTTPRouter.HandlerFunc(http.MethodGet, "/debug/pprof/", pprof.Index)
router.HTTPRouter.HandlerFunc(http.MethodGet, "/debug/pprof/cmdline", pprof.Cmdline)
router.HTTPRouter.HandlerFunc(http.MethodGet, "/debug/pprof/profile", pprof.Profile)
router.HTTPRouter.HandlerFunc(http.MethodGet, "/debug/pprof/symbol", pprof.Symbol)
router.HTTPRouter.HandlerFunc(http.MethodGet, "/debug/pprof/trace", pprof.Trace)
router.HTTPRouter.Handler(http.MethodGet, "/debug/pprof/goroutine", pprof.Handler("goroutine"))
router.HTTPRouter.Handler(http.MethodGet, "/debug/pprof/heap", pprof.Handler("heap"))
router.HTTPRouter.Handler(http.MethodGet, "/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
router.HTTPRouter.Handler(http.MethodGet, "/debug/pprof/block", pprof.Handler("block"))
}

// Set the 404 handler (any request not detected)
Expand Down
20 changes: 9 additions & 11 deletions actions/base/routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
// TestBaseRegisterRoutes will test routes
func (ts *TestSuite) TestBaseRegisterRoutes() {
ts.T().Run("test routes", func(t *testing.T) {

// index
handle, _, _ := ts.Router.HTTPRouter.Lookup(http.MethodGet, "/")
assert.NotNil(t, handle)
Expand All @@ -38,32 +37,31 @@ func (ts *TestSuite) TestBaseRegisterRoutes() {
})

ts.T().Run("test debug profile routes", func(t *testing.T) {

handle, _, _ := ts.Router.HTTPRouter.Lookup(http.MethodPatch, "/debug/pprof/")
handle, _, _ := ts.Router.HTTPRouter.Lookup(http.MethodGet, "/debug/pprof/")
assert.NotNil(t, handle)

handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodPatch, "/debug/pprof/cmdline")
handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodGet, "/debug/pprof/cmdline")
assert.NotNil(t, handle)

handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodPatch, "/debug/pprof/profile")
handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodGet, "/debug/pprof/profile")
assert.NotNil(t, handle)

handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodPatch, "/debug/pprof/symbol")
handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodGet, "/debug/pprof/symbol")
assert.NotNil(t, handle)

handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodPatch, "/debug/pprof/trace")
handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodGet, "/debug/pprof/trace")
assert.NotNil(t, handle)

handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodPatch, "/debug/pprof/goroutine")
handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodGet, "/debug/pprof/goroutine")
assert.NotNil(t, handle)

handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodPatch, "/debug/pprof/heap")
handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodGet, "/debug/pprof/heap")
assert.NotNil(t, handle)

handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodPatch, "/debug/pprof/threadcreate")
handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodGet, "/debug/pprof/threadcreate")
assert.NotNil(t, handle)

handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodPatch, "/debug/pprof/block")
handle, _, _ = ts.Router.HTTPRouter.Lookup(http.MethodGet, "/debug/pprof/block")
assert.NotNil(t, handle)
})
}

0 comments on commit cb4e9f3

Please sign in to comment.