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

Set proper service context in client tchannels #781

Merged
merged 2 commits into from
Aug 19, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions runtime/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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,
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions runtime/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/endpoints/baz/baz_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion test/endpoints/tchannel/baz/baz_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down