Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #174 from 0xProject/marcin/params
Browse files Browse the repository at this point in the history
Inconsistent config practices
  • Loading branch information
eitu5ami authored Feb 20, 2024
2 parents da2b86a + 61cf4c3 commit 3249f8d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
7 changes: 4 additions & 3 deletions internal/proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ type ProxyConfig struct { // nolint:revive

// This struct is temporary. It's about to keep the input interface clean and simple.
type Config struct {
Proxy ProxyConfig
Targets []NodeProviderConfig
HealthChecks HealthCheckConfig
Proxy ProxyConfig
Targets []NodeProviderConfig
HealthChecks HealthCheckConfig
HealthcheckManager *HealthCheckManager
}
4 changes: 2 additions & 2 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ type Proxy struct {
metricResponseStatus *prometheus.CounterVec
}

func NewProxy(config Config, hcm *HealthCheckManager) *Proxy {
func NewProxy(config Config) *Proxy {
proxy := &Proxy{
hcm: hcm,
hcm: config.HealthcheckManager,
timeout: config.Proxy.UpstreamTimeout,
metricRequestDuration: promauto.NewHistogramVec(
prometheus.HistogramOpts{
Expand Down
13 changes: 8 additions & 5 deletions internal/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ func TestHttpFailoverProxyRerouteRequests(t *testing.T) {
Config: rpcGatewayConfig.HealthChecks,
Logger: slog.New(slog.NewTextHandler(os.Stderr, nil)),
})
rpcGatewayConfig.HealthcheckManager = healthcheckManager

// Setup HttpFailoverProxy but not starting the HealthCheckManager
// so the no target will be tainted or marked as unhealthy by the HealthCheckManager
// the failoverProxy should automatically reroute the request to the second RPC Server by itself
httpFailoverProxy := NewProxy(rpcGatewayConfig, healthcheckManager)
httpFailoverProxy := NewProxy(rpcGatewayConfig)

requestBody := bytes.NewBufferString(`{"this_is": "body"}`)
req, err := http.NewRequest(http.MethodPost, "/", requestBody)
Expand Down Expand Up @@ -123,9 +124,10 @@ func TestHttpFailoverProxyDecompressRequest(t *testing.T) {
Config: rpcGatewayConfig.HealthChecks,
Logger: slog.New(slog.NewTextHandler(os.Stderr, nil)),
})
rpcGatewayConfig.HealthcheckManager = healthcheckManager
// Setup HttpFailoverProxy but not starting the HealthCheckManager
// so the no target will be tainted or marked as unhealthy by the HealthCheckManager
httpFailoverProxy := NewProxy(rpcGatewayConfig, healthcheckManager)
httpFailoverProxy := NewProxy(rpcGatewayConfig)

var buf bytes.Buffer
g := gzip.NewWriter(&buf)
Expand Down Expand Up @@ -178,9 +180,10 @@ func TestHttpFailoverProxyWithCompressionSupportedTarget(t *testing.T) {
Config: rpcGatewayConfig.HealthChecks,
Logger: slog.New(slog.NewTextHandler(os.Stderr, nil)),
})
rpcGatewayConfig.HealthcheckManager = healthcheckManager
// Setup HttpFailoverProxy but not starting the HealthCheckManager
// so the no target will be tainted or marked as unhealthy by the HealthCheckManager
httpFailoverProxy := NewProxy(rpcGatewayConfig, healthcheckManager)
httpFailoverProxy := NewProxy(rpcGatewayConfig)

var buf bytes.Buffer
g := gzip.NewWriter(&buf)
Expand Down Expand Up @@ -243,13 +246,13 @@ func TestHTTPFailoverProxyWhenCannotConnectToPrimaryProvider(t *testing.T) {
Config: rpcGatewayConfig.HealthChecks,
Logger: slog.New(slog.NewTextHandler(os.Stderr, nil)),
})

rpcGatewayConfig.HealthcheckManager = healthcheckManager
// Setup HttpFailoverProxy but not starting the HealthCheckManager so the
// no target will be tainted or marked as unhealthy by the
// HealthCheckManager the failoverProxy should automatically reroute the
// request to the second RPC Server by itself

httpFailoverProxy := NewProxy(rpcGatewayConfig, healthcheckManager)
httpFailoverProxy := NewProxy(rpcGatewayConfig)

requestBody := bytes.NewBufferString(`{"this_is": "body"}`)
req, err := http.NewRequest(http.MethodPost, "/", requestBody)
Expand Down
8 changes: 4 additions & 4 deletions internal/rpcgateway/rpcgateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ func NewRPCGateway(config RPCGatewayConfig) *RPCGateway {
})
proxy := proxy.NewProxy(
proxy.Config{
Proxy: config.Proxy,
Targets: config.Targets,
HealthChecks: config.HealthChecks,
Proxy: config.Proxy,
Targets: config.Targets,
HealthChecks: config.HealthChecks,
HealthcheckManager: hcm,
},
hcm,
)

r := chi.NewRouter()
Expand Down

0 comments on commit 3249f8d

Please sign in to comment.