diff --git a/common/membership/config.go b/common/membership/config.go deleted file mode 100644 index ca20d3e5b57..00000000000 --- a/common/membership/config.go +++ /dev/null @@ -1,40 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package membership - -import ( - "fmt" - "net" - - "go.temporal.io/server/common/config" -) - -// ValidateConfig validates that the membership config is parseable and valid -func ValidateConfig(cfg *config.Membership) error { - if cfg.BroadcastAddress != "" && net.ParseIP(cfg.BroadcastAddress) == nil { - return fmt.Errorf("ringpop config malformed `broadcastAddress` param") - } - return nil -} diff --git a/common/membership/config_test.go b/common/membership/config_test.go deleted file mode 100644 index 3b0503aef94..00000000000 --- a/common/membership/config_test.go +++ /dev/null @@ -1,42 +0,0 @@ -// The MIT License -// -// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. -// -// Copyright (c) 2020 Uber Technologies, Inc. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -package membership - -import ( - "testing" - "time" - - "github.com/stretchr/testify/assert" - - "go.temporal.io/server/common/config" -) - -func TestInvalidConfig(t *testing.T) { - var cfg config.Membership - cfg.MaxJoinDuration = time.Minute - assert.NoError(t, ValidateConfig(&cfg)) - cfg.BroadcastAddress = "sjhdfskdjhf" - assert.Error(t, ValidateConfig(&cfg)) -} diff --git a/common/membership/ringpop/factory.go b/common/membership/ringpop/factory.go index f01253c3548..477ea72aeec 100644 --- a/common/membership/ringpop/factory.go +++ b/common/membership/ringpop/factory.go @@ -27,6 +27,7 @@ package ringpop import ( "context" "crypto/tls" + "errors" "fmt" "net" "sync" @@ -70,6 +71,8 @@ type factory struct { monOnce sync.Once } +var errMalformedBroadcastAddress = errors.New("ringpop config malformed `broadcastAddress` param") + // newFactory builds a ringpop factory conforming // to the underlying configuration func newFactory( @@ -82,8 +85,8 @@ func newFactory( tlsProvider encryption.TLSConfigProvider, dc *dynamicconfig.Collection, ) (*factory, error) { - if err := membership.ValidateConfig(rpConfig); err != nil { - return nil, err + if rpConfig.BroadcastAddress != "" && net.ParseIP(rpConfig.BroadcastAddress) == nil { + return nil, fmt.Errorf("%w: %s", errMalformedBroadcastAddress, rpConfig.BroadcastAddress) } if rpConfig.MaxJoinDuration == 0 { rpConfig.MaxJoinDuration = defaultMaxJoinDuration diff --git a/common/membership/ringpop/factory_test.go b/common/membership/ringpop/factory_test.go index 878a0ee584a..a2a9142eba6 100644 --- a/common/membership/ringpop/factory_test.go +++ b/common/membership/ringpop/factory_test.go @@ -39,7 +39,6 @@ import ( "go.temporal.io/server/common/config" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" - "go.temporal.io/server/common/membership" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/primitives" "go.temporal.io/server/common/rpc/encryption" @@ -138,8 +137,6 @@ func (s *RingpopSuite) TestHostsMode() { s.Nil(err) s.Equal("1.2.3.4", cfg.BroadcastAddress) s.Equal(time.Second*30, cfg.MaxJoinDuration) - err = membership.ValidateConfig(&cfg) - s.Nil(err) f, err := newFactory(&cfg, "test", nil, log.NewNoopLogger(), nil, nil, nil, nil) s.Nil(err) s.NotNil(f) @@ -151,6 +148,25 @@ broadcastAddress: "1.2.3.4" maxJoinDuration: 30s` } +func (s *RingpopSuite) TestInvalidBroadcastAddress() { + cfg := config.Membership{ + MaxJoinDuration: time.Minute, + BroadcastAddress: "oopsie", + } + _, err := newFactory( + &cfg, + "test", + nil, + log.NewNoopLogger(), + nil, + nil, + nil, + nil, + ) + s.ErrorIs(err, errMalformedBroadcastAddress) + s.ErrorContains(err, "oopsie") +} + func newTestRingpopFactory( serviceName primitives.ServiceName, logger log.Logger, diff --git a/temporal/fx.go b/temporal/fx.go index a9429731696..10de3e3ddb5 100644 --- a/temporal/fx.go +++ b/temporal/fx.go @@ -52,7 +52,6 @@ import ( "go.temporal.io/server/common/headers" "go.temporal.io/server/common/log" "go.temporal.io/server/common/log/tag" - "go.temporal.io/server/common/membership" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/persistence" "go.temporal.io/server/common/persistence/cassandra" @@ -169,11 +168,6 @@ func ServerOptionsProvider(opts []ServerOption) (serverOptionsProvider, error) { return serverOptionsProvider{}, err } - err = membership.ValidateConfig(&so.config.Global.Membership) - if err != nil { - return serverOptionsProvider{}, fmt.Errorf("ringpop config validation error: %w", err) - } - stopChan := make(chan interface{}) // Logger