Skip to content

Commit

Permalink
chore: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
polsar88 committed Oct 7, 2024
2 parents 51cb864 + e85b2ee commit 77194a9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
6 changes: 4 additions & 2 deletions internal/checks/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type ErrorCheck struct {
upstreamConfig *config.UpstreamConfig
routingConfig *config.RoutingConfig
errorCircuitBreaker ErrorCircuitBreaker
isCheckEnabled bool
}

type ErrorCircuitBreaker interface {
Expand Down Expand Up @@ -55,6 +56,7 @@ func NewErrorChecker(
metricsContainer: metricsContainer,
logger: logger,
errorCircuitBreaker: NewErrorStats(routingConfig),
isCheckEnabled: routingConfig.IsEnabled,
}
}

Expand Down Expand Up @@ -155,7 +157,7 @@ func (e *ErrorStats) IsOpen() bool {
}

func (c *ErrorCheck) IsPassing([]string) bool {
if !c.routingConfig.IsEnhancedRoutingControlDefined() {
if !c.isCheckEnabled {
return true
}

Expand All @@ -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
}

Expand Down
6 changes: 4 additions & 2 deletions internal/checks/latency.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -68,6 +69,7 @@ func NewLatencyChecker(
metricsContainer: metricsContainer,
logger: logger,
methodLatencyBreaker: make(map[string]LatencyCircuitBreaker),
isCheckEnabled: routingConfig.IsEnabled,
}
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ type RoutingConfig struct {
BanWindow *time.Duration `yaml:"banWindow"`
MaxBlocksBehind int `yaml:"maxBlocksBehind"`
IsInitialized bool
IsEnabled bool
}

// IsEnhancedRoutingControlDefined returns true iff any of the enhanced routing control fields are specified
Expand Down Expand Up @@ -434,6 +435,7 @@ func (r *RoutingConfig) setDefaults(globalConfig *RoutingConfig, force bool) boo
}

r.IsInitialized = true
r.IsEnabled = true

return true
}
Expand Down
15 changes: 15 additions & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ func TestParseConfig_ValidConfigLatencyRouting_AllFieldsSet(t *testing.T) {
Latency: &expectedLatencyConfig,
AlwaysRoute: newBool(true),
IsInitialized: true,
IsEnabled: true,
}

expectedRoutingChainConfig := expectedRoutingConfig
Expand Down Expand Up @@ -521,6 +522,7 @@ func TestParseConfig_ValidConfigLatencyRouting_ErrorsConfigOverridesAndMerges(t
Latency: &LatencyConfig{MethodLatencyThresholds: map[string]time.Duration{}},
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
}

expectedRoutingChainConfig := expectedRoutingConfig
Expand Down Expand Up @@ -601,6 +603,7 @@ func TestParseConfig_ValidConfigLatencyRouting_DefaultsForDetectionAndBanWindows
Latency: &expectedLatencyConfig,
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
},
},
Chains: getCommonChainsConfig(&RoutingConfig{
Expand All @@ -610,6 +613,7 @@ func TestParseConfig_ValidConfigLatencyRouting_DefaultsForDetectionAndBanWindows
Latency: &expectedLatencyConfig,
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
}),
}

Expand Down Expand Up @@ -761,6 +765,7 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencySp
Errors: &ErrorsConfig{Rate: DefaultErrorRate},
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
},
},

Expand All @@ -786,6 +791,7 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencySp
Errors: &ErrorsConfig{Rate: DefaultErrorRate},
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
}),
}

Expand Down Expand Up @@ -849,6 +855,7 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencyNo
Errors: &ErrorsConfig{Rate: DefaultErrorRate},
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
},
},

Expand All @@ -859,6 +866,7 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencyNo
Errors: &ErrorsConfig{Rate: DefaultErrorRate},
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
}),
}

Expand Down Expand Up @@ -927,6 +935,7 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencySp
Errors: &ErrorsConfig{Rate: DefaultErrorRate},
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
},
},

Expand All @@ -951,6 +960,7 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencySp
Errors: &ErrorsConfig{Rate: DefaultErrorRate},
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
}),
}

Expand Down Expand Up @@ -1057,6 +1067,7 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencyNo
Errors: &expectedErrorsConfig,
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
},
},

Expand Down Expand Up @@ -1090,6 +1101,7 @@ func TestParseConfig_ValidConfigLatencyRouting_MethodLatencies_TopLevelLatencyNo
Errors: &expectedErrorsConfig,
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
}),
}

Expand Down Expand Up @@ -1161,6 +1173,7 @@ func TestParseConfig_ValidConfigLatencyRouting_NoGlobalRoutingConfig_TwoChains_O
Errors: &ErrorsConfig{Rate: 0.25},
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
},
},
Chains: append(getCommonChainsConfig(&RoutingConfig{
Expand All @@ -1179,6 +1192,7 @@ func TestParseConfig_ValidConfigLatencyRouting_NoGlobalRoutingConfig_TwoChains_O
Errors: &ErrorsConfig{Rate: 0.25},
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
}), append(getCommonChainsConfig(&RoutingConfig{
DetectionWindow: NewDuration(DefaultDetectionWindow),
BanWindow: NewDuration(DefaultBanWindow),
Expand All @@ -1196,6 +1210,7 @@ func TestParseConfig_ValidConfigLatencyRouting_NoGlobalRoutingConfig_TwoChains_O
Errors: &ErrorsConfig{Rate: 0.25},
AlwaysRoute: newBool(false),
IsInitialized: true,
IsEnabled: true,
}), getCommonChainsConfig(&RoutingConfig{})...)...),
}

Expand Down
1 change: 1 addition & 0 deletions internal/server/web_server_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

func getRoutingConfig(alwaysRoute bool) *config.RoutingConfig {
return &config.RoutingConfig{
IsEnabled: true,
AlwaysRoute: &alwaysRoute,
DetectionWindow: config.NewDuration(10 * time.Minute),
BanWindow: config.NewDuration(100 * time.Millisecond),
Expand Down

0 comments on commit 77194a9

Please sign in to comment.