feat: include rotated agent logs in support bundles (#26055)

Support bundles previously captured only the active coder-agent.log, losing
history across agent restarts. Add an optional `after` filter to the agent's
/debug/logs endpoint: without it the endpoint is unchanged (active log only,
10 MiB cap); with it the response includes the active log plus rotated
coder-agent-*.log files modified after the cutoff, newest first. Support
bundles request the last 24h.

Closes #25395
This commit is contained in:
Ehab Younes
2026-06-22 16:38:18 +03:00
committed by GitHub
parent adad5bdd49
commit f5cb2e547e
10 changed files with 512 additions and 30 deletions
+30 -4
View File
@@ -98,7 +98,7 @@ type AgentConn interface {
CallMCPTool(ctx context.Context, req CallMCPToolRequest) (CallMCPToolResponse, error)
Close() error
ContextConfig(ctx context.Context) (ContextConfigResponse, error)
DebugLogs(ctx context.Context) ([]byte, error)
DebugLogs(ctx context.Context, opts ...DebugLogsOption) ([]byte, error)
DebugMagicsock(ctx context.Context) ([]byte, error)
DebugManifest(ctx context.Context) ([]byte, error)
DialContext(ctx context.Context, network string, addr string) (net.Conn, error)
@@ -443,11 +443,29 @@ func (c *agentConn) DebugManifest(ctx context.Context) ([]byte, error) {
return bs, nil
}
// DebugLogs returns up to the last 10MB of `/tmp/coder-agent.log`
func (c *agentConn) DebugLogs(ctx context.Context) ([]byte, error) {
// DebugLogsOption configures a DebugLogs request.
type DebugLogsOption func(*debugLogsConfig)
type debugLogsConfig struct {
after time.Time
}
// WithLogsAfter also returns rotated logs modified at or after t, separated by
// boundary markers (100 MiB combined cap).
func WithLogsAfter(t time.Time) DebugLogsOption {
return func(c *debugLogsConfig) { c.after = t }
}
// DebugLogs returns up to 10 MiB of the active agent log. Pass WithLogsAfter to
// also include rotated logs.
func (c *agentConn) DebugLogs(ctx context.Context, opts ...DebugLogsOption) ([]byte, error) {
var cfg debugLogsConfig
for _, opt := range opts {
opt(&cfg)
}
ctx, span := tracing.StartSpan(ctx)
defer span.End()
res, err := c.apiRequest(ctx, http.MethodGet, "/debug/logs", nil)
res, err := c.apiRequest(ctx, http.MethodGet, debugLogsPath(cfg.after), nil)
if err != nil {
return nil, xerrors.Errorf("do request: %w", err)
}
@@ -462,6 +480,14 @@ func (c *agentConn) DebugLogs(ctx context.Context) ([]byte, error) {
return bs, nil
}
func debugLogsPath(after time.Time) string {
query := neturl.Values{}
if !after.IsZero() {
query.Set("after", after.UTC().Format(time.RFC3339Nano))
}
return agentAPIPath("/debug/logs", query)
}
// PrometheusMetrics returns a response from the agent's prometheus metrics endpoint
func (c *agentConn) PrometheusMetrics(ctx context.Context) ([]byte, error) {
ctx, span := tracing.StartSpan(ctx)