RMPMP-2110: add circuit breaker lifecycle hooks#33
Open
stewartboyd119 wants to merge 7 commits into
Open
Conversation
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 Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PostCircuitBreakerOpenedandPostCircuitBreakerClosedtoLifecycleHooks, with empty meta structs (LifecyclePostCircuitBreakerOpened/LifecyclePostCircuitBreakerClosed) so additional fields can be introduced without breaking changes.ChainLifecycleHooks.OnStateChangehandler inWorkfactory wiring on transitions toStateOpen/StateClosed.Test Plan
go build ./...go vet ./...go test ./...(zkafka + test packages green)Test_LifecycleChainedHooksAreCalledto assert the new hooks fan out across chained entries.Test_LifecycleChainedNilPostCircuitBreakerOpenedInvocation/Closedto confirm nil-safe chaining.TestWork_Run_CircuitBreakerLifecycleHooksInvokedandTestWork_Run_CircuitBreakerHooksChainedintest/worker_test.godemonstrating the open/close callbacks fire end-to-end as the breaker trips on consecutive errors and recovers when processing succeeds.🤖 Generated with Claude Code