Skip to content

Commit

Permalink
Add more tags to metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
herainman committed Oct 26, 2018
1 parent c662e77 commit 3b15286
Show file tree
Hide file tree
Showing 157 changed files with 1,099 additions and 814 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Panics in endpoints are now caught (#458). HTTP endpoints return `502` status code with a body `"Unexpected workflow panic, recovered at endpoint."`. TChannel endpoints will return ErrCodeUnexpected.

### Changed
- **BREAKING** Use [`ContextMerics`](https://godoc.org/github.com/uber/zanzibar/runtime#ContextMerics) instead of tally.Scope at [`NewRouterEndpoint`](https://godoc.org/github.com/uber/zanzibar/runtime#NewRouterEndpointContext), [`NewHTTPClient`](https://godoc.org/github.com/uber/zanzibar/runtime#NewHTTPClient), [`NewTChannelClient`](https://godoc.org/github.com/uber/zanzibar/runtime#NewTChannelClient)
- **BREAKING** Use [`ContextMerics`](https://godoc.org/github.com/uber/zanzibar/runtime#ContextMerics) to emit metrics instead of metrics from call_metrics.go.
- **BREAKING** Application packages must now export a global variable named `AppOptions` of type [`*zanzibar.Options`](https://godoc.org/github.com/uber/zanzibar/runtime#Options) to be located at package root (the package defined in `build.json`/`build.yaml`).
- Most built-in logs like `Finished an outgoing client HTTP request` now use the context logger.
- Added [`ContextExtractor`](https://godoc.org/github.com/uber/zanzibar/runtime#ContextExtractor) interface. It is part of the API for dfining "extractors" or functions to pull out dynamic fields like trace ID, request headers, etc. out of the context to be used in log fields and metric tags. These can be used to pull out fields that are application-specific without adding code to zanzibar.
Expand Down
5 changes: 5 additions & 0 deletions benchmarks/contacts_2500KB.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- wrk -t25 -c400 -d3000s -s ./benchmarks/contacts_2500KB.lua http://localhost:8093/contacts/foo/contacts
-- go-torch -u http://localhost:8093/ -t5
wrk.method = "POST"
wrk.body = "{\"userUUID\":\"some-uuid\",\"contacts\":[{\"fragments\":[{\"type\":\"message\",\"text\":\"foobarbaz\"}],\"attributes\":{\"firstName\":\"steve\",\"lastName\":\"stevenson\",\"hasPhoto\":true,\"numFields\":10,\"timesContacted\":5,\"lastTimeContacted\":0,\"isStarred\":false,\"hasCustomRingtone\":false,\"isSendToVoicemail\":false,\"hasThumbnail\":false,\"namePrefix\":\"\",\"nameSuffix\":\"\"}},{\"fragments\":[{\"type\":\"message\",\"text\":\"foobarbaz\"}],\"attributes\":{\"firstName\":\"steve\",\"lastName\":\"stevenson\",\"hasPhoto\":true,\"numFields\":10,\"timesContacted\":5,\"lastTimeContacted\":0,\"isStarred\":false,\"hasCustomRingtone\":false,\"isSendToVoicemail\":false,\"hasThumbnail\":false,\"namePrefix\":\"\",\"nameSuffix\":\"\"}},{\"fragments\":[],\"attributes\":{\"firstName\":\"steve\",\"lastName\":\"stevenson\",\"hasPhoto\":true,\"numFields\":10,\"timesContacted\":5,\"lastTimeContacted\":0,\"isStarred\":false,\"hasCustomRingtone\":false,\"isSendToVoicemail\":false,\"hasThumbnail\":false,\"namePrefix\":\"\",\"nameSuffix\":\"\"}},{\"fragments\":[],\"attributes\":{\"firstName\":\"steve\",\"lastName\":\"stevenson\",\"hasPhoto\":true,\"numFields\":10,\"timesContacted\":5,\"lastTimeContacted\":0,\"isStarred\":false,\"hasCustomRingtone\":false,\"isSendToVoicemail\":false,\"hasThumbnail\":false,\"namePrefix\":\"\",\"nameSuffix\":\"\"}}],\"appType\":\"MY_APP\"}"
wrk.headers["deviceversion"] = math.random()
32 changes: 19 additions & 13 deletions codegen/template_bundle/template_files.go

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

4 changes: 2 additions & 2 deletions codegen/templates/endpoint.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func New{{$handlerName}}(deps *module.Dependencies) *{{$handlerName}} {
Dependencies: deps,
}
handler.endpoint = zanzibar.NewRouterEndpoint(
deps.Default.Logger, deps.Default.Scope, deps.Default.Tracer,
deps.Default.ContextExtractor, deps.Default.ContextMetrics, deps.Default.Logger, deps.Default.Tracer,
"{{$endpointId}}", "{{$handleId}}",
{{ if len $middlewares | ne 0 -}}
zanzibar.NewStack([]zanzibar.MiddlewareHandle{
Expand Down Expand Up @@ -114,7 +114,7 @@ func (h *{{$handlerName}}) HandleRequest(
zap.String("stacktrace", stacktrace),
zap.String("endpoint", h.endpoint.EndpointName))

h.endpoint.Metrics.Panic.Inc(1)
h.endpoint.ContextMetrics.IncCounter(ctx, zanzibar.InboundCallsPanic, 1)
res.SendError(502, "Unexpected workflow panic, recovered at endpoint.", nil)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion codegen/templates/http_client.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func {{$exportName}}(deps *module.Dependencies) Client {
calleeName: calleeName,
{{end -}}
httpClient: zanzibar.NewHTTPClient(
deps.Default.Logger, deps.Default.Scope,
deps.Default.Logger, deps.Default.ContextMetrics,
"{{$clientID}}",
[]string{
{{range $serviceMethod, $methodName := $exposedMethods -}}
Expand Down
2 changes: 2 additions & 0 deletions codegen/templates/module_initializer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ func InitializeDependencies(

initializedDefaultDependencies := &zanzibar.DefaultDependencies{
Logger: g.Logger,
ContextExtractor: g.ContextExtractor,
ContextLogger: g.ContextLogger,
ContextMetrics: zanzibar.NewContextMetrics(g.AllHostScope),
Scope: g.AllHostScope,
Tracer: g.Tracer,
Config: g.Config,
Expand Down
2 changes: 2 additions & 0 deletions codegen/templates/module_mock_initializer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func InitializeDependenciesMock(
{{ end -}}

initializedDefaultDependencies := &zanzibar.DefaultDependencies{
ContextExtractor: g.ContextExtractor,
ContextMetrics: g.ContextMetrics,
ContextLogger: g.ContextLogger,
Logger: g.Logger,
Scope: g.AllHostScope,
Expand Down
2 changes: 1 addition & 1 deletion codegen/templates/tchannel_client.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func {{$exportName}}(deps *module.Dependencies) Client {
client := zanzibar.NewTChannelClient(
deps.Default.Channel,
deps.Default.Logger,
deps.Default.Scope,
deps.Default.ContextMetrics,
&zanzibar.TChannelClientOption{
ServiceName: serviceName,
ClientID: "{{$clientID}}",
Expand Down
4 changes: 2 additions & 2 deletions codegen/templates/tchannel_endpoint.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (h *{{$handlerName}}) Handle(
zap.String("stacktrace", stacktrace),
zap.String("endpoint", h.endpoint.EndpointID))

h.endpoint.Metrics.Panic.Inc(1)
h.endpoint.ContextMetrics.IncCounter(ctx, zanzibar.InboundCallsPanic, 1)
isSuccessful = false
response = nil
headers = nil
Expand Down Expand Up @@ -242,7 +242,7 @@ func (h *{{$handlerName}}) redirectToDeputy(
client := zanzibar.NewTChannelClient(
h.Deps.Default.Channel,
h.Deps.Default.Logger,
h.Deps.Default.Scope,
h.Deps.Default.ContextMetrics,
&zanzibar.TChannelClientOption{
ServiceName: serviceName,
ClientID: "{{$clientID}}",
Expand Down
2 changes: 2 additions & 0 deletions codegen/templates/workflow_mock.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func New{{$workflowInterface}}Mock(t *testing.T) (workflow.{{$workflowInterface}
Logger: zap.NewNop(),
}
initializedDefaultDependencies.ContextLogger = zanzibar.NewContextLogger(initializedDefaultDependencies.Logger)
contextExtractors := &zanzibar.ContextExtractors{}
initializedDefaultDependencies.ContextExtractor = contextExtractors.MakeContextExtractor()

{{range $idx, $className := $instance.DependencyOrder}}
{{- $moduleInstances := (index $instance.RecursiveDependencies $className)}}
Expand Down
5 changes: 3 additions & 2 deletions codegen/test_data/clients/bar.gogen
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ import (
"time"

"github.com/pkg/errors"
zanzibar "github.com/uber/zanzibar/runtime"

module "github.com/uber/zanzibar/.tmp_gen/clients/bar/module"
clientsBarBar "github.com/uber/zanzibar/examples/example-gateway/build/gen-code/clients/bar/bar"
clientsFooFoo "github.com/uber/zanzibar/examples/example-gateway/build/gen-code/clients/foo/foo"
zanzibar "github.com/uber/zanzibar/runtime"
)

// Client defines bar client interface.
Expand Down Expand Up @@ -210,7 +211,7 @@ func NewClient(deps *module.Dependencies) Client {
return &barClient{
clientID: "bar",
httpClient: zanzibar.NewHTTPClient(
deps.Default.Logger, deps.Default.Scope,
deps.Default.Logger, deps.Default.ContextMetrics,
"bar",
[]string{
"ArgNotStruct",
Expand Down
12 changes: 7 additions & 5 deletions codegen/test_data/endpoints/bar_bar_method_argnotstruct.gogen
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import (

"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
module "github.com/uber/zanzibar/.tmp_gen/endpoints/bar/module"
workflow "github.com/uber/zanzibar/.tmp_gen/endpoints/bar/workflow"
endpointsBarBar "github.com/uber/zanzibar/examples/example-gateway/build/gen-code/endpoints/bar/bar"
zanzibar "github.com/uber/zanzibar/runtime"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

workflow "github.com/uber/zanzibar/.tmp_gen/endpoints/bar/workflow"
endpointsBarBar "github.com/uber/zanzibar/examples/example-gateway/build/gen-code/endpoints/bar/bar"

module "github.com/uber/zanzibar/.tmp_gen/endpoints/bar/module"
)

// BarArgNotStructHandler is the handler for "/bar/arg-not-struct-path"
Expand All @@ -50,7 +52,7 @@ func NewBarArgNotStructHandler(deps *module.Dependencies) *BarArgNotStructHandle
Dependencies: deps,
}
handler.endpoint = zanzibar.NewRouterEndpoint(
deps.Default.Logger, deps.Default.Scope, deps.Default.Tracer,
deps.Default.ContextExtractor, deps.Default.ContextMetrics, deps.Default.Logger, deps.Default.Tracer,
"bar", "argNotStruct",
handler.HandleRequest,
)
Expand Down Expand Up @@ -83,7 +85,7 @@ func (h *BarArgNotStructHandler) HandleRequest(
zap.String("stacktrace", stacktrace),
zap.String("endpoint", h.endpoint.EndpointName))

h.endpoint.Metrics.Panic.Inc(1)
h.endpoint.ContextMetrics.IncCounter(ctx, zanzibar.InboundCallsPanic, 1)
res.SendError(502, "Unexpected workflow panic, recovered at endpoint.", nil)
}
}()
Expand Down
12 changes: 7 additions & 5 deletions codegen/test_data/endpoints/bar_bar_method_argwithheaders.gogen
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ import (

"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
module "github.com/uber/zanzibar/.tmp_gen/endpoints/bar/module"
workflow "github.com/uber/zanzibar/.tmp_gen/endpoints/bar/workflow"
endpointsBarBar "github.com/uber/zanzibar/examples/example-gateway/build/gen-code/endpoints/bar/bar"
zanzibar "github.com/uber/zanzibar/runtime"
"go.uber.org/thriftrw/ptr"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

workflow "github.com/uber/zanzibar/.tmp_gen/endpoints/bar/workflow"
endpointsBarBar "github.com/uber/zanzibar/examples/example-gateway/build/gen-code/endpoints/bar/bar"

module "github.com/uber/zanzibar/.tmp_gen/endpoints/bar/module"
)

// BarArgWithHeadersHandler is the handler for "/bar/argWithHeaders"
Expand All @@ -52,7 +54,7 @@ func NewBarArgWithHeadersHandler(deps *module.Dependencies) *BarArgWithHeadersHa
Dependencies: deps,
}
handler.endpoint = zanzibar.NewRouterEndpoint(
deps.Default.Logger, deps.Default.Scope, deps.Default.Tracer,
deps.Default.ContextExtractor, deps.Default.ContextMetrics, deps.Default.Logger, deps.Default.Tracer,
"bar", "argWithHeaders",
handler.HandleRequest,
)
Expand Down Expand Up @@ -85,7 +87,7 @@ func (h *BarArgWithHeadersHandler) HandleRequest(
zap.String("stacktrace", stacktrace),
zap.String("endpoint", h.endpoint.EndpointName))

h.endpoint.Metrics.Panic.Inc(1)
h.endpoint.ContextMetrics.IncCounter(ctx, zanzibar.InboundCallsPanic, 1)
res.SendError(502, "Unexpected workflow panic, recovered at endpoint.", nil)
}
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ import (

"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
module "github.com/uber/zanzibar/.tmp_gen/endpoints/bar/module"
workflow "github.com/uber/zanzibar/.tmp_gen/endpoints/bar/workflow"
endpointsBarBar "github.com/uber/zanzibar/examples/example-gateway/build/gen-code/endpoints/bar/bar"
zanzibar "github.com/uber/zanzibar/runtime"
"go.uber.org/thriftrw/ptr"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"

workflow "github.com/uber/zanzibar/.tmp_gen/endpoints/bar/workflow"
endpointsBarBar "github.com/uber/zanzibar/examples/example-gateway/build/gen-code/endpoints/bar/bar"

module "github.com/uber/zanzibar/.tmp_gen/endpoints/bar/module"
)

// BarArgWithManyQueryParamsHandler is the handler for "/bar/argWithManyQueryParams"
Expand All @@ -52,7 +54,7 @@ func NewBarArgWithManyQueryParamsHandler(deps *module.Dependencies) *BarArgWithM
Dependencies: deps,
}
handler.endpoint = zanzibar.NewRouterEndpoint(
deps.Default.Logger, deps.Default.Scope, deps.Default.Tracer,
deps.Default.ContextExtractor, deps.Default.ContextMetrics, deps.Default.Logger, deps.Default.Tracer,
"bar", "argWithManyQueryParams",
handler.HandleRequest,
)
Expand Down Expand Up @@ -85,7 +87,7 @@ func (h *BarArgWithManyQueryParamsHandler) HandleRequest(
zap.String("stacktrace", stacktrace),
zap.String("endpoint", h.endpoint.EndpointName))

h.endpoint.Metrics.Panic.Inc(1)
h.endpoint.ContextMetrics.IncCounter(ctx, zanzibar.InboundCallsPanic, 1)
res.SendError(502, "Unexpected workflow panic, recovered at endpoint.", nil)
}
}()
Expand Down
Loading

0 comments on commit 3b15286

Please sign in to comment.