Skip to content

Commit 92cccd7

Browse files
feat: enhance Caddy Admin API diagnostics and error handling
- Added detailed diagnostic tests for Docker SDK container detection and connectivity - Implemented fallback mechanisms using shell commands when Docker SDK fails - Added comprehensive logging for connection strategy selection and failure cases - Created new debug functions to test container status, network config, and Docker socket permissions - Added detailed error messages and fix suggestions for common Docker connectivity issues - Improved observ
1 parent 8253c29 commit 92cccd7

2 files changed

Lines changed: 356 additions & 0 deletions

File tree

pkg/hecate/caddy_admin_api.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"io"
1111
"net/http"
12+
"os"
1213
"strings"
1314
"time"
1415
)
@@ -51,25 +52,43 @@ func NewCaddyAdminClient(host string) *CaddyAdminClient {
5152

5253
// Determine which host to use (three-tier fallback)
5354
var targetHost string
55+
var strategyUsed string
56+
5457
if host != "" && host != "localhost" {
5558
// Tier 1: Explicit host provided (e.g., from env var CADDY_ADMIN_HOST)
5659
targetHost = host
60+
strategyUsed = "explicit_host"
5761
} else {
5862
// Tier 2: Auto-detect container IP via Docker SDK (best approach)
5963
// RATIONALE: Bypasses localhost IPv4/IPv6 resolution issues
6064
// NON-FATAL: If Docker SDK fails, fall back to localhost
6165
ctx := context.Background()
6266
if containerIP, err := GetCaddyContainerIP(ctx); err == nil {
6367
targetHost = containerIP
68+
strategyUsed = "docker_sdk"
6469
} else {
6570
// Tier 3: Fall back to localhost (legacy behavior)
6671
// WARNING: May fail with IPv6 resolution issues
72+
73+
// CRITICAL: Log why Docker SDK failed (P0 finding from adversarial analysis)
74+
// RATIONALE: Silent failures are impossible to debug
75+
// NOTE: Can't use structured logger here (no RuntimeContext in constructor)
76+
// Using fmt.Fprintf to stderr as diagnostic output
77+
fmt.Fprintf(os.Stderr, "WARN: Caddy Admin API - Docker SDK container IP detection failed: %v\n", err)
78+
fmt.Fprintf(os.Stderr, "WARN: Caddy Admin API - Falling back to localhost:2019 (may fail with IPv6 issues)\n")
79+
fmt.Fprintf(os.Stderr, "INFO: Caddy Admin API - Run 'eos debug hecate --caddy' to diagnose Docker SDK issues\n")
80+
6781
targetHost = "localhost"
82+
strategyUsed = "localhost_fallback"
6883
}
6984
}
7085

7186
baseURL := fmt.Sprintf("http://%s:%d", targetHost, CaddyAdminAPIPort)
7287

88+
// Log which strategy was used for observability (P2 finding from adversarial analysis)
89+
// NOTE: This goes to stderr so it doesn't pollute stdout but is visible to user
90+
fmt.Fprintf(os.Stderr, "INFO: Caddy Admin API client created - strategy=%s, url=%s\n", strategyUsed, baseURL)
91+
7392
return &CaddyAdminClient{
7493
BaseURL: baseURL,
7594
HTTPClient: httpClient,

0 commit comments

Comments
 (0)