diff --git a/internal/checks/error.go b/internal/checks/error.go index c06cbff..ead18bd 100644 --- a/internal/checks/error.go +++ b/internal/checks/error.go @@ -22,6 +22,7 @@ type ErrorCheck struct { upstreamConfig *config.UpstreamConfig routingConfig *config.RoutingConfig errorCircuitBreaker ErrorCircuitBreaker + isCheckEnabled bool } type ErrorCircuitBreaker interface { @@ -55,6 +56,7 @@ func NewErrorChecker( metricsContainer: metricsContainer, logger: logger, errorCircuitBreaker: NewErrorStats(routingConfig), + isCheckEnabled: routingConfig.IsCheckEnabled, } } @@ -155,7 +157,7 @@ func (e *ErrorStats) IsOpen() bool { } func (c *ErrorCheck) IsPassing([]string) bool { - if !c.routingConfig.IsEnhancedRoutingControlDefined() { + if !c.isCheckEnabled { return true } @@ -173,7 +175,7 @@ func (c *ErrorCheck) IsPassing([]string) bool { } func (c *ErrorCheck) RecordRequest(data *types.RequestData) { - if !c.routingConfig.IsEnhancedRoutingControlDefined() { + if !c.isCheckEnabled { return } diff --git a/internal/checks/latency.go b/internal/checks/latency.go index 9c26484..4dde6e9 100644 --- a/internal/checks/latency.go +++ b/internal/checks/latency.go @@ -20,6 +20,7 @@ type LatencyCheck struct { routingConfig *config.RoutingConfig methodLatencyBreaker map[string]LatencyCircuitBreaker // RPC method -> LatencyCircuitBreaker lock sync.RWMutex + isCheckEnabled bool } type LatencyCircuitBreaker interface { @@ -68,6 +69,7 @@ func NewLatencyChecker( metricsContainer: metricsContainer, logger: logger, methodLatencyBreaker: make(map[string]LatencyCircuitBreaker), + isCheckEnabled: routingConfig.IsCheckEnabled, } } @@ -113,7 +115,7 @@ func (l *LatencyStats) IsOpen() bool { } func (c *LatencyCheck) IsPassing(methods []string) bool { - if !c.routingConfig.IsEnhancedRoutingControlDefined() { + if !c.isCheckEnabled { return true } @@ -147,7 +149,7 @@ func (c *LatencyCheck) IsPassing(methods []string) bool { } func (c *LatencyCheck) RecordRequest(data *types.RequestData) { - if !c.routingConfig.IsEnhancedRoutingControlDefined() { + if !c.isCheckEnabled { return } diff --git a/internal/config/config.go b/internal/config/config.go index d57aeb8..ac9b7ff 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -352,6 +352,7 @@ type RoutingConfig struct { BanWindow *time.Duration `yaml:"banWindow"` MaxBlocksBehind int `yaml:"maxBlocksBehind"` IsInitialized bool + IsCheckEnabled bool } // IsEnhancedRoutingControlDefined returns true iff any of the enhanced routing control fields are specified @@ -434,6 +435,7 @@ func (r *RoutingConfig) setDefaults(globalConfig *RoutingConfig, force bool) boo } r.IsInitialized = true + r.IsCheckEnabled = true return true } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 006961d..aa749e8 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -429,9 +429,10 @@ func TestParseConfig_ValidConfigLatencyRouting_AllFieldsSet(t *testing.T) { "internal server error", }, }, - Latency: &expectedLatencyConfig, - AlwaysRoute: newBool(true), - IsInitialized: true, + Latency: &expectedLatencyConfig, + AlwaysRoute: newBool(true), + IsInitialized: true, + IsCheckEnabled: true, } expectedRoutingChainConfig := expectedRoutingConfig @@ -518,9 +519,10 @@ func TestParseConfig_ValidConfigLatencyRouting_ErrorsConfigOverridesAndMerges(t "freaking out", }, }, - Latency: &LatencyConfig{MethodLatencyThresholds: map[string]time.Duration{}}, - AlwaysRoute: newBool(false), - IsInitialized: true, + Latency: &LatencyConfig{MethodLatencyThresholds: map[string]time.Duration{}}, + AlwaysRoute: newBool(false), + IsInitialized: true, + IsCheckEnabled: true, } expectedRoutingChainConfig := expectedRoutingConfig @@ -598,9 +600,10 @@ func TestParseConfig_ValidConfigLatencyRouting_DefaultsForDetectionAndBanWindows Errors: &ErrorsConfig{ Rate: 0.25, }, - Latency: &expectedLatencyConfig, - AlwaysRoute: newBool(false), - IsInitialized: true, + Latency: &expectedLatencyConfig, + AlwaysRoute: newBool(false), + IsInitialized: true, + IsCheckEnabled: true, }, }, Chains: getCommonChainsConfig(&RoutingConfig{ @@ -610,6 +613,7 @@ func TestParseConfig_ValidConfigLatencyRouting_DefaultsForDetectionAndBanWindows Latency: &expectedLatencyConfig, AlwaysRoute: newBool(false), IsInitialized: true, + IsCheckEnabled: true, }), } @@ -758,9 +762,10 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencySp }, }, }, - Errors: &ErrorsConfig{Rate: DefaultErrorRate}, - AlwaysRoute: newBool(false), - IsInitialized: true, + Errors: &ErrorsConfig{Rate: DefaultErrorRate}, + AlwaysRoute: newBool(false), + IsInitialized: true, + IsCheckEnabled: true, }, }, @@ -783,9 +788,10 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencySp }, }, }, - Errors: &ErrorsConfig{Rate: DefaultErrorRate}, - AlwaysRoute: newBool(false), - IsInitialized: true, + Errors: &ErrorsConfig{Rate: DefaultErrorRate}, + AlwaysRoute: newBool(false), + IsInitialized: true, + IsCheckEnabled: true, }), } @@ -849,6 +855,7 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencyNo Errors: &ErrorsConfig{Rate: DefaultErrorRate}, AlwaysRoute: newBool(false), IsInitialized: true, + IsCheckEnabled: true, }, }, @@ -859,6 +866,7 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencyNo Errors: &ErrorsConfig{Rate: DefaultErrorRate}, AlwaysRoute: newBool(false), IsInitialized: true, + IsCheckEnabled: true, }), } @@ -924,9 +932,10 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencySp }, }, }, - Errors: &ErrorsConfig{Rate: DefaultErrorRate}, - AlwaysRoute: newBool(false), - IsInitialized: true, + Errors: &ErrorsConfig{Rate: DefaultErrorRate}, + AlwaysRoute: newBool(false), + IsInitialized: true, + IsCheckEnabled: true, }, }, @@ -948,9 +957,10 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencySp }, }, }, - Errors: &ErrorsConfig{Rate: DefaultErrorRate}, - AlwaysRoute: newBool(false), - IsInitialized: true, + Errors: &ErrorsConfig{Rate: DefaultErrorRate}, + AlwaysRoute: newBool(false), + IsInitialized: true, + IsCheckEnabled: true, }), } @@ -1054,9 +1064,10 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencyNo }, Threshold: DefaultMaxLatency, }, - Errors: &expectedErrorsConfig, - AlwaysRoute: newBool(false), - IsInitialized: true, + Errors: &expectedErrorsConfig, + AlwaysRoute: newBool(false), + IsInitialized: true, + IsCheckEnabled: true, }, }, @@ -1087,9 +1098,10 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencyNo }, }, }, - Errors: &expectedErrorsConfig, - AlwaysRoute: newBool(false), - IsInitialized: true, + Errors: &expectedErrorsConfig, + AlwaysRoute: newBool(false), + IsInitialized: true, + IsCheckEnabled: true, }), } @@ -1158,9 +1170,10 @@ func TestParseConfig_ValidConfigLatencyRouting_NoGlobalRoutingConfig_TwoChains_O Latency: &LatencyConfig{ MethodLatencyThresholds: map[string]time.Duration{}, }, - Errors: &ErrorsConfig{Rate: 0.25}, - AlwaysRoute: newBool(false), - IsInitialized: true, + Errors: &ErrorsConfig{Rate: 0.25}, + AlwaysRoute: newBool(false), + IsInitialized: true, + IsCheckEnabled: true, }, }, Chains: append(getCommonChainsConfig(&RoutingConfig{ @@ -1176,9 +1189,10 @@ func TestParseConfig_ValidConfigLatencyRouting_NoGlobalRoutingConfig_TwoChains_O }, }, }, - Errors: &ErrorsConfig{Rate: 0.25}, - AlwaysRoute: newBool(false), - IsInitialized: true, + Errors: &ErrorsConfig{Rate: 0.25}, + AlwaysRoute: newBool(false), + IsInitialized: true, + IsCheckEnabled: true, }), append(getCommonChainsConfig(&RoutingConfig{ DetectionWindow: NewDuration(DefaultDetectionWindow), BanWindow: NewDuration(DefaultBanWindow), @@ -1193,9 +1207,10 @@ func TestParseConfig_ValidConfigLatencyRouting_NoGlobalRoutingConfig_TwoChains_O }, }, }, - Errors: &ErrorsConfig{Rate: 0.25}, - AlwaysRoute: newBool(false), - IsInitialized: true, + Errors: &ErrorsConfig{Rate: 0.25}, + AlwaysRoute: newBool(false), + IsInitialized: true, + IsCheckEnabled: true, }), getCommonChainsConfig(&RoutingConfig{})...)...), }