Skip to content

Commit

Permalink
Add a flag for firehose mode (jaegertracing#419)
Browse files Browse the repository at this point in the history
* Add a flag for firehose mode

Add 0b100 as a constant for Firehose mode and allow setting and checking
this on the span context.

fixes jaegertracing#417
ref #1731

Signed-off-by: Prithvi Raj <p.r@uber.com>
  • Loading branch information
vprithvi authored Aug 21, 2019
1 parent e8ef996 commit 30e6256
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 15 deletions.
10 changes: 8 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
)

const (
flagSampled = byte(1)
flagDebug = byte(2)
flagSampled = byte(1)
flagDebug = byte(2)
flagFirehose = byte(8)
)

var (
Expand Down Expand Up @@ -88,6 +89,11 @@ func (c SpanContext) IsDebug() bool {
return (c.flags & flagDebug) == flagDebug
}

// IsFirehose indicates whether the firehose flag was set
func (c SpanContext) IsFirehose() bool {
return (c.flags & flagFirehose) == flagFirehose
}

// IsValid indicates whether this context actually represents a valid trace.
func (c SpanContext) IsValid() bool {
return c.traceID.IsValid() && c.spanID != 0
Expand Down
84 changes: 71 additions & 13 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,79 @@ func TestSpanContext_WithBaggageItem(t *testing.T) {
assert.Equal(t, map[string]string{"some-KEY": "Some-Other-Value"}, ctx.baggage)
}

func TestSpanContext_SampledDebug(t *testing.T) {
ctx, err := ContextFromString("1:1:1:1")
require.NoError(t, err)
assert.True(t, ctx.IsSampled())
assert.False(t, ctx.IsDebug())
func TestSpanContext_Flags(t *testing.T) {

ctx, err = ContextFromString("1:1:1:3")
require.NoError(t, err)
assert.True(t, ctx.IsSampled())
assert.True(t, ctx.IsDebug())
var tests = map[string]struct {
in string
sampledFlag bool
debugFlag bool
firehoseFlag bool
}{
"None": {
in: "1:1:1:0",
sampledFlag: false,
debugFlag: false,
firehoseFlag: false,
},
"Sampled Only": {
in: "1:1:1:1",
sampledFlag: true,
debugFlag: false,
firehoseFlag: false,
},

ctx, err = ContextFromString("1:1:1:0")
require.NoError(t, err)
assert.False(t, ctx.IsSampled())
assert.False(t, ctx.IsDebug())
"Debug Only": {
in: "1:1:1:2",
sampledFlag: false,
debugFlag: true,
firehoseFlag: false,
},

"IsFirehose Only": {
in: "1:1:1:8",
sampledFlag: false,
debugFlag: false,
firehoseFlag: true,
},

"Sampled And Debug": {
in: "1:1:1:3",
sampledFlag: true,
debugFlag: true,
firehoseFlag: false,
},

"Sampled And Firehose": {
in: "1:1:1:9",
sampledFlag: true,
debugFlag: false,
firehoseFlag: true,
},

"Debug And Firehose": {
in: "1:1:1:10",
sampledFlag: false,
debugFlag: true,
firehoseFlag: true,
},

"Sampled And Debug And Firehose": {
in: "1:1:1:11",
sampledFlag: true,
debugFlag: true,
firehoseFlag: true,
},
}

for name, tc := range tests {
t.Run(name, func(t *testing.T) {
ctx, err := ContextFromString(tc.in)
require.NoError(t, err)
assert.Equal(t, tc.sampledFlag, ctx.IsSampled())
assert.Equal(t, tc.debugFlag, ctx.IsDebug())
assert.Equal(t, tc.firehoseFlag, ctx.IsFirehose())
})
}
}

func TestSpanContext_CopyFrom(t *testing.T) {
Expand Down
5 changes: 5 additions & 0 deletions span.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,8 @@ func setSamplingPriority(s *Span, value interface{}) bool {
}
return false
}

// EnableFirehose enables firehose flag on the span context
func EnableFirehose(s *Span) {
s.context.flags |= flagFirehose
}
12 changes: 12 additions & 0 deletions span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ func TestSetTag_SamplingPriority(t *testing.T) {
assert.False(t, sp1.context.IsDebug(), "debug should not be allowed by the throttler")
}

func TestSetFirehoseMode(t *testing.T) {
tracer, closer := NewTracer("DOOP", NewConstSampler(true), NewNullReporter())
defer closer.Close()

sp1 := tracer.StartSpan("s1").(*Span)
assert.False(t, sp1.context.IsFirehose())

EnableFirehose(sp1)

assert.True(t, sp1.context.IsFirehose())
}

type testThrottler struct {
allowAll bool
}
Expand Down

0 comments on commit 30e6256

Please sign in to comment.