Skip to content

Commit

Permalink
test: add tests for enhanced routing control (#143)
Browse files Browse the repository at this point in the history
* fix: remove a TODO

* fix: field alignment

* fix: field alignment

* fix: readability

* fix: update `README.md`

* feat: initial implementation of `AlwaysRouteRoutingStrategy`

* fix: comment formatting

* fix: comment phrasing

* fix: add a TODO

* fix: renaming

* fix: revert to the previous version of `PriorityRoundRobinStrategy`

* fix: remove `HealthStatus` field

* feat: LatencyChecker can now be configured to only check latency, errors, or both

* feat: create separate instances of LatencyChecker for error and latency checking

* feat: plumbing for `AlwaysRouteFilteringStrategy`

* fix: tests

* fix: removable filters

* feat: add debug logging

* fix: move `getFilterTypeName` function to `node_filter` module

* refactor: deduplicate filter upstreams code

* refactor: remove passive error/latency checker code

* refactor: split error latency checker into two structs

* fix: error and latency filters are now passed to regular filtering routing strategy

* fix: typo

* style: remove unused global variable

* test: add test

* refactor: test

* refactor: test

* refactor: add test

* test: add test

* test: add high latency test

* refactor: routing config struct

* test: add latency test with always route

* test: add error rate test with always route
  • Loading branch information
polsar88 authored Oct 7, 2024
1 parent e85b2ee commit 0c27246
Show file tree
Hide file tree
Showing 5 changed files with 333 additions and 53 deletions.
36 changes: 0 additions & 36 deletions internal/checks/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package checks
import (
"errors"
"testing"
"time"

"github.com/satsuma-data/node-gateway/internal/config"
"github.com/stretchr/testify/assert"
Expand All @@ -15,41 +14,6 @@ var defaultUpstreamConfig = &config.UpstreamConfig{
WSURL: "wss://alchemy",
}

var defaultRoutingConfig = &config.RoutingConfig{
DetectionWindow: config.NewDuration(10 * time.Minute),
BanWindow: config.NewDuration(50 * time.Minute),
Errors: &config.ErrorsConfig{
Rate: 0.25,
HTTPCodes: []string{
"5xx",
"420",
},
JSONRPCCodes: []string{
"32xxx",
},
ErrorStrings: []string{
"internal server error",
},
},
Latency: &config.LatencyConfig{
MethodLatencyThresholds: map[string]time.Duration{
"eth_call": 10000 * time.Millisecond,
"eth_getLogs": 2000 * time.Millisecond,
},
Threshold: 1000 * time.Millisecond,
Methods: []config.MethodConfig{
{
Name: "eth_getLogs",
Threshold: 2000 * time.Millisecond,
},
{
Name: "eth_call",
Threshold: 10000 * time.Millisecond,
},
},
},
}

type methodNotSupportedError struct{}

func (e methodNotSupportedError) Error() string { return "Method Not Supported." }
Expand Down
2 changes: 1 addition & 1 deletion internal/checks/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

const (
PercentPerFrac = 100
MinNumRequestsForRate = 1 // The minimum number of requests required to compute the error rate.
MinNumRequestsForRate = 4 // The minimum number of requests required to compute the error rate.
)

// NewCircuitBreaker abstracts away the rather complex circuitbreaker.Builder API.
Expand Down
1 change: 1 addition & 0 deletions internal/jsonrpc/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type ResponseBody interface {
GetSubResponses() []SingleResponseBody
}

// SingleResponseBody
// See: http://www.jsonrpc.org/specification#response_object
type SingleResponseBody struct {
Error *Error `json:"error,omitempty"`
Expand Down
4 changes: 3 additions & 1 deletion internal/route/filtering_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func filterUpstreams(
}
}

priorityToHealthyUpstreams[priority] = filteredUpstreams
if len(filteredUpstreams) > 0 {
priorityToHealthyUpstreams[priority] = filteredUpstreams
}
}

return priorityToHealthyUpstreams
Expand Down
Loading

0 comments on commit 0c27246

Please sign in to comment.