Skip to content

Commit

Permalink
Merge 6581917 into 68c6199
Browse files Browse the repository at this point in the history
  • Loading branch information
herainman committed Aug 16, 2018
2 parents 68c6199 + 6581917 commit 634bcdf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions runtime/context.go
Expand Up @@ -29,10 +29,17 @@ import (
type contextFieldKey string

const (
endpointKey = contextFieldKey("endpoint")
requestUUIDKey = contextFieldKey("requestUUID")
routingDelegateKey = contextFieldKey("rd")
)

// withEndpointFields adds the endpoint information in the
// request context.
func withEndpointField(ctx context.Context, endpoint string) context.Context {
return context.WithValue(ctx, endpointKey, endpoint)
}

// withRequestFields annotates zanzibar request context to context.Context. In
// future, we can use a request context struct to add more context in terms of
// request handler, etc if need be.
Expand Down
11 changes: 11 additions & 0 deletions runtime/context_test.go
Expand Up @@ -28,6 +28,17 @@ import (
"github.com/stretchr/testify/assert"
)

func TestWithEndpointFields(t *testing.T) {
expected := "someEndpoint"
ctx := withEndpointField(context.TODO(), expected)

ek := ctx.Value(endpointKey)
endpoint, ok := ek.(string)

assert.True(t, ok)
assert.Equal(t, endpoint, expected)
}

func TestWithRequestFields(t *testing.T) {
ctx := withRequestFields(context.TODO())

Expand Down
1 change: 1 addition & 0 deletions runtime/router.go
Expand Up @@ -99,6 +99,7 @@ func (endpoint *RouterEndpoint) HandleRequest(
// defer cancel()
//}
ctx := withRequestFields(r.Context())
ctx = withEndpointField(ctx, endpoint.EndpointName)

endpoint.HandlerFn(ctx, req, req.res)
req.res.flush()
Expand Down
2 changes: 2 additions & 0 deletions runtime/tchannel_server.go
Expand Up @@ -175,6 +175,8 @@ func (s *TChannelRouter) Handle(ctx context.Context, call *tchannel.InboundCall)
return
}

ctx = withEndpointField(ctx, e.EndpointID)

var err error
errc := make(chan error, 1)
c := tchannelInboundCall{
Expand Down

0 comments on commit 634bcdf

Please sign in to comment.