feat(agent): add http debug routes for magicsock (#7287)

This commit is contained in:
Colin Adler
2023-04-26 13:01:49 -05:00
committed by GitHub
parent 272573e9f0
commit 3eb7f06bf1
4 changed files with 58 additions and 9 deletions
+22 -6
View File
@@ -38,6 +38,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
sshMaxTimeout time.Duration
tailnetListenPort int64
prometheusAddress string
debugAddress string
)
cmd := &clibase.Cmd{
Use: "agent",
@@ -48,7 +49,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
ctx, cancel := context.WithCancel(inv.Context())
defer cancel()
agentPorts := map[int]string{}
ignorePorts := map[int]string{}
isLinux := runtime.GOOS == "linux"
@@ -125,14 +126,14 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
defer pprofSrvClose()
// Do a best effort here. If this fails, it's not a big deal.
if port, err := urlPort(pprofAddress); err == nil {
agentPorts[port] = "pprof"
ignorePorts[port] = "pprof"
}
prometheusSrvClose := ServeHandler(ctx, logger, prometheusMetricsHandler(), prometheusAddress, "prometheus")
defer prometheusSrvClose()
// Do a best effort here. If this fails, it's not a big deal.
if port, err := urlPort(prometheusAddress); err == nil {
agentPorts[port] = "prometheus"
ignorePorts[port] = "prometheus"
}
// exchangeToken returns a session token.
@@ -196,7 +197,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
return xerrors.Errorf("add executable to $PATH: %w", err)
}
closer := agent.New(agent.Options{
agnt := agent.New(agent.Options{
Client: client,
Logger: logger,
LogDir: logDir,
@@ -215,11 +216,19 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
EnvironmentVariables: map[string]string{
"GIT_ASKPASS": executablePath,
},
AgentPorts: agentPorts,
IgnorePorts: ignorePorts,
SSHMaxTimeout: sshMaxTimeout,
})
debugSrvClose := ServeHandler(ctx, logger, agnt.HTTPDebug(), debugAddress, "debug")
defer debugSrvClose()
// Do a best effort here. If this fails, it's not a big deal.
if port, err := urlPort(debugAddress); err == nil {
ignorePorts[port] = "debug"
}
<-ctx.Done()
return closer.Close()
return agnt.Close()
},
}
@@ -273,6 +282,13 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
Value: clibase.StringOf(&prometheusAddress),
Description: "The bind address to serve Prometheus metrics.",
},
{
Flag: "debug-address",
Default: "127.0.0.1:2113",
Env: "CODER_AGENT_DEBUG_ADDRESS",
Value: clibase.StringOf(&debugAddress),
Description: "The bind address to serve a debug HTTP server.",
},
}
return cmd
+3
View File
@@ -6,6 +6,9 @@ Starts the Coder workspace agent.
--auth string, $CODER_AGENT_AUTH (default: token)
Specify the authentication type to use for the agent.
--debug-address string, $CODER_AGENT_DEBUG_ADDRESS (default: 127.0.0.1:2113)
The bind address to serve a debug HTTP server.
--log-dir string, $CODER_AGENT_LOG_DIR (default: /tmp)
Specify the location for the agent log files.