Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update toxiproxy.NewProxy signature to support common attributes #418

Merged
merged 1 commit into from Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
@@ -1,6 +1,7 @@
# [Unreleased]

* Support go 1.18, 1.19.
* Support go 1.18, 1.19. (@miry)
* `toxiproxy.NewProxy` now accepts `name`, `listen addr` and `upstream addr`. (#418, @miry)

# [2.4.0] - 2022-03-07

Expand Down
5 changes: 1 addition & 4 deletions api.go
Expand Up @@ -151,10 +151,7 @@ func (server *ApiServer) ProxyCreate(response http.ResponseWriter, request *http
return
}

proxy := NewProxy(server)
proxy.Name = input.Name
proxy.Listen = input.Listen
proxy.Upstream = input.Upstream
proxy := NewProxy(server, input.Name, input.Listen, input.Upstream)

err = server.Collection.Add(proxy, input.Enabled)
if apiError(response, err) {
Expand Down
5 changes: 1 addition & 4 deletions metrics_test.go
Expand Up @@ -19,10 +19,7 @@ func TestProxyMetricsReceivedSentBytes(t *testing.T) {
srv := NewServer(NewMetricsContainer(prometheus.NewRegistry()))
srv.Metrics.ProxyMetrics = collectors.NewProxyMetricCollectors()

proxy := NewProxy(srv)
proxy.Name = "test_proxy_metrics_received_sent_bytes"
proxy.Listen = "localhost:0"
proxy.Upstream = "upstream"
proxy := NewProxy(srv, "test_proxy_metrics_received_sent_bytes", "localhost:0", "upstream")

r := bufio.NewReader(bytes.NewBufferString("hello"))
w := &testWriteCloser{
Expand Down
5 changes: 4 additions & 1 deletion proxy.go
Expand Up @@ -48,8 +48,11 @@ func (c *ConnectionList) Unlock() {

var ErrProxyAlreadyStarted = errors.New("Proxy already started")

func NewProxy(server *ApiServer) *Proxy {
func NewProxy(server *ApiServer, name, listen, upstream string) *Proxy {
proxy := &Proxy{
Name: name,
Listen: listen,
Upstream: upstream,
started: make(chan error),
connections: ConnectionList{list: make(map[string]net.Conn)},
apiServer: server,
Expand Down
5 changes: 1 addition & 4 deletions proxy_collection.go
Expand Up @@ -97,10 +97,7 @@ func (collection *ProxyCollection) PopulateJson(
proxies := make([]*Proxy, 0, len(input))

for i := range input {
proxy := NewProxy(server)
proxy.Name = input[i].Name
proxy.Listen = input[i].Listen
proxy.Upstream = input[i].Upstream
proxy := NewProxy(server, input[i].Name, input[i].Listen, input[i].Upstream)

err = collection.AddOrReplace(proxy, *input[i].Enabled)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions toxics/toxic_test.go
Expand Up @@ -25,11 +25,7 @@ func init() {
func NewTestProxy(name, upstream string) *toxiproxy.Proxy {
srv := toxiproxy.NewServer(toxiproxy.NewMetricsContainer(prometheus.NewRegistry()))
srv.Metrics.ProxyMetrics = collectors.NewProxyMetricCollectors()
proxy := toxiproxy.NewProxy(srv)

proxy.Name = name
proxy.Listen = "localhost:0"
proxy.Upstream = upstream
proxy := toxiproxy.NewProxy(srv, name, "localhost:0", upstream)

return proxy
}
Expand Down
6 changes: 1 addition & 5 deletions toxiproxy_test.go
Expand Up @@ -13,11 +13,7 @@ import (
func NewTestProxy(name, upstream string) *toxiproxy.Proxy {
srv := toxiproxy.NewServer(toxiproxy.NewMetricsContainer(prometheus.NewRegistry()))
srv.Metrics.ProxyMetrics = collectors.NewProxyMetricCollectors()
proxy := toxiproxy.NewProxy(srv)

proxy.Name = name
proxy.Listen = "localhost:0"
proxy.Upstream = upstream
proxy := toxiproxy.NewProxy(srv, name, "localhost:0", upstream)

return proxy
}
Expand Down