3
0

Add debug routes for eventbus & corredor service

This commit is contained in:
Denis Arh
2020-03-24 14:02:53 +01:00
parent ce10e46e71
commit db789e10fd
4 changed files with 44 additions and 0 deletions

View File

@@ -2,6 +2,9 @@ package api
import (
"fmt"
"github.com/cortezaproject/corteza-server/pkg/corredor"
"github.com/cortezaproject/corteza-server/pkg/eventbus"
"github.com/davecgh/go-spew/spew"
"net/http"
"reflect"
"runtime"
@@ -29,3 +32,15 @@ func debugRoutes(r chi.Routes) http.HandlerFunc {
printRoutes(r, "")
}
}
func debugEventbus() http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
spew.Fdump(w, eventbus.Service().Debug())
}
}
func debugCorredor() http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
spew.Fdump(w, corredor.Service().Debug())
}
}

View File

@@ -103,6 +103,12 @@ func (s server) Serve(ctx context.Context) {
s.log.Debug("list of routes: /__routes", zap.Error(err))
router.Get("/__routes", debugRoutes(router))
s.log.Debug("eventbus handlers: /__eventbus", zap.Error(err))
router.Get("/__eventbus", debugEventbus())
s.log.Debug("corredor service: /__corredor", zap.Error(err))
router.Get("/__corredor", debugCorredor())
}
if s.httpOpt.EnableVersionRoute {

View File

@@ -746,3 +746,12 @@ func (svc *service) GetBundle(ctx context.Context, name, bType string) *Bundle {
return nil
}
func (svc *service) Debug() interface{} {
return map[string]interface{}{
"registered": svc.registered,
"explicit": svc.explicit,
"server-scripts": svc.sScripts,
"client-scripts": svc.cScripts,
}
}

14
pkg/eventbus/debug.go Normal file
View File

@@ -0,0 +1,14 @@
package eventbus
// Debug returns structured debug data
func (b *eventbus) Debug() interface{} {
var (
o = make([]*handler, 0, len(b.handlers))
)
for _, h := range b.handlers {
o = append(o, h)
}
return o
}