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

Fix capture service name to accommodate alternate service detail #935

Merged
merged 2 commits into from
Jun 27, 2024
Merged
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
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
}
Loading