Skip to content

Commit

Permalink
feat: ErrorsConfig and LatencyConfig are now pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
polsar88 committed Aug 6, 2024
1 parent 8bdf5c9 commit f9a9b54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ type LatencyConfig struct {
}

type RoutingConfig struct {
AlwaysRoute *bool `yaml:"alwaysRoute"`
Errors ErrorsConfig `yaml:"errors"`
Latency LatencyConfig `yaml:"latency"`
MaxBlocksBehind int `yaml:"maxBlocksBehind"`
DetectionWindow time.Duration `yaml:"detectionWindow"`
BanWindow time.Duration `yaml:"banWindow"`
AlwaysRoute *bool `yaml:"alwaysRoute"`
Errors *ErrorsConfig `yaml:"errors"`
Latency *LatencyConfig `yaml:"latency"`
MaxBlocksBehind int `yaml:"maxBlocksBehind"`
DetectionWindow time.Duration `yaml:"detectionWindow"`
BanWindow time.Duration `yaml:"banWindow"`
}

type ChainCacheConfig struct {
Expand Down Expand Up @@ -245,11 +245,15 @@ func (c *SingleChainConfig) isValid() bool {
}

func (r *RoutingConfig) isRoutingConfigValid() bool {
// TODO(polsar): Validate the HTTP codes.
// TODO(polsar): Validate the HTTP and JSON RPC codes, and potentially methods as well.
return r.isErrorRateValid()
}

func (r *RoutingConfig) isErrorRateValid() bool {
if r.Errors == nil {
return true
}

rate := r.Errors.Rate
isValid := 0.0 <= rate && rate <= 1.0

Expand Down
6 changes: 3 additions & 3 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp" //nolint:imports // Legacy
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -371,7 +371,7 @@ func TestParseConfig_ValidConfigLatencyRouting_AllFieldsSet(t *testing.T) {
Routing: RoutingConfig{
DetectionWindow: 10 * time.Minute,
BanWindow: 50 * time.Minute,
Errors: ErrorsConfig{
Errors: &ErrorsConfig{
Rate: 0.25,
HTTPCodes: []string{
"5xx",
Expand All @@ -384,7 +384,7 @@ func TestParseConfig_ValidConfigLatencyRouting_AllFieldsSet(t *testing.T) {
"internal server error",
},
},
Latency: LatencyConfig{
Latency: &LatencyConfig{
Threshold: 1000 * time.Millisecond,
Methods: []MethodConfig{
{
Expand Down

0 comments on commit f9a9b54

Please sign in to comment.