Skip to content

Commit a7ca9ed

Browse files
author
Yuri Shkuro
committed
Address comments
Signed-off-by: Yuri Shkuro <ys@uber.com>
1 parent 40aa21e commit a7ca9ed

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

cmd/tracegen/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func main() {
5454
opentracing.InitGlobalTracer(tracer)
5555
logger.Info("Initialized global tracer")
5656

57-
cfg.Run(logger)
57+
tracegen.Run(cfg, logger)
5858

5959
logger.Info("Waiting 1.5sec for metrics to flush")
6060
time.Sleep(3 * time.Second / 2)

internal/tracegen/.nocover

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FIXME

internal/tracegen/config.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
type Config struct {
2929
Workers int
3030
Traces int
31-
Marshall bool
31+
Marshal bool
3232
Debug bool
3333
Pause time.Duration
3434
Duration time.Duration
@@ -38,33 +38,33 @@ type Config struct {
3838
func (c *Config) Flags(fs *flag.FlagSet) {
3939
fs.IntVar(&c.Workers, "workers", 1, "Number of workers (goroutines) to run")
4040
fs.IntVar(&c.Traces, "traces", 1, "Number of traces to generate in each worker (ignored if duration is provided")
41-
fs.BoolVar(&c.Marshall, "marshall", false, "Whether to marshall trace context via HTTP headers")
41+
fs.BoolVar(&c.Marshal, "marshal", false, "Whether to marshal trace context via HTTP headers")
4242
fs.BoolVar(&c.Debug, "debug", false, "Whether to set DEBUG flag on the spans to prevent downsampling")
4343
fs.DurationVar(&c.Pause, "pause", time.Microsecond, "How long to pause before finishing trace")
4444
fs.DurationVar(&c.Duration, "duration", 0, "For how long to run the test")
4545
}
4646

4747
// Run executes the test scenario.
48-
func (c *Config) Run(logger *zap.Logger) error {
48+
func Run(c *Config, logger *zap.Logger) error {
4949
if c.Duration > 0 {
5050
c.Traces = 0
5151
} else if c.Traces <= 0 {
5252
return fmt.Errorf("Either `traces` or `duration` must be greater than 0")
5353
}
5454

55-
wg := &sync.WaitGroup{}
55+
wg := sync.WaitGroup{}
5656
var running uint32 = 1
5757
for i := 0; i < c.Workers; i++ {
5858
wg.Add(1)
5959
w := worker{
6060
id: i,
6161
traces: c.Traces,
62-
marshall: c.Marshall,
62+
marshal: c.Marshal,
6363
debug: c.Debug,
6464
pause: c.Pause,
6565
duration: c.Duration,
6666
running: &running,
67-
wg: wg,
67+
wg: &wg,
6868
logger: logger.With(zap.Int("worker", i)),
6969
}
7070

internal/tracegen/worker.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,22 @@ import (
2626
)
2727

2828
type worker struct {
29+
running *uint32 // pointer to shared flag that indicates it's time to stop the test
2930
id int // worker id
3031
traces int // how many traces the worker has to generate (only when duration==0)
31-
marshall bool // whether the worker needs to marshall trace context via HTTP headers
32+
marshal bool // whether the worker needs to marshal trace context via HTTP headers
3233
debug bool // whether to set DEBUG flag on the spans
3334
duration time.Duration // how long to run the test for (overrides `traces`)
3435
pause time.Duration // how long to pause before finishing the trace
35-
running *uint32 // pointer to shared flag that indicates it's time to stop the test
3636
wg *sync.WaitGroup // notify when done
3737
logger *zap.Logger
3838
}
3939

40-
var fakeIP uint32 = 1<<24 | 2<<16 | 3<<8 | 4
40+
const (
41+
fakeIP uint32 = 1<<24 | 2<<16 | 3<<8 | 4
42+
43+
fakeSpanDuration = 123 * time.Microsecond
44+
)
4145

4246
func (w worker) simulateTraces() {
4347
tracer := opentracing.GlobalTracer()
@@ -52,7 +56,7 @@ func (w worker) simulateTraces() {
5256
}
5357

5458
childCtx := sp.Context()
55-
if w.marshall {
59+
if w.marshal {
5660
m := make(map[string]string)
5761
c := opentracing.TextMapCarrier(m)
5862
if err := tracer.Inject(sp.Context(), opentracing.TextMap, c); err == nil {
@@ -78,7 +82,7 @@ func (w worker) simulateTraces() {
7882
child.Finish()
7983
sp.Finish()
8084
} else {
81-
opt := opentracing.FinishOptions{FinishTime: time.Now().Add(123 * time.Microsecond)}
85+
opt := opentracing.FinishOptions{FinishTime: time.Now().Add(fakeSpanDuration)}
8286
child.FinishWithOptions(opt)
8387
sp.FinishWithOptions(opt)
8488
}

0 commit comments

Comments
 (0)