Skip to content

Commit

Permalink
Registering optional fields and tags with tchannel server endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ravirajj committed Oct 3, 2017
1 parent e981978 commit 2c0233b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions codegen/template_bundle/template_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codegen/templates/tchannel_endpoint.tmpl
Expand Up @@ -43,7 +43,7 @@ type {{$handlerName}} struct {
func (h *{{$handlerName}}) Register(g *zanzibar.Gateway) error {
h.endpoint = g.TChannelRouter.Register(
"{{$spec.EndpointID}}", "{{$spec.HandleID}}", "{{.ThriftService}}::{{.Name}}",
h,
h, nil, nil,
)
// TODO: Register should return an error for route conflicts
return nil
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 21 additions & 13 deletions runtime/tchannel_server.go
Expand Up @@ -98,34 +98,42 @@ func NewTChannelRouter(registrar tchannel.Registrar, g *Gateway) *TChannelRouter
func (s *TChannelRouter) Register(
endpointID, handlerID, method string,
h TChannelHandler,
fields []zapcore.Field,
tags map[string]string,
) *TChannelEndpoint {
return s.RegisterWithPostResponseCB(endpointID, handlerID, method, h, nil)
return s.RegisterWithPostResponseCB(endpointID, handlerID, method, h, fields, tags, nil)
}

// RegisterWithPostResponseCB registers the given TChannelHandler with a PostResponseCB function
func (s *TChannelRouter) RegisterWithPostResponseCB(
endpointID, handlerID, method string,
h TChannelHandler,
fields []zapcore.Field,
tags map[string]string,
cb PostResponseCB,
) *TChannelEndpoint {
logger := s.logger.With(
zap.String("endpointID", endpointID),
zap.String("handlerID", endpointID),
zap.String("method", method),
)
scope := s.scope.Tagged(map[string]string{
"endpoint": endpointID,
"handler": handlerID,
"method": method,
})
if fields == nil {
fields = make([]zapcore.Field, 0, 3)
}
fields = append(fields, zap.String("endpointID", endpointID))
fields = append(fields, zap.String("handlerID", handlerID))
fields = append(fields, zap.String("method", method))

if tags == nil {
tags = make(map[string]string, 3)
}
tags["endpoint"] = endpointID
tags["handler"] = handlerID
tags["method"] = method

endpoint := TChannelEndpoint{
EndpointID: endpointID,
HandlerID: handlerID,
Method: method,
handler: h,
postResponseCB: cb,
Logger: logger,
metrics: NewInboundTChannelMetrics(scope),
Logger: s.logger.With(fields...),
metrics: NewInboundTChannelMetrics(s.scope.Tagged(tags)),
}
s.register(&endpoint)
return &endpoint
Expand Down
Expand Up @@ -109,7 +109,7 @@ func TestCallTChannelSuccessfulRequestOKResponse(t *testing.T) {
assert.Equal(t, "info", tags["level"])
assert.Equal(t, "Finished an incoming server TChannel request", tags["msg"])
assert.Equal(t, "bazTChannel", tags["endpointID"])
assert.Equal(t, "bazTChannel", tags["handlerID"])
assert.Equal(t, "call", tags["handlerID"])
assert.Equal(t, "SimpleService::Call", tags["method"])
assert.Equal(t, "token", tags["Request-Header-x-token"])
assert.Equal(t, "uuid", tags["Request-Header-x-uuid"])
Expand Down
2 changes: 1 addition & 1 deletion test/lib/test_backend/test_tchannel_backend.go
Expand Up @@ -103,7 +103,7 @@ func (backend *TestTChannelBackend) Register(
endpointID, handlerID, method string,
handler zanzibar.TChannelHandler,
) {
backend.Router.Register(endpointID, handlerID, method, handler)
backend.Router.Register(endpointID, handlerID, method, handler, nil, nil)
}

// Close closes the underlying channel
Expand Down

0 comments on commit 2c0233b

Please sign in to comment.