@@ -37,7 +37,8 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
37
37
noReap bool
38
38
sshMaxTimeout time.Duration
39
39
tailnetListenPort int64
40
- prometheusAddress string
40
+ promAddress string
41
+ debugAddress string
41
42
)
42
43
cmd := & clibase.Cmd {
43
44
Use : "agent" ,
@@ -48,7 +49,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
48
49
ctx , cancel := context .WithCancel (inv .Context ())
49
50
defer cancel ()
50
51
51
- agentPorts := map [int ]string {}
52
+ ignorePorts := map [int ]string {}
52
53
53
54
isLinux := runtime .GOOS == "linux"
54
55
@@ -125,14 +126,14 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
125
126
defer pprofSrvClose ()
126
127
// Do a best effort here. If this fails, it's not a big deal.
127
128
if port , err := urlPort (pprofAddress ); err == nil {
128
- agentPorts [port ] = "pprof"
129
+ ignorePorts [port ] = "pprof"
129
130
}
130
131
131
- prometheusSrvClose := ServeHandler (ctx , logger , prometheusMetricsHandler (), prometheusAddress , "prometheus" )
132
+ prometheusSrvClose := ServeHandler (ctx , logger , prometheusMetricsHandler (), promAddress , "prometheus" )
132
133
defer prometheusSrvClose ()
133
134
// Do a best effort here. If this fails, it's not a big deal.
134
- if port , err := urlPort (prometheusAddress ); err == nil {
135
- agentPorts [port ] = "prometheus"
135
+ if port , err := urlPort (promAddress ); err == nil {
136
+ ignorePorts [port ] = "prometheus"
136
137
}
137
138
138
139
// exchangeToken returns a session token.
@@ -196,7 +197,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
196
197
return xerrors .Errorf ("add executable to $PATH: %w" , err )
197
198
}
198
199
199
- closer := agent .New (agent.Options {
200
+ agnt := agent .New (agent.Options {
200
201
Client : client ,
201
202
Logger : logger ,
202
203
LogDir : logDir ,
@@ -215,11 +216,19 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
215
216
EnvironmentVariables : map [string ]string {
216
217
"GIT_ASKPASS" : executablePath ,
217
218
},
218
- AgentPorts : agentPorts ,
219
+ IgnorePorts : ignorePorts ,
219
220
SSHMaxTimeout : sshMaxTimeout ,
220
221
})
222
+
223
+ debugSrvClose := ServeHandler (ctx , logger , agnt .HTTPDebug (), debugAddress , "debug" )
224
+ defer debugSrvClose ()
225
+ // Do a best effort here. If this fails, it's not a big deal.
226
+ if port , err := urlPort (debugAddress ); err == nil {
227
+ ignorePorts [port ] = "debug"
228
+ }
229
+
221
230
<- ctx .Done ()
222
- return closer .Close ()
231
+ return agnt .Close ()
223
232
},
224
233
}
225
234
@@ -270,9 +279,16 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
270
279
Flag : "prometheus-address" ,
271
280
Default : "127.0.0.1:2112" ,
272
281
Env : "CODER_AGENT_PROMETHEUS_ADDRESS" ,
273
- Value : clibase .StringOf (& prometheusAddress ),
282
+ Value : clibase .StringOf (& promAddress ),
274
283
Description : "The bind address to serve Prometheus metrics." ,
275
284
},
285
+ {
286
+ Flag : "debug-address" ,
287
+ Default : "127.0.0.1:2113" ,
288
+ Env : "CODER_AGENT_DEBUG_ADDRESS" ,
289
+ Value : clibase .StringOf (& debugAddress ),
290
+ Description : "The bind address to serve a debug HTTP server." ,
291
+ },
276
292
}
277
293
278
294
return cmd
0 commit comments