Skip to content

Commit

Permalink
feat: pprof is always on (#4951)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtojek committed Nov 8, 2022
1 parent 16384f8 commit bf4a6fb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 62 deletions.
18 changes: 6 additions & 12 deletions cli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"
"net/http"
_ "net/http/pprof" //nolint: gosec
"net/http/pprof"
"net/url"
"os"
"path/filepath"
Expand All @@ -28,7 +28,6 @@ import (
func workspaceAgent() *cobra.Command {
var (
auth string
pprofEnabled bool
pprofAddress string
noReap bool
)
Expand Down Expand Up @@ -82,15 +81,11 @@ func workspaceAgent() *cobra.Command {
// Set a reasonable timeout so requests can't hang forever!
client.HTTPClient.Timeout = 10 * time.Second

if pprofEnabled {
srvClose := serveHandler(cmd.Context(), logger, nil, pprofAddress, "pprof")
defer srvClose()
} else {
// If pprof wasn't enabled at startup, allow a
// `kill -USR1 $agent_pid` to start it (on Unix).
srvClose := agentStartPPROFOnUSR1(cmd.Context(), logger, pprofAddress)
defer srvClose()
}
// Enable pprof handler
// This prevents the pprof import from being accidentally deleted.
_ = pprof.Handler
pprofSrvClose := serveHandler(cmd.Context(), logger, nil, pprofAddress, "pprof")
defer pprofSrvClose()

// exchangeToken returns a session token.
// This is abstracted to allow for the same looping condition
Expand Down Expand Up @@ -177,7 +172,6 @@ func workspaceAgent() *cobra.Command {
}

cliflag.StringVarP(cmd.Flags(), &auth, "auth", "", "CODER_AGENT_AUTH", "token", "Specify the authentication type to use for the agent")
cliflag.BoolVarP(cmd.Flags(), &pprofEnabled, "pprof-enable", "", "CODER_AGENT_PPROF_ENABLE", false, "Enable serving pprof metrics on the address defined by --pprof-address.")
cliflag.BoolVarP(cmd.Flags(), &noReap, "no-reap", "", "", false, "Do not start a process reaper.")
cliflag.StringVarP(cmd.Flags(), &pprofAddress, "pprof-address", "", "CODER_AGENT_PPROF_ADDRESS", "127.0.0.1:6060", "The address to serve pprof.")
return cmd
Expand Down
38 changes: 0 additions & 38 deletions cli/agent_unix.go

This file was deleted.

12 changes: 0 additions & 12 deletions cli/agent_windows.go

This file was deleted.

0 comments on commit bf4a6fb

Please sign in to comment.