Skip to content

Commit

Permalink
Merge pull request #574 from uber/lu.l
Browse files Browse the repository at this point in the history
Provide solution to filter log fields by user demand
  • Loading branch information
ChuntaoLu committed Mar 4, 2019
2 parents eba639c + b9af148 commit fcbf945
Show file tree
Hide file tree
Showing 44 changed files with 725 additions and 382 deletions.
42 changes: 30 additions & 12 deletions codegen/template_bundle/template_files.go

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

14 changes: 14 additions & 0 deletions codegen/templates/http_client.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type {{$clientName}} struct {
clientID string
httpClient *zanzibar.HTTPClient
circuitBreakerDisabled bool
requestUUIDHeaderKey string

{{if $sidecarRouter -}}
calleeHeader string
Expand Down Expand Up @@ -80,6 +81,10 @@ func {{$exportName}}(deps *module.Dependencies) Client {
if deps.Default.Config.ContainsKey("clients.{{$clientID}}.defaultHeaders") {
deps.Default.Config.MustGetStruct("clients.{{$clientID}}.defaultHeaders", &defaultHeaders)
}
var requestUUIDHeaderKey string
if deps.Default.Config.ContainsKey("http.clients.requestUUIDHeaderKey") {
requestUUIDHeaderKey = deps.Default.Config.MustGetString("http.clients.requestUUIDHeaderKey")
}


circuitBreakerDisabled := configureCicruitBreaker(deps, timeoutVal)
Expand All @@ -105,6 +110,7 @@ func {{$exportName}}(deps *module.Dependencies) Client {
timeout,
),
circuitBreakerDisabled: circuitBreakerDisabled,
requestUUIDHeaderKey: requestUUIDHeaderKey,
}
}

Expand Down Expand Up @@ -169,6 +175,14 @@ func (c *{{$clientName}}) {{$methodName}}(
r {{.RequestType}},
{{end -}}
) ({{- if ne .ResponseType "" -}} {{.ResponseType}}, {{- end -}}map[string]string, error) {
reqUUID := zanzibar.RequestUUIDFromCtx(ctx)
if reqUUID != "" {
if headers == nil {
headers = make(map[string]string)
}
headers[c.requestUUIDHeaderKey] = reqUUID
}

{{if .ResponseType -}}
var defaultRes {{.ResponseType}}
{{end -}}
Expand Down
19 changes: 12 additions & 7 deletions codegen/templates/tchannel_client.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func {{$exportName}}(deps *module.Dependencies) Client {
if deps.Default.Config.ContainsKey("clients.{{$clientID}}.routingKey") {
routingKey = deps.Default.Config.MustGetString("clients.{{$clientID}}.routingKey")
}
var requestUUIDHeaderKey string
if deps.Default.Config.ContainsKey("tchannel.clients.requestUUIDHeaderKey") {
requestUUIDHeaderKey = deps.Default.Config.MustGetString("tchannel.clients.requestUUIDHeaderKey")
}
sc := deps.Default.Channel.GetSubChannel(serviceName, tchannel.Isolated)

{{if $sidecarRouter -}}
Expand Down Expand Up @@ -111,13 +115,14 @@ func {{$exportName}}(deps *module.Dependencies) Client {
deps.Default.Logger,
deps.Default.ContextMetrics,
&zanzibar.TChannelClientOption{
ServiceName: serviceName,
ClientID: "{{$clientID}}",
MethodNames: methodNames,
Timeout: timeout,
TimeoutPerAttempt: timeoutPerAttempt,
RoutingKey: &routingKey,
AltSubchannelName: scAltName,
ServiceName: serviceName,
ClientID: "{{$clientID}}",
MethodNames: methodNames,
Timeout: timeout,
TimeoutPerAttempt: timeoutPerAttempt,
RoutingKey: &routingKey,
AltSubchannelName: scAltName,
RequestUUIDHeaderKey: requestUUIDHeaderKey,
},
)

Expand Down
3 changes: 1 addition & 2 deletions codegen/templates/workflow_mock.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func New{{$workflowInterface}}Mock(t *testing.T) (workflow.{{$workflowInterface}
Scope: tally.NewTestScope("", make(map[string]string)),
}
initializedDefaultDependencies.ContextLogger = zanzibar.NewContextLogger(initializedDefaultDependencies.Logger)
contextExtractors := &zanzibar.ContextExtractors{}
initializedDefaultDependencies.ContextExtractor = contextExtractors.MakeContextExtractor()
initializedDefaultDependencies.ContextExtractor = &zanzibar.ContextExtractors{}

{{range $idx, $className := $instance.DependencyOrder}}
{{- $moduleInstances := (index $instance.RecursiveDependencies $className)}}
Expand Down
5 changes: 5 additions & 0 deletions examples/example-gateway/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func getRequestTags(ctx context.Context) map[string]string {
func getRequestFields(ctx context.Context) []zap.Field {
var fields []zap.Field
headers := zanzibar.GetEndpointRequestHeadersFromCtx(ctx)
uuid, ok := headers["X-Uuid"]
if !ok {
uuid = headers["x-uuid"]
}
fields = append(fields, zap.String("x-uuid", uuid))
fields = append(fields, zap.String("regionname", headers["Regionname"]))
fields = append(fields, zap.String("device", headers["Device"]))
fields = append(fields, zap.String("deviceversion", headers["Deviceversion"]))
Expand Down

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

0 comments on commit fcbf945

Please sign in to comment.