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

Add option for consistent high trace ID #219

Merged
merged 6 commits into from
Nov 14, 2017

Conversation

isaachier
Copy link
Contributor

Allow high 64 bits of trace ID to be set to the first 64 bits of SHA256 of service name. This is a quick way to identify the originator of a given trace.

@codecov
Copy link

codecov bot commented Nov 8, 2017

Codecov Report

Merging #219 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #219      +/-   ##
==========================================
+ Coverage   81.92%   81.99%   +0.06%     
==========================================
  Files          51       51              
  Lines        3214     3226      +12     
==========================================
+ Hits         2633     2645      +12     
  Misses        457      457              
  Partials      124      124
Impacted Files Coverage Δ
tracer.go 89.83% <100%> (+0.34%) ⬆️
tracer_options.go 79.41% <100%> (+1.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc53686...6838cf7. Read the comment docs.

@black-adder
Copy link
Contributor

lgtm, but I'm a bit hesitant on landing this since it's for a very specific Uber use case. Let's keep this branch open and pin this branch for now.

@isaachier
Copy link
Contributor Author

Sounds good to me

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

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

-1 if this is trying to address our blackbox issue, the only thing we need in the open source is the ability to override the id generator. Also, iirc the id is being treated as a random number by the probabilistic sampler, so that needs to change.

@isaachier
Copy link
Contributor Author

Lol the sampling part is true for the lower 64 bits. Regardless that is a good point about overriding the random number generator.

@isaachier isaachier force-pushed the consistent-high-trace-id branch from 61a4729 to 65e5b85 Compare November 9, 2017 12:17
tracer.go Outdated
@@ -61,6 +62,7 @@ type Tracer struct {

baggageRestrictionManager baggage.RestrictionManager
baggageSetter *baggageSetter
serviceNameHash uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

don't think the tracer needs to be aware of this

Copy link
Member

Choose a reason for hiding this comment

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

remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh missed this thanks

tracer.go Outdated
@@ -206,6 +208,8 @@ func (t *Tracer) startSpanWithOptions(
ctx.traceID.Low = t.randomID()
if t.options.gen128Bit {
ctx.traceID.High = t.randomID()
} else if t.options.highTraceIDGenerator != nil {
Copy link
Member

@yurishkuro yurishkuro Nov 11, 2017

Choose a reason for hiding this comment

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

I don't think else if is appropriate - if we're not asked to generate 128bit IDs, then there's no need to invoke High ID generator even if it is provided. On the other hand, if gen128Bit == true but the external generator is not provided, it needs to be defaulted to tracer.randomID.

I would also return an error from constructor if gen128Bit==false && highTraceIDGenerator != nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough. I think I just didn't think about the change in logic after changing the option to a function. This was originally checking the ConsistentHighTraceID flag.

tracer_test.go Outdated
@@ -317,6 +319,30 @@ func TestGen128Bit(t *testing.T) {
assert.True(t, traceID.Low != 0)
}

func TestHighTraceIDGenerator(t *testing.T) {
hash := sha256.Sum256([]byte("x"))
id := binary.BigEndian.Uint64(hash[0:])
Copy link
Member

@yurishkuro yurishkuro Nov 11, 2017

Choose a reason for hiding this comment

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

don't see the point of these manipulations - why not just define some constant and check against it? Also, if the default is random generator, then there is a chance it will produce the same constant, so the test must be checking that the generator was actually called, not just that the resulting HighID is equal to the constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Although the likelihood of the random generator coming up with the same value is effectively zero, still worth doing the ideal way. This was just where I temporarily moved the service name to hash transformation.

tracer.go Outdated
@@ -205,7 +212,11 @@ func (t *Tracer) startSpanWithOptions(
newTrace = true
ctx.traceID.Low = t.randomID()
if t.options.gen128Bit {
ctx.traceID.High = t.randomID()
if t.options.highTraceIDGenerator != nil {
Copy link
Member

Choose a reason for hiding this comment

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

the branching is not necessary, you can default highTraceIDGenerator to randomID() in the constructor

tracer_test.go Outdated
assert.True(t, calledGenerator)
}

type mockLogger struct {
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't do that. We have log/zap package where you can create a logger with zap, and zap has a ByteBuffer-backed logger. To make using it easier, however, we can add log/testutils package that will do the above in one call.

Copy link
Member

Choose a reason for hiding this comment

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

incidentally, we have something like that in the main repo, jaeger/pkg/testutils/logger.go, another option would be to consolidate that in jaeger-lib (but I'd punt on that for now)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I try using a the log/zap package in my test case, I get this error:

# github.com/uber/jaeger-client-go
import cycle not allowed in test
package github.com/uber/jaeger-client-go (test)
	imports github.com/uber/jaeger-client-go/log/zap
	imports github.com/uber/jaeger-client-go

Imagine this needs to be moved to jaeger-lib or otherwise refactored (the issue is log/zap/field.go not log/zap/logger.go).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I just copy the struct from log/zap/logger.go for now or should I refactor testutils into jaeger-lib as you mentioned above?

Copy link
Member

Choose a reason for hiding this comment

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

just leave it for now, add a TODO

Signed-off-by: Isaac Hier <[email protected]>
@isaachier isaachier force-pushed the consistent-high-trace-id branch from c1a92a4 to 0e4fac0 Compare November 13, 2017 22:01
Signed-off-by: Isaac Hier <[email protected]>
@yurishkuro
Copy link
Member

Signed-off-by: Isaac Hier <[email protected]>
@yurishkuro yurishkuro merged commit 06a5312 into jaegertracing:master Nov 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants