Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 490a226

Browse files
committed
feat: Add support for pprof in coder agent
1 parent e09cd3e commit 490a226

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

cli/agent.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cli
33
import (
44
"context"
55
"net/http"
6+
_ "net/http/pprof"
67
"net/url"
78
"os"
89
"path/filepath"
@@ -25,7 +26,9 @@ import (
2526

2627
func workspaceAgent() *cobra.Command {
2728
var (
28-
auth string
29+
auth string
30+
pprofEnabled bool
31+
pprofAddress string
2932
)
3033
cmd := &cobra.Command{
3134
Use: "agent",
@@ -49,6 +52,11 @@ func workspaceAgent() *cobra.Command {
4952
logger := slog.Make(sloghuman.Sink(cmd.ErrOrStderr()), sloghuman.Sink(logWriter)).Leveled(slog.LevelDebug)
5053
client := codersdk.New(coderURL)
5154

55+
if pprofEnabled {
56+
//nolint:revive
57+
defer serveHandler(cmd.Context(), logger, nil, pprofAddress, "pprof")()
58+
}
59+
5260
// exchangeToken returns a session token.
5361
// This is abstracted to allow for the same looping condition
5462
// regardless of instance identity auth type.
@@ -139,5 +147,7 @@ func workspaceAgent() *cobra.Command {
139147
}
140148

141149
cliflag.StringVarP(cmd.Flags(), &auth, "auth", "", "CODER_AGENT_AUTH", "token", "Specify the authentication type to use for the agent")
150+
cliflag.BoolVarP(cmd.Flags(), &pprofEnabled, "pprof-enable", "", "CODER_AGENT_PPROF_ENABLE", false, "Enable serving pprof metrics on the address defined by --pprof-address.")
151+
cliflag.StringVarP(cmd.Flags(), &pprofAddress, "pprof-address", "", "CODER_AGENT_PPROF_ADDRESS", "127.0.0.1:6060", "The address to serve pprof.")
142152
return cmd
143153
}

0 commit comments

Comments
 (0)