Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VC-35738] Move the pprof endpoints to the main HTTP server rather than starting a second server #600

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/agent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func InitAgentCmdFlags(c *cobra.Command, cfg *AgentCmdFlags) {
"enable-pprof",
"",
false,
"Enables the pprof profiling server on the agent (port: 6060).",
"Enables the pprof profiling endpoints on the agent server (port: 8081).",
)
c.PersistentFlags().BoolVarP(
&cfg.Prometheus,
Expand Down
21 changes: 10 additions & 11 deletions pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/jetstack/preflight/pkg/logs"
"github.com/jetstack/preflight/pkg/version"

_ "net/http/pprof"
"net/http/pprof"
)

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

if Flags.Profiling {
logs.Log.Printf("pprof profiling was enabled.\nRunning profiling on port :6060")
go func() {
err := http.ListenAndServe(":6060", nil)
if err != nil && !errors.Is(err, http.ErrServerClosed) {
logs.Log.Fatalf("failed to run pprof profiler: %s", err)
}
}()
}

go func() {
server := http.NewServeMux()

if Flags.Profiling {
logs.Log.Printf("pprof profiling was enabled.")
server.HandleFunc("/debug/pprof/", pprof.Index)
server.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
server.HandleFunc("/debug/pprof/profile", pprof.Profile)
server.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
server.HandleFunc("/debug/pprof/trace", pprof.Trace)
}

if Flags.Prometheus {
logs.Log.Printf("Prometheus was enabled.\nRunning prometheus on port :8081")
prometheus.MustRegister(metricPayloadSize)
Expand Down