Skip to content

Commit af26058

Browse files
authored
[log] Add debug logging to circuit breaker (#4582)
Adds 4 focused debug log calls to `internal/server/circuit_breaker.go` using the existing `logCircuitBreaker` logger (`server:circuit_breaker` namespace). ## Changes **File modified:** `internal/server/circuit_breaker.go` ### New logging calls | Location | Message | |----------|---------| | `newCircuitBreaker` | Logs creation with `serverID`, `threshold`, and `cooldown` so you can see CB config at startup | | `Allow` (HALF-OPEN branch) | Logs when a probe is already in flight and the request is being rejected | | `RecordSuccess` | Logs when the consecutive error counter is reset (only when it was > 0, avoids noise on healthy paths) | | `parseRateLimitResetFromText` | Logs the parsed reset duration and absolute timestamp when a reset time is extracted from error text | ## Validation - `go build ./...` ✅ - `go vet ./...` ✅ - `go test ./internal/server/...` ✅ ## Enable these logs ```bash DEBUG=server:circuit_breaker ./awmg --config config.toml ``` > [!WARNING] > **⚠️ Firewall blocked 1 domain** > > The following domain was blocked by the firewall during workflow execution: > > - `releaseassets.githubusercontent.com` > > To allow these domains, add them to the `network.allowed` list in your workflow frontmatter: > > ```yaml > network: > allowed: > - defaults > - "releaseassets.githubusercontent.com" > ``` > > See [Network Configuration](https://github.github.com/gh-aw/reference/network/) for more information. > Generated by [Go Logger Enhancement](https://github.com/github/gh-aw-mcpg/actions/runs/24948903175/agentic_workflow) · ● 5.4M · [◷](https://github.com/search?q=repo%3Agithub%2Fgh-aw-mcpg+%22gh-aw-workflow-id%3A+go-logger%22&type=pullrequests) <!-- gh-aw-agentic-workflow: Go Logger Enhancement, engine: copilot, version: 1.0.21, model: auto, id: 24948903175, workflow_id: go-logger, run: https://github.com/github/gh-aw-mcpg/actions/runs/24948903175 --> <!-- gh-aw-workflow-id: go-logger -->
2 parents e01fad9 + 01dbced commit af26058

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

internal/server/circuit_breaker.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func newCircuitBreaker(serverID string, threshold int, cooldown time.Duration) *
8484
if cooldown <= 0 {
8585
cooldown = DefaultRateLimitCooldown
8686
}
87+
logCircuitBreaker.Printf("Creating circuit breaker: serverID=%s, threshold=%d, cooldown=%v", serverID, threshold, cooldown)
8788
return &circuitBreaker{
8889
serverID: serverID,
8990
state: circuitClosed,
@@ -140,6 +141,7 @@ func (cb *circuitBreaker) Allow() error {
140141
case circuitHalfOpen:
141142
// Only one probe is allowed; further requests are blocked until the probe resolves.
142143
if cb.probeInFlight {
144+
logCircuitBreaker.Printf("server %q circuit breaker HALF-OPEN, probe already in flight — rejecting request", cb.serverID)
143145
return &ErrCircuitOpen{ServerID: cb.serverID, ResetAt: cb.resetAt}
144146
}
145147
// This shouldn't normally happen (probe resolved but state wasn't updated),
@@ -157,6 +159,9 @@ func (cb *circuitBreaker) RecordSuccess() {
157159
defer cb.mu.Unlock()
158160

159161
prev := cb.state
162+
if cb.consecutiveErrors > 0 {
163+
logCircuitBreaker.Printf("server %q circuit breaker resetting consecutive error count: %d → 0", cb.serverID, cb.consecutiveErrors)
164+
}
160165
cb.consecutiveErrors = 0
161166
cb.probeInFlight = false
162167
if cb.state == circuitHalfOpen {
@@ -314,5 +319,7 @@ func parseRateLimitResetFromText(text string) time.Time {
314319
if err != nil || secs <= 0 {
315320
return time.Time{}
316321
}
317-
return time.Now().Add(time.Duration(secs) * time.Second)
322+
resetAt := time.Now().Add(time.Duration(secs) * time.Second)
323+
logCircuitBreaker.Printf("Parsed rate limit reset time from text: resetIn=%ds, resetAt=%s", secs, resetAt.UTC().Format(time.RFC3339))
324+
return resetAt
318325
}

0 commit comments

Comments
 (0)