Skip to content

Commit

Permalink
Merge pull request #935 from uber/altServiceName
Browse files Browse the repository at this point in the history
Fix capture service name to accommodate alternate service detail
  • Loading branch information
shivam-srivastava28 authored Jun 27, 2024
2 parents 469a97c + e41ce73 commit 8d71902
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions runtime/tchannel_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ func (c *TChannelClient) call(
if sk != "" {
ctxBuilder.SetShardKey(sk)
}
serviceName := ""

ctx, cancel := ctxBuilder.Build()
defer cancel()
Expand All @@ -242,7 +243,8 @@ func (c *TChannelClient) call(
call.resHeaders = map[string]string{}
call.success = false

sc, ctx := c.getDynamicChannelWithFallback(reqHeaders, c.sc, ctx)
sc, ctx, altService := c.getDynamicChannelWithFallback(reqHeaders, c.sc, ctx, c.serviceName)
serviceName = altService
call.call, cerr = sc.BeginCall(ctx, call.serviceMethod, &tchannel.CallOptions{
Format: tchannel.Thrift,
ShardKey: GetShardKeyFromCtx(ctx),
Expand Down Expand Up @@ -294,7 +296,7 @@ func (c *TChannelClient) call(
if GetToCapture(ctx) {
event := &ThriftOutgoingEvent{
MethodName: call.serviceMethod,
ServiceName: c.serviceName,
ServiceName: serviceName,
ReqHeaders: call.reqHeaders,
Req: req,
RspHeaders: call.resHeaders,
Expand All @@ -312,10 +314,10 @@ func (c *TChannelClient) call(

// first rule match, would be the chosen channel. if nothing matches fallback to default channel
func (c *TChannelClient) getDynamicChannelWithFallback(reqHeaders map[string]string,
sc *tchannel.SubChannel, ctx netContext.Context) (*tchannel.SubChannel, netContext.Context) {
sc *tchannel.SubChannel, ctx netContext.Context, serviceName string) (*tchannel.SubChannel, netContext.Context, string) {
ch := sc
if c.ruleEngine == nil {
return ch, ctx
return ch, ctx, serviceName
}
for _, headerPattern := range c.headerPatterns {
// this header is not present, so can't match a rule
Expand All @@ -334,8 +336,8 @@ func (c *TChannelClient) getDynamicChannelWithFallback(reqHeaders map[string]str
if len(serviceDetails) > 1 {
ctx = WithRoutingDelegate(ctx, serviceDetails[1])
}
return ch, ctx
return ch, ctx, serviceDetails[0]
}
// if nothing matches return the default channel/**/
return ch, ctx
return ch, ctx, serviceName
}

0 comments on commit 8d71902

Please sign in to comment.