Skip to content

Commit efebe5b

Browse files
authored
Move the pprof endpoints to the main HTTP server rather than starting a second server (#600)
Signed-off-by: Richard Wall <[email protected]>
1 parent 1f00f09 commit efebe5b

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

pkg/agent/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
281281
"enable-pprof",
282282
"",
283283
false,
284-
"Enables the pprof profiling server on the agent (port: 6060).",
284+
"Enables the pprof profiling endpoints on the agent server (port: 8081).",
285285
)
286286
c.PersistentFlags().BoolVarP(
287287
&cfg.Prometheus,

pkg/agent/run.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"github.com/jetstack/preflight/pkg/logs"
3535
"github.com/jetstack/preflight/pkg/version"
3636

37-
_ "net/http/pprof"
37+
"net/http/pprof"
3838
)
3939

4040
var Flags AgentCmdFlags
@@ -74,19 +74,18 @@ func Run(cmd *cobra.Command, args []string) {
7474
logs.Log.Fatalf("While evaluating configuration: %v", err)
7575
}
7676

77-
if Flags.Profiling {
78-
logs.Log.Printf("pprof profiling was enabled.\nRunning profiling on port :6060")
79-
go func() {
80-
err := http.ListenAndServe(":6060", nil)
81-
if err != nil && !errors.Is(err, http.ErrServerClosed) {
82-
logs.Log.Fatalf("failed to run pprof profiler: %s", err)
83-
}
84-
}()
85-
}
86-
8777
go func() {
8878
server := http.NewServeMux()
8979

80+
if Flags.Profiling {
81+
logs.Log.Printf("pprof profiling was enabled.")
82+
server.HandleFunc("/debug/pprof/", pprof.Index)
83+
server.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
84+
server.HandleFunc("/debug/pprof/profile", pprof.Profile)
85+
server.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
86+
server.HandleFunc("/debug/pprof/trace", pprof.Trace)
87+
}
88+
9089
if Flags.Prometheus {
9190
logs.Log.Printf("Prometheus was enabled.\nRunning prometheus on port :8081")
9291
prometheus.MustRegister(metricPayloadSize)

0 commit comments

Comments
 (0)