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

Support tracer env based initialization in hotrod #1115

Merged
Merged
Show file tree
Hide file tree
Changes from 7 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
5 changes: 3 additions & 2 deletions examples/hotrod/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ go run ./main.go all
docker run \
--rm \
--link jaeger \
--env JAEGER_AGENT_HOST=jaeger \
--env JAEGER_AGENT_PORT=6831 \
-p8080-8083:8080-8083 \
jaegertracing/example-hotrod:1.6 \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.6 version is old, so it needs to be updated to accept JAEGER_AGENT_XXX env.
Should I remove version tag so that latest is pulled?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be updated. latest is fine or 1.8

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to latest

all \
--jaeger-agent.host-port=jaeger:6831
all
```

Then open http://127.0.0.1:8080
Expand Down
3 changes: 1 addition & 2 deletions examples/hotrod/cmd/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ var customerCmd = &cobra.Command{
logger := log.NewFactory(zapLogger)
server := customer.NewServer(
net.JoinHostPort("0.0.0.0", strconv.Itoa(customerPort)),
tracing.Init("customer", metricsFactory.Namespace("customer", nil), logger, jAgentHostPort),
tracing.Init("customer", metricsFactory, logger),
metricsFactory,
logger,
jAgentHostPort,
)
return logError(zapLogger, server.Run())
},
Expand Down
3 changes: 1 addition & 2 deletions examples/hotrod/cmd/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ var driverCmd = &cobra.Command{
logger := log.NewFactory(zapLogger)
server := driver.NewServer(
net.JoinHostPort("0.0.0.0", strconv.Itoa(driverPort)),
tracing.Init("driver", metricsFactory.Namespace("driver", nil), logger, jAgentHostPort),
tracing.Init("driver", metricsFactory, logger),
metricsFactory,
logger,
jAgentHostPort,
)
return logError(zapLogger, server.Run())
},
Expand Down
2 changes: 1 addition & 1 deletion examples/hotrod/cmd/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var frontendCmd = &cobra.Command{
logger := log.NewFactory(zapLogger)
server := frontend.NewServer(
options,
tracing.Init("frontend", metricsFactory.Namespace("frontend", nil), logger, jAgentHostPort),
tracing.Init("frontend", metricsFactory, logger),
logger,
)
return logError(zapLogger, server.Run())
Expand Down
2 changes: 0 additions & 2 deletions examples/hotrod/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

var (
metricsBackend string
jAgentHostPort string
logger *zap.Logger
metricsFactory metrics.Factory

Expand Down Expand Up @@ -63,7 +62,6 @@ func Execute() {

func init() {
RootCmd.PersistentFlags().StringVarP(&metricsBackend, "metrics", "m", "expvar", "Metrics backend (expvar|prometheus)")
RootCmd.PersistentFlags().StringVarP(&jAgentHostPort, "jaeger-agent.host-port", "a", "0.0.0.0:6831", "String representing jaeger-agent UDP host:port, or jaeger-collector HTTP endpoint address, e.g. http://localhost:14268/api/traces.")
RootCmd.PersistentFlags().DurationVarP(&fixDBConnDelay, "fix-db-query-delay", "D", 300*time.Millisecond, "Average lagency of MySQL DB query")
RootCmd.PersistentFlags().BoolVarP(&fixDBConnDisableMutex, "fix-disable-db-conn-mutex", "M", false, "Disables the mutex guarding db connection")
RootCmd.PersistentFlags().IntVarP(&fixRouteWorkerPoolSize, "fix-route-worker-pool-size", "W", 3, "Default worker pool size")
Expand Down
2 changes: 1 addition & 1 deletion examples/hotrod/cmd/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var routeCmd = &cobra.Command{
logger := log.NewFactory(zapLogger)
server := route.NewServer(
net.JoinHostPort("0.0.0.0", strconv.Itoa(routePort)),
tracing.Init("route", metricsFactory.Namespace("route", nil), logger, jAgentHostPort),
tracing.Init("route", metricsFactory, logger),
logger,
)
return logError(zapLogger, server.Run())
Expand Down
40 changes: 11 additions & 29 deletions examples/hotrod/pkg/tracing/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,33 @@ package tracing

import (
"fmt"
"strings"
"time"

"github.com/opentracing/opentracing-go"
"github.com/uber/jaeger-client-go"
"github.com/uber/jaeger-client-go/config"
"github.com/uber/jaeger-client-go/rpcmetrics"
"github.com/uber/jaeger-client-go/transport"
"github.com/uber/jaeger-lib/metrics"
"go.uber.org/zap"

"github.com/jaegertracing/jaeger/examples/hotrod/pkg/log"
)

// Init creates a new instance of Jaeger tracer.
func Init(serviceName string, metricsFactory metrics.Factory, logger log.Factory, backendHostPort string) opentracing.Tracer {
cfg := config.Configuration{
Sampler: &config.SamplerConfig{
Type: "const",
Param: 1,
},
func Init(serviceName string, metricsFactory metrics.Factory, logger log.Factory) opentracing.Tracer {
cfg, err := config.FromEnv()
if err != nil {
logger.Bg().Fatal("cannot parse Jaeger env vars", zap.Error(err))
}
cfg.ServiceName = serviceName
cfg.Sampler.Type = "const"
cfg.Sampler.Param = 1

// TODO(ys) a quick hack to ensure random generators get different seeds, which are based on current time.
time.Sleep(100 * time.Millisecond)
jaegerLogger := jaegerLoggerAdapter{logger.Bg()}
var sender jaeger.Transport
if strings.HasPrefix(backendHostPort, "http://") {
sender = transport.NewHTTPTransport(
backendHostPort,
transport.HTTPBatchSize(1),
)
} else {
if s, err := jaeger.NewUDPTransport(backendHostPort, 0); err != nil {
logger.Bg().Fatal("cannot initialize UDP sender", zap.Error(err))
} else {
sender = s
}
}
tracer, _, err := cfg.New(
serviceName,
config.Reporter(jaeger.NewRemoteReporter(
sender,
jaeger.ReporterOptions.BufferFlushInterval(1*time.Second),
jaeger.ReporterOptions.Logger(jaegerLogger),
)),

metricsFactory = metricsFactory.Namespace(serviceName, nil)
tracer, _, err := cfg.NewTracer(
config.Logger(jaegerLogger),
config.Metrics(metricsFactory),
config.Observer(rpcmetrics.NewObserver(metricsFactory, rpcmetrics.DefaultNameNormalizer)),
Expand Down
4 changes: 2 additions & 2 deletions examples/hotrod/services/customer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ type Server struct {
}

// NewServer creates a new customer.Server
func NewServer(hostPort string, tracer opentracing.Tracer, metricsFactory metrics.Factory, logger log.Factory, jAgentHostPort string) *Server {
func NewServer(hostPort string, tracer opentracing.Tracer, metricsFactory metrics.Factory, logger log.Factory) *Server {
return &Server{
hostPort: hostPort,
tracer: tracer,
logger: logger,
database: newDatabase(
tracing.Init("mysql", metricsFactory.Namespace("mysql", nil), logger, jAgentHostPort),
tracing.Init("mysql", metricsFactory, logger),
logger.With(zap.String("component", "mysql")),
),
}
Expand Down
4 changes: 2 additions & 2 deletions examples/hotrod/services/driver/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ type Redis struct {
errorSimulator
}

func newRedis(metricsFactory metrics.Factory, logger log.Factory, jAgentHostPort string) *Redis {
func newRedis(metricsFactory metrics.Factory, logger log.Factory) *Redis {
return &Redis{
tracer: tracing.Init("redis", metricsFactory.Namespace("redis", nil), logger, jAgentHostPort),
tracer: tracing.Init("redis", metricsFactory, logger),
logger: logger,
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/hotrod/services/driver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Server struct {
}

// NewServer creates a new driver.Server
func NewServer(hostPort string, tracer opentracing.Tracer, metricsFactory metrics.Factory, logger log.Factory, jAgentHostPort string) *Server {
func NewServer(hostPort string, tracer opentracing.Tracer, metricsFactory metrics.Factory, logger log.Factory) *Server {
channelOpts := &tchannel.ChannelOptions{
Tracer: tracer,
}
Expand All @@ -52,7 +52,7 @@ func NewServer(hostPort string, tracer opentracing.Tracer, metricsFactory metric
logger: logger,
ch: ch,
server: server,
redis: newRedis(metricsFactory, logger, jAgentHostPort),
redis: newRedis(metricsFactory, logger),
}
}

Expand Down
21 changes: 11 additions & 10 deletions glide.lock

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

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import:
- package: go.uber.org/zap
version: ^1
- package: github.com/uber/jaeger-client-go
version: ^2.11.0
version: ^2.15.0
subpackages:
- transport
- package: github.com/uber/jaeger-lib
Expand Down