diff --git a/runtime/gateway.go b/runtime/gateway.go index 346256ea0..0c5fe5e66 100644 --- a/runtime/gateway.go +++ b/runtime/gateway.go @@ -829,9 +829,9 @@ func (gateway *Gateway) setupServerTChannel(config *StaticConfig) error { } // SetupClientTChannel sets up a dedicated tchannel for each client with a given service name -// If multiple backends with the same service name exist (for e.g presentation service), then -// all of them would receive the same channel. The method is exported because it is called -// from the generated clients if "dedicated.tchannel.client: true" +// If multiple backends with the same service name exist (for e.g. presentation service), then +// all of them would receive the same channel. The method is exported because it is called from +// the generated clients if "dedicated.tchannel.client: true" else server tchannel is reused func (gateway *Gateway) SetupClientTChannel(config *StaticConfig, serviceName string) *tchannel.Channel { if ch, ok := gateway.ClientTChannels[serviceName]; ok { gateway.Logger.Info(fmt.Sprintf("returning already initialised TChannel client for [%v]", serviceName)) @@ -841,7 +841,9 @@ func (gateway *Gateway) SetupClientTChannel(config *StaticConfig, serviceName st level := gateway.TChannelSubLoggerLevel channel, err := tchannel.NewChannel( - serviceName, + // when specifying the service name for the channel, we reuse the server service + // name else calls from other unauthorised sources may be blocked + config.MustGetString("tchannel.serviceName"), &tchannel.ChannelOptions{ ProcessName: processName, Tracer: gateway.Tracer, @@ -854,8 +856,9 @@ func (gateway *Gateway) SetupClientTChannel(config *StaticConfig, serviceName st }) if err != nil { scope.Gauge("tchannel.client.running").Update(0) - gateway.Logger.Info(fmt.Sprintf("failed to initialise TChannel client for [%v]", serviceName)) + gateway.Logger.Info(fmt.Sprintf("Failed to initiate dedicated TChannel client for [%v]", serviceName)) } else { + gateway.Logger.Info(fmt.Sprintf("Dedicated TChannel client initiated for client [%v]", serviceName)) scope.Gauge("tchannel.client.running").Update(1) } gateway.ClientTChannels[serviceName] = channel diff --git a/runtime/gateway_test.go b/runtime/gateway_test.go index 1d0229527..a6993217d 100644 --- a/runtime/gateway_test.go +++ b/runtime/gateway_test.go @@ -143,6 +143,7 @@ func TestGatewaySetupClientTChannelWhenServiceNameAlreadyExists(t *testing.T) { func TestGatewaySetupClientTChannel(t *testing.T) { cfg := NewStaticConfigOrDie(nil, map[string]interface{}{ "tchannel.processName": "test-proc", + "tchannel.serviceName": "test-gateway", }) g := Gateway{ TChannelSubLoggerLevel: zapcore.ErrorLevel, diff --git a/test/endpoints/baz/baz_metrics_test.go b/test/endpoints/baz/baz_metrics_test.go index 2176d48a2..b49a91e2c 100644 --- a/test/endpoints/baz/baz_metrics_test.go +++ b/test/endpoints/baz/baz_metrics_test.go @@ -168,7 +168,7 @@ func TestCallMetrics(t *testing.T) { tchannelTags := map[string]string{ "env": "test", "app": "test-gateway", - "service": "bazService", + "service": "test-gateway", "target-service": "bazService", "target-endpoint": "SimpleService__call", "host": zanzibar.GetHostname(), diff --git a/test/endpoints/tchannel/baz/baz_metrics_test.go b/test/endpoints/tchannel/baz/baz_metrics_test.go index 189d92100..5de0c693c 100644 --- a/test/endpoints/tchannel/baz/baz_metrics_test.go +++ b/test/endpoints/tchannel/baz/baz_metrics_test.go @@ -168,7 +168,7 @@ func TestCallMetrics(t *testing.T) { // this host tag is added by tchannel library, which we don't have control with "host": zanzibar.GetHostname(), "env": "test", - "service": "bazService", + "service": "test-gateway", "target-endpoint": "SimpleService__call", "target-service": "bazService", "dc": "unknown",