(addr string, eng *server.Server)
| 28 | ) |
| 29 | |
| 30 | func setupDebugHandlers(addr string, eng *server.Server) error { |
| 31 | m := http.NewServeMux() |
| 32 | m.Handle("/debug/vars", expvar.Handler()) |
| 33 | m.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index)) |
| 34 | m.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) |
| 35 | m.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) |
| 36 | m.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) |
| 37 | m.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) |
| 38 | m.Handle("/debug/pprof/heap", pprof.Handler("heap")) |
| 39 | m.Handle("/debug/pprof/mutex", pprof.Handler("mutex")) |
| 40 | m.Handle("/debug/pprof/block", pprof.Handler("block")) |
| 41 | m.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine")) |
| 42 | m.Handle("/debug/requests", http.HandlerFunc(trace.Traces)) |
| 43 | m.Handle("/debug/events", http.HandlerFunc(trace.Events)) |
| 44 | // m.Handle("/debug/fgtrace", fgtrace.Config{}) |
| 45 | |
| 46 | // uncomment these to get data from /mutex and /block |
| 47 | // runtime.SetMutexProfileFraction(1) |
| 48 | // runtime.SetBlockProfileRate(1) |
| 49 | |
| 50 | m.Handle("/debug/gc", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { |
| 51 | runtime.GC() |
| 52 | debug.FreeOSMemory() |
| 53 | logrus.Debugf("triggered GC from debug endpoint") |
| 54 | })) |
| 55 | m.Handle("/debug/dagql/egraph", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { |
| 56 | if eng == nil { |
| 57 | http.Error(rw, "engine server not available", http.StatusServiceUnavailable) |
| 58 | return |
| 59 | } |
| 60 | snapshot := eng.DagqlDebugSnapshot() |
| 61 | if snapshot == nil { |
| 62 | http.Error(rw, "dagql cache not available", http.StatusServiceUnavailable) |
| 63 | return |
| 64 | } |
| 65 | rw.Header().Set("Content-Type", "application/json") |
| 66 | enc := json.NewEncoder(rw) |
| 67 | enc.SetIndent("", " ") |
| 68 | if err := enc.Encode(snapshot); err != nil { |
| 69 | http.Error(rw, err.Error(), http.StatusInternalServerError) |
| 70 | return |
| 71 | } |
| 72 | })) |
| 73 | m.Handle("/debug/dagql/cache", http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { |
| 74 | if eng == nil { |
| 75 | http.Error(rw, "engine server not available", http.StatusServiceUnavailable) |
| 76 | return |
| 77 | } |
| 78 | rw.Header().Set("Content-Type", "application/json") |
| 79 | if err := eng.WriteDagqlCacheDebugSnapshot(rw); err != nil { |
| 80 | logrus.WithError(err).Warn("failed streaming dagql cache debug snapshot") |
| 81 | } |
| 82 | })) |
| 83 | |
| 84 | // setting debugaddr is opt-in. permission is defined by listener address |
| 85 | trace.AuthRequest = func(_ *http.Request) (bool, bool) { |
| 86 | return true, true |
| 87 | } |
no test coverage detected