Skip to content

RMPMP-2110: add circuit breaker lifecycle hooks#33

Open
stewartboyd119 wants to merge 7 commits into
mainfrom
RMPMP-2110
Open

RMPMP-2110: add circuit breaker lifecycle hooks#33
stewartboyd119 wants to merge 7 commits into
mainfrom
RMPMP-2110

Conversation

@stewartboyd119
Copy link
Copy Markdown
Member

Summary

  • Add PostCircuitBreakerOpened and PostCircuitBreakerClosed to LifecycleHooks, with empty meta structs (LifecyclePostCircuitBreakerOpened / LifecyclePostCircuitBreakerClosed) so additional fields can be introduced without breaking changes.
  • Chain the new hooks in ChainLifecycleHooks.
  • Invoke the hooks from the gobreaker OnStateChange handler in Work factory wiring on transitions to StateOpen / StateClosed.

Test Plan

  • go build ./...
  • go vet ./...
  • go test ./... (zkafka + test packages green)
  • Extended Test_LifecycleChainedHooksAreCalled to assert the new hooks fan out across chained entries.
  • Added Test_LifecycleChainedNilPostCircuitBreakerOpenedInvocation / Closed to confirm nil-safe chaining.
  • Added TestWork_Run_CircuitBreakerLifecycleHooksInvoked and TestWork_Run_CircuitBreakerHooksChained in test/worker_test.go demonstrating the open/close callbacks fire end-to-end as the breaker trips on consecutive errors and recovers when processing succeeds.

🤖 Generated with Claude Code

Extend LifecycleHooks with PostCircuitBreakerOpened and
PostCircuitBreakerClosed callbacks (with empty meta structs that can
grow without breaking changes), chain them in ChainLifecycleHooks, and
invoke them from the gobreaker OnStateChange handler when the breaker
transitions into open or closed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

❌ Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.47%. Comparing base (e814e93) to head (a921272).

Files with missing lines Patch % Lines
lifecycle.go 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #33      +/-   ##
==========================================
+ Coverage   89.40%   89.47%   +0.06%     
==========================================
  Files          18       18              
  Lines        1586     1605      +19     
==========================================
+ Hits         1418     1436      +18     
  Misses        111      111              
- Partials       57       58       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

stewartbzillow and others added 6 commits May 10, 2026 10:36
Call PostCircuitBreakerOpened/Closed before the busy-loop-breaker
release/timer setup so observers see the state transition before any
release side effects.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace pollWait/pollOpts with require.Eventually for the new circuit
breaker lifecycle hook tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the mock-reader-based CB hook tests with an integration-style
test that uses confluent-kafka-go's in-process MockCluster. The topic
is created and seeded with real messages; the worker reads them through
the actual zkafka client/reader path, the processor returns errors to
trip the breaker, and is then flipped to success so the breaker
recovers — exercising both PostCircuitBreakerOpened and
PostCircuitBreakerClosed end-to-end. Lives in
test/integration_confluent_mock_cluster_test.go.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace PostCircuitBreakerOpened/Closed with a single
CircuitBreakerStateChanged callback that receives a
LifecyclePostCircuitBreakerStateChange{From, To} value. State strings
are exposed as CircuitBreakerStateOpen/HalfOpen/Closed so callers can
observe all gobreaker transitions, including half-open.

- lifecycle.go: new types + CircuitBreakerStateChanged field; chain
  fans out the single hook across entries; toCircuitBreakerState maps
  gobreaker.State -> CircuitBreakerState.
- work.go: invoke the hook once per OnStateChange transition with both
  from and to translated, before the busy-loop-breaker side effects.
- lifecycle_test.go: chained-hooks test now counts a single hook per
  entry, with assertions across two transitions; replaces the two old
  nil-invocation tests with a single one.
- test/integration_confluent_mock_cluster_test.go: track opens/closes
  by inspecting meta.To.

Also ignores plan/ directory.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants