diff --git a/api.go b/api.go index 14d8306..01af368 100644 --- a/api.go +++ b/api.go @@ -14,7 +14,7 @@ import ( libpack_cache "github.com/lukaszraczylo/graphql-monitoring-proxy/cache" libpack_config "github.com/lukaszraczylo/graphql-monitoring-proxy/config" libpack_logger "github.com/lukaszraczylo/graphql-monitoring-proxy/logging" - "github.com/sony/gobreaker" + "github.com/sony/gobreaker/v2" ) var bannedUsersIDs sync.Map // key: userID string, value: reason string diff --git a/circuit_breaker_fallback_test.go b/circuit_breaker_fallback_test.go index 6d7e8f0..73911ba 100644 --- a/circuit_breaker_fallback_test.go +++ b/circuit_breaker_fallback_test.go @@ -6,7 +6,7 @@ import ( "github.com/gofiber/fiber/v3" libpack_cache "github.com/lukaszraczylo/graphql-monitoring-proxy/cache" libpack_monitoring "github.com/lukaszraczylo/graphql-monitoring-proxy/monitoring" - "github.com/sony/gobreaker" + "github.com/sony/gobreaker/v2" "github.com/stretchr/testify/assert" "github.com/valyala/fasthttp" ) diff --git a/circuit_breaker_state_test.go b/circuit_breaker_state_test.go index 03a886a..f028947 100644 --- a/circuit_breaker_state_test.go +++ b/circuit_breaker_state_test.go @@ -4,7 +4,7 @@ import ( "errors" "time" - "github.com/sony/gobreaker" + "github.com/sony/gobreaker/v2" "github.com/stretchr/testify/assert" ) diff --git a/circuit_breaker_test.go b/circuit_breaker_test.go index 1f73c54..2afc3b5 100644 --- a/circuit_breaker_test.go +++ b/circuit_breaker_test.go @@ -15,7 +15,7 @@ import ( libpack_cache_memory "github.com/lukaszraczylo/graphql-monitoring-proxy/cache/memory" libpack_logger "github.com/lukaszraczylo/graphql-monitoring-proxy/logging" libpack_monitoring "github.com/lukaszraczylo/graphql-monitoring-proxy/monitoring" - "github.com/sony/gobreaker" + "github.com/sony/gobreaker/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "github.com/valyala/fasthttp" @@ -497,7 +497,7 @@ func (suite *CircuitBreakerTestSuite) TestCircuitBreakerFailureRatioWindow() { func (suite *CircuitBreakerTestSuite) TestCircuitBackoffResetsOnSuccessfulRecovery() { cbMutex.Lock() cbBackoff.reset() - cb = gobreaker.NewCircuitBreaker(gobreaker.Settings{ + cb = gobreaker.NewCircuitBreaker[any](gobreaker.Settings{ Name: "recovery-test", MaxRequests: 1, Timeout: 5 * time.Millisecond, @@ -682,7 +682,7 @@ func TestCircuitBackoffGateBlocks(t *testing.T) { testCfg.CircuitBreaker.BackoffMultiplier = tt.multiplier testCfg.CircuitBreaker.MaxBackoffTimeout = int(tt.maxBackoff / time.Second) - breaker := gobreaker.NewCircuitBreaker(gobreaker.Settings{Name: "gate-test"}) + breaker := gobreaker.NewCircuitBreaker[any](gobreaker.Settings{Name: "gate-test"}) now := tripTime.Add(tt.elapsed) got := circuitBackoffGateBlocks(testCfg, breaker, now) @@ -725,10 +725,10 @@ func TestCircuitBackoffLongerClosedDoorWithHigherMultiplier(t *testing.T) { cfgProgressive.CircuitBreaker.BackoffMultiplier = 2.0 seed() - blockedAtDefault := circuitBackoffGateBlocks(cfgDefault, gobreaker.NewCircuitBreaker(gobreaker.Settings{Name: "default"}), now) + blockedAtDefault := circuitBackoffGateBlocks(cfgDefault, gobreaker.NewCircuitBreaker[any](gobreaker.Settings{Name: "default"}), now) seed() - blockedAtProgressive := circuitBackoffGateBlocks(cfgProgressive, gobreaker.NewCircuitBreaker(gobreaker.Settings{Name: "progressive"}), now) + blockedAtProgressive := circuitBackoffGateBlocks(cfgProgressive, gobreaker.NewCircuitBreaker[any](gobreaker.Settings{Name: "progressive"}), now) assert.False(t, blockedAtDefault, "multiplier=1.0 (default): base has already elapsed, gate must match today's behaviour and not block") assert.True(t, blockedAtProgressive, "multiplier=2.0: effective backoff has not yet elapsed at the same instant, gate must still block -- strictly longer closed-door time than the default") diff --git a/errors.go b/errors.go index 2f2ca0a..b30b949 100644 --- a/errors.go +++ b/errors.go @@ -6,7 +6,7 @@ import ( "fmt" "time" - "github.com/sony/gobreaker" + "github.com/sony/gobreaker/v2" ) // Error codes for structured error responses diff --git a/errors_test.go b/errors_test.go index 8db2bde..dac57e4 100644 --- a/errors_test.go +++ b/errors_test.go @@ -6,7 +6,7 @@ import ( "net/http" "testing" - "github.com/sony/gobreaker" + "github.com/sony/gobreaker/v2" "github.com/stretchr/testify/assert" ) diff --git a/go.mod b/go.mod index a1e0577..cf68321 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/lukaszraczylo/go-simple-graphql v1.2.89 github.com/lukaszraczylo/oss-telemetry v0.2.5 github.com/redis/go-redis/v9 v9.22.0 - github.com/sony/gobreaker v1.0.0 + github.com/sony/gobreaker/v2 v2.4.0 github.com/stretchr/testify v1.12.1 github.com/valyala/fasthttp v1.74.0 go.opentelemetry.io/otel v1.47.0 diff --git a/go.sum b/go.sum index e82308d..5b53bc3 100644 --- a/go.sum +++ b/go.sum @@ -97,8 +97,8 @@ github.com/savsgio/gotils v0.0.0-20250924091648-bce9a52d7761 h1:McifyVxygw1d67y6 github.com/savsgio/gotils v0.0.0-20250924091648-bce9a52d7761/go.mod h1:Vi9gvHvTw4yCUHIznFl5TPULS7aXwgaTByGeBY75Wko= github.com/shamaton/msgpack/v3 v3.2.3 h1:0r0aZtrXDFOPpwWJTEOpFq+Ih/JmMLm0pqLN5mSilrw= github.com/shamaton/msgpack/v3 v3.2.3/go.mod h1:sgBYvEiyz8JR1NC3yGRoPVME9xXovpnh3l/plW1nfRo= -github.com/sony/gobreaker v1.0.0 h1:feX5fGGXSl3dYd4aHZItw+FpHLvvoaqkawKjVNiFMNQ= -github.com/sony/gobreaker v1.0.0/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= +github.com/sony/gobreaker/v2 v2.4.0 h1:g2KJRW1Ubty3+ZOcSEUN7K+REQJdN6yo6XvaML+jptg= +github.com/sony/gobreaker/v2 v2.4.0/go.mod h1:pTyFJgcZ3h2tdQVLZZruK2C0eoFL1fb/G83wK1ZQl+s= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= diff --git a/integration_test.go b/integration_test.go index 2d2f503..3e02615 100644 --- a/integration_test.go +++ b/integration_test.go @@ -13,7 +13,7 @@ import ( "github.com/gofiber/fiber/v3" libpack_cache "github.com/lukaszraczylo/graphql-monitoring-proxy/cache" libpack_monitoring "github.com/lukaszraczylo/graphql-monitoring-proxy/monitoring" - "github.com/sony/gobreaker" + "github.com/sony/gobreaker/v2" "github.com/valyala/fasthttp" ) diff --git a/proxy.go b/proxy.go index 55ec59f..c5ad4ea 100644 --- a/proxy.go +++ b/proxy.go @@ -23,7 +23,7 @@ import ( libpack_logger "github.com/lukaszraczylo/graphql-monitoring-proxy/logging" libpack_monitoring "github.com/lukaszraczylo/graphql-monitoring-proxy/monitoring" libpack_tracing "github.com/lukaszraczylo/graphql-monitoring-proxy/tracing" - "github.com/sony/gobreaker" + "github.com/sony/gobreaker/v2" "github.com/valyala/fasthttp" ) @@ -91,7 +91,7 @@ var circuitBreakerCountWindow = 10 * time.Minute // Global circuit breaker var ( - cb *gobreaker.CircuitBreaker + cb *gobreaker.CircuitBreaker[any] cbMutex sync.RWMutex ) @@ -240,7 +240,7 @@ func initCircuitBreaker(config *config) { } // Initialize the circuit breaker - cb = gobreaker.NewCircuitBreaker(cbSettings) + cb = gobreaker.NewCircuitBreaker[any](cbSettings) config.Logger.Info(&libpack_logger.LogMessage{ Message: "Circuit breaker initialized", @@ -530,7 +530,7 @@ func effectiveCircuitBackoff(base time.Duration, multiplier float64, maxBackoff // allocation- and lock-free on the hot path. now is a parameter (not // time.Now() read internally) so tests can drive this deterministically // without wall-clock sleeps. -func circuitBackoffGateBlocks(config *config, breaker *gobreaker.CircuitBreaker, now time.Time) bool { +func circuitBackoffGateBlocks(config *config, breaker *gobreaker.CircuitBreaker[any], now time.Time) bool { trips := cbBackoff.trips() if trips <= 0 { return false diff --git a/server_handlers_test.go b/server_handlers_test.go index d76db77..c55937a 100644 --- a/server_handlers_test.go +++ b/server_handlers_test.go @@ -14,7 +14,7 @@ import ( "github.com/gofiber/fiber/v3" libpack_cache "github.com/lukaszraczylo/graphql-monitoring-proxy/cache" - "github.com/sony/gobreaker" + "github.com/sony/gobreaker/v2" "github.com/valyala/fasthttp" )