Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Throttle debug traces #274

Merged
merged 3 commits into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 36 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2017 Uber Technologies, Inc.
// Copyright (c) 2017-2018 Uber Technologies, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you manually doing these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes lol talk to @yurishkuro.

Copy link
Contributor

Choose a reason for hiding this comment

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

seems painful... I'll see how we can automate this

Copy link
Contributor Author

@isaachier isaachier Mar 27, 2018

Choose a reason for hiding this comment

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

I think it can be done with the existing script if you append -<current-year> and limit the files to the list given by this command git diff --name-status master | grep -E '^M' | sed 's/^M\s\+//g'. That looks scarier than it is ;).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't seem to work on my Mac. Unclear why not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Spent way too long researching this... Mac chokes on tab characters (see tab here https://github.com/git/git/blob/c6284da4ff4afbde8211efe5d03f3604b1c6b9d6/combine-diff.c#L1185). Maybe git diff --name-status master | grep -E '^M' | tr '\t' ';' | sed 's/^M;//g' instead.

Copy link
Member

Choose a reason for hiding this comment

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

Mac chokes on tab characters

with what error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually more bizarre than that. In my terminal, any attempt to evaluate a tab character causes autocomplete. If I copy and paste this M process.go from the output into my input I get Makefileprocess.go. There seems to be no way to simply sed with a tab character on my Mac.

//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@ import (

"github.com/uber/jaeger-client-go"
"github.com/uber/jaeger-client-go/internal/baggage/remote"
throttler "github.com/uber/jaeger-client-go/internal/throttler/remote"
"github.com/uber/jaeger-client-go/rpcmetrics"
)

Expand All @@ -49,6 +50,7 @@ type Configuration struct {
Reporter *ReporterConfig `yaml:"reporter"`
Headers *jaeger.HeadersConfig `yaml:"headers"`
BaggageRestrictions *BaggageRestrictionsConfig `yaml:"baggage_restrictions"`
Throttler *ThrottlerConfig `yaml:"throttler"`
}

// SamplerConfig allows initializing a non-default sampler. All fields are optional.
Expand Down Expand Up @@ -125,6 +127,24 @@ type BaggageRestrictionsConfig struct {
RefreshInterval time.Duration `yaml:"refreshInterval"`
}

// ThrottlerConfig configures the throttler which can be used to throttle the
// rate at which the client may send debug requests.
type ThrottlerConfig struct {
// HostPort of jaeger-agent's credit server.
HostPort string `yaml:"hostPort"`

// RefreshInterval controls how often the throttler will poll jaeger-agent
// for more throttling credits.
RefreshInterval time.Duration `yaml:"refreshInterval"`

// SynchronousInitialization determines whether or not the throttler should
// synchronously fetch credits from the agent when an operation is seen for
// the first time. This should be set to true if the client will be used by
// a short lived service that needs to ensure that credits are fetched
// upfront such that sampling or throttling occurs.
SynchronousInitialization bool `yaml:"synchronousInitialization"`
}

type nullCloser struct{}

func (*nullCloser) Close() error { return nil }
Expand Down Expand Up @@ -238,6 +258,21 @@ func (c Configuration) NewTracer(options ...Option) (opentracing.Tracer, io.Clos
tracerOptions = append(tracerOptions, jaeger.TracerOptions.BaggageRestrictionManager(mgr))
}

if c.Throttler != nil {
debugThrottler := throttler.NewThrottler(
c.ServiceName,
throttler.Options.Metrics(tracerMetrics),
throttler.Options.Logger(opts.logger),
throttler.Options.HostPort(c.Throttler.HostPort),
throttler.Options.RefreshInterval(c.Throttler.RefreshInterval),
throttler.Options.SynchronousInitialization(
c.Throttler.SynchronousInitialization,
),
)

tracerOptions = append(tracerOptions, jaeger.TracerOptions.DebugThrottler(debugThrottler))
}

tracer, closer := jaeger.NewTracer(
c.ServiceName,
sampler,
Expand Down
16 changes: 16 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,19 @@ func TestServiceNameViaConfiguration(t *testing.T) {
assert.NoError(t, err)
defer closer.Close()
}

func TestTracerTags(t *testing.T) {
cfg := &Configuration{Tags: []opentracing.Tag{{Key: "test", Value: 123}}}
_, closer, err := cfg.New("test-service")
assert.NoError(t, err)
defer closer.Close()
}

func TestThrottlerDefaultConfig(t *testing.T) {
cfg := &Configuration{
Throttler: &ThrottlerConfig{},
}
_, closer, err := cfg.New("test-service")
assert.NoError(t, err)
defer closer.Close()
}
3 changes: 3 additions & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ const (
// TracerIPTagKey used to report ip of the process.
TracerIPTagKey = "ip"

// TracerUUIDTagKey used to report UUID of the client process.
TracerUUIDTagKey = "client-uuid"

// SamplerTypeTagKey reports which sampler was used on the root span.
SamplerTypeTagKey = "sampler.type"

Expand Down
17 changes: 14 additions & 3 deletions crossdock/endtoend/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ import (
"time"

"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"

"github.com/uber/jaeger-client-go"
"github.com/uber/jaeger-client-go/config"
"github.com/uber/jaeger-client-go/crossdock/common"
"github.com/uber/jaeger-client-go/crossdock/log"
)

var (
const (
defaultSamplerType = jaeger.SamplerTypeRemote
)

var (
endToEndConfig = config.Configuration{
Disabled: false,
Sampler: &config.SamplerConfig{
Expand All @@ -42,6 +45,10 @@ var (
Reporter: &config.ReporterConfig{
BufferFlushInterval: time.Second,
},
Throttler: &config.ThrottlerConfig{
SynchronousInitialization: true,
HostPort: "agent:5778",
},
}
)

Expand Down Expand Up @@ -110,7 +117,7 @@ func (h *Handler) getTracer(samplerType string) opentracing.Tracer {
if !ok {
endToEndConfig.Sampler.Type = samplerType
if err := h.init(endToEndConfig); err != nil {
log.Printf("Failed to create tracer: %s", err.Error())
log.Printf("Failed to create tracer: %s\n", err.Error())
return nil
}
tracer, _ = h.tracers[samplerType]
Expand Down Expand Up @@ -138,7 +145,11 @@ func generateTraces(tracer opentracing.Tracer, r *traceRequest) {
for i := 0; i < r.Count; i++ {
span := tracer.StartSpan(r.Operation)
for k, v := range r.Tags {
span.SetTag(k, v)
if k == string(ext.SamplingPriority) && v == "1" {
span.SetTag(k, uint16(1))
} else {
span.SetTag(k, v)
}
}
span.Finish()
}
Expand Down
2 changes: 1 addition & 1 deletion crossdock/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ var Enabled bool
// Printf delegates to log.Printf if Enabled == true
func Printf(msg string, args ...interface{}) {
if Enabled {
real_log.Printf(msg, args)
real_log.Printf(msg, args...)
}
}
30 changes: 17 additions & 13 deletions glide.lock

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

3 changes: 2 additions & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import:
- metrics
- package: github.com/pkg/errors
version: ~0.8.0
- package: github.com/satori/go.uuid
version: ^1.2.0
testImport:
- package: github.com/stretchr/testify
version: ^1.1.3
subpackages:
- assert
- require
Expand Down
Loading