Skip to content

Commit

Permalink
Fix public client default value after xdc switching to gRPC
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng authored Oct 11, 2021
1 parent 9ff3eb3 commit aa9e7a5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/server/cadence/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build !race
// +build !race

package cadence
Expand Down
19 changes: 16 additions & 3 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"encoding/json"
"fmt"
"log"
"net"
"time"

"github.com/uber-go/tally/m3"
Expand Down Expand Up @@ -122,7 +123,7 @@ type (

// RPC contains the rpc config items
RPC struct {
// Port is the port on which the channel will bind to
// Port is the port on which the Thrift TChannel will bind to
Port int `yaml:"port"`
// GRPCPort is the port on which the grpc listener will bind to
GRPCPort int `yaml:"grpcPort"`
Expand Down Expand Up @@ -501,7 +502,7 @@ func (c *Config) validate() error {
func (c *Config) fillDefaults() {
c.Persistence.FillDefaults()

// TODO: remove this after 0.23 and mention a breaking change in config.
// TODO: remove this at the point when we decided to make some breaking changes in config.
if c.ClusterGroupMetadata == nil && c.ClusterMetadata != nil {
c.ClusterGroupMetadata = c.ClusterMetadata
log.Println("[WARN] clusterMetadata config is deprecated. Please replace it with clusterGroupMetadata.")
Expand All @@ -512,7 +513,19 @@ func (c *Config) fillDefaults() {
// filling publicClient with current cluster's RPC address if empty
if c.PublicClient.HostPort == "" && c.ClusterGroupMetadata != nil {
name := c.ClusterGroupMetadata.CurrentClusterName
c.PublicClient.HostPort = c.ClusterGroupMetadata.ClusterGroup[name].RPCAddress
currentCluster := c.ClusterGroupMetadata.ClusterGroup[name]
if currentCluster.RPCTransport != "grpc" {
c.PublicClient.HostPort = currentCluster.RPCAddress
} else {
// public client cannot use gRPC because GoSDK hasn't supported it. we need to fallback to Thrift
// TODO: remove this fallback after GoSDK supporting gRPC
thriftPort := c.Services["frontend"].RPC.Port // use the Thrift port from RPC config
host, _, err := net.SplitHostPort(currentCluster.RPCAddress)
if err != nil {
log.Fatalf("RPCAddress is invalid for cluster %v", name)
}
c.PublicClient.HostPort = fmt.Sprintf("%v:%v", host, thriftPort)
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion common/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ func TestInvalidMultipleDatabaseConfig_nonEmptySQLConnAddr(t *testing.T) {
func TestConfigFallbacks(t *testing.T) {
metadata := validClusterGroupMetadata()
cfg := &Config{
Services: map[string]Service{
"frontend": {
RPC: RPC{
Port: 7900,
},
},
},
ClusterGroupMetadata: metadata,
Persistence: Persistence{
DefaultStore: "default",
Expand Down Expand Up @@ -191,7 +198,7 @@ func TestConfigFallbacks(t *testing.T) {
assert.NotEmpty(t, cfg.Persistence.DataStores["cass"].Cassandra, "cassandra config should remain after update")
assert.NotEmpty(t, cfg.Persistence.DataStores["cass"].NoSQL, "nosql config should contain cassandra config / not be empty")
assert.NotZero(t, cfg.Persistence.DataStores["default"].SQL.NumShards, "num shards should be nonzero")
assert.Equal(t, metadata.ClusterGroup[metadata.CurrentClusterName].RPCAddress, cfg.PublicClient.HostPort)
assert.Equal(t, "localhost:7900", cfg.PublicClient.HostPort)
}

func TestConfigErrorInAuthorizationConfig(t *testing.T) {
Expand Down

0 comments on commit aa9e7a5

Please sign in to comment.