diff options
author | pg9182 <96569817+pg9182@users.noreply.github.com> | 2023-03-08 19:48:52 -0500 |
---|---|---|
committer | pg9182 <96569817+pg9182@users.noreply.github.com> | 2023-04-17 14:49:47 -0400 |
commit | 4ca91ad422b455a9ef44df10cc5ccde2e2c67c12 (patch) | |
tree | 18e9a8a3d35d6e2c854b4c0af0bf7762947020a7 | |
parent | ff19827321355eaa51c950717c9190f0a3f11317 (diff) | |
download | Atlas-4ca91ad422b455a9ef44df10cc5ccde2e2c67c12.tar.gz Atlas-4ca91ad422b455a9ef44df10cc5ccde2e2c67c12.zip |
cmd/atlas: Add nspkt to debug server
-rw-r--r-- | cmd/atlas/main.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/cmd/atlas/main.go b/cmd/atlas/main.go index e019b4e..d0665d4 100644 --- a/cmd/atlas/main.go +++ b/cmd/atlas/main.go @@ -16,6 +16,7 @@ import ( "github.com/hashicorp/go-envparse" _ "github.com/mattn/go-sqlite3" "github.com/r2northstar/atlas/pkg/atlas" + "github.com/r2northstar/atlas/pkg/nspkt" "github.com/spf13/pflag" ) @@ -53,15 +54,22 @@ func main() { } } + dbg := http.NewServeMux() if dbgAddr, _ := getEnvList("INSECURE_DEBUG_SERVER_ADDR", e, os.Environ()); dbgAddr != "" { go func() { fmt.Fprintf(os.Stderr, "warning: running insecure debug server on %q\n", dbgAddr) - if err := runDebugServer(dbgAddr); err != nil { + if err := http.ListenAndServe(dbgAddr, dbg); err != nil { fmt.Fprintf(os.Stderr, "warning: failed to start debug server: %v\n", err) } }() } + dbg.HandleFunc("/debug/pprof/", pprof.Index) + dbg.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + dbg.HandleFunc("/debug/pprof/profile", pprof.Profile) + dbg.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + dbg.HandleFunc("/debug/pprof/trace", pprof.Trace) + var c atlas.Config if err := c.UnmarshalEnv(e, false); err != nil { fmt.Fprintf(os.Stderr, "error: parse config: %v\n", err) @@ -74,6 +82,8 @@ func main() { os.Exit(1) } + dbg.Handle("/nspkt", nspkt.DebugMonitorHandler(s.API0.NSPkt)) + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer stop() @@ -93,16 +103,6 @@ func main() { } } -func runDebugServer(addr string) error { - m := http.NewServeMux() - m.HandleFunc("/debug/pprof/", pprof.Index) - m.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) - m.HandleFunc("/debug/pprof/profile", pprof.Profile) - m.HandleFunc("/debug/pprof/symbol", pprof.Symbol) - m.HandleFunc("/debug/pprof/trace", pprof.Trace) - return http.ListenAndServe(addr, m) -} - func getEnvList(k string, e ...[]string) (string, bool) { for _, l := range e { for _, x := range l { |