-
Notifications
You must be signed in to change notification settings - Fork 288
Conversation
black-adder
commented
Aug 1, 2017
•
edited
Loading
edited
- Tests
tracer_options.go
Outdated
|
||
func (tracerOptions) BaggageRestrictionsConfig(cfg *BaggageRestrictionsConfig) TracerOption { | ||
return func(tracer *Tracer) { | ||
tracer.baggageRestrictionsConfig = cfg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to copy: https://github.com/uber/jaeger-client-go/blob/master/tracer_options.go#L57 but what happens if metrics doesn't exist before that option is run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why expose Config to the tracer instead of the actual baggage manager?
This design affects all languages, and the API visibility issues are similar. Can the following work?
This way the two API additions are BaggageSetter interface and BaggageManagerConfig struct. Everything else is either private or stashed under We could also go a bit further and move RemoteBRM under |
What we can do instead:
We can take your approach in other languages, just not in go. |
well my goal was to come up with a unified API across all languages. |
my bad
and restriction is generated once in the DBRM and once a minute in RBRM |
So one drawback I see in your approach is "(baggageSetter handles metrics and logs)" - meaning there isn't any way to actually NOT log baggage without introducing more options to the Tracer (and increasing its surface). In my proposal the side-effects of setting baggage are encapsulated into another struct that can be replaced if needed, and Tracer is only exposed to its SetBaggage interface. Although when you mentioned circular dependency on the call, I see the potential for it here since the setter might need access to private Span API - :-( ... |
I addressed some of the concerns and moved as much of the code over to the internal directory. I'll address the design decisions inline |
@@ -109,8 +111,10 @@ func NewTracer( | |||
zipkinPropagator := &zipkinPropagator{tracer: t} | |||
t.addCodec(ZipkinSpanFormat, zipkinPropagator, zipkinPropagator) | |||
|
|||
if t.baggageRestrictionManager == nil { | |||
t.baggageRestrictionManager = newDefaultBaggageRestrictionManager(&t.metrics, 0) | |||
if t.baggageRestrictionManager != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the manager isn't passed in, the baggageSetter defaults to use the DefaultManager.
type defaultBaggageSetter struct { | ||
maxValueLength int | ||
metrics *Metrics | ||
type baggageSetter struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted to just make this a struct and not an interface. Given it's private anyway, if we ever need to change it to a interface it can be easily done.
type baggageRestrictionManager interface { | ||
// setBaggage sets the baggage key:value on a span and the associated logs. | ||
setBaggage(span *Span, key, value string) | ||
type Restriction struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to make this immutable by adding the getters. This way we only need to generate this once and return it to the setter
// defaultBaggageRestrictionManager allows any baggage key. | ||
type defaultBaggageRestrictionManager struct { | ||
setter baggageSetter | ||
func NewRestriction(valid bool, maxValueLength int) *Restriction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a fan of this, pollutes namespace and if we ever need to add extra restrictions, can't easily update the signature without a breaking change.
@@ -0,0 +1,216 @@ | |||
// Copyright (c) 2017 Uber Technologies, Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this whole file commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wanted to iron out the API before writing the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approach looks ok. Surprised there are no changes to Span in this diff - who calls tracer.setBaggage?
baggage_setter.go
Outdated
} | ||
|
||
func logFields(span *Span, key, value, prevItem string, truncated, invalid bool) { | ||
func logFields(span *Span, key, value, prevItem string, truncated, valid bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe make it a member function, to avoid polluting jaeger
namespace?
// setBaggage sets the baggage key:value on a span and the associated logs. | ||
setBaggage(span *Span, key, value string) | ||
type Restriction struct { | ||
valid bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/valid/keyAllowed/ ?
span calls tracer.setBaggage, but that was already done in a previous PR. Information hiding ftw |
baggage_setter.go
Outdated
} | ||
} | ||
|
||
func (s *defaultBaggageSetter) setBaggage(span *Span, key, value string) { | ||
func (s baggageSetter) setBaggage(span *Span, key, value string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you pass the receiver by value?
https://gist.github.com/yurishkuro/b135e6750df0f95aa86c35a77cc736d4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be (mostly) ok to merge. Main comments are about using pointer-receiver (fix now) and the timeout of initial load (address in different PR).
baggage_setter.go
Outdated
} | ||
} | ||
|
||
func (s *defaultBaggageSetter) setBaggage(span *Span, key, value string) { | ||
func (s baggageSetter) setBaggage(span *Span, key, value string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there expectation that the caller holds a lock on the span?
const ( | ||
defaultMaxValueLength = 2048 | ||
defaultRefreshInterval = time.Minute | ||
defaultServerURL = "http://localhost:5778/baggageRestrictions" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not suggesting we change this now, but there are a couple problems with this URL config property that perhaps we should keep in mind:
- if the deployment requires accessing the agent via different name than
localhost
we now have several config variables the user needs to update - while updating those variables, the user needs to know the exact URLs like
/baggageRestrictions
when all they needed was to update the agent's host name
Maybe we should have a TODO somewhere for the next major release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ill fix in next PR
internal/baggage/remote/options.go
Outdated
var Options options | ||
|
||
type options struct { | ||
failClosed bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this follow the same naming pattern as the option? DenyBaggageOnInitializationFailure
invalidRestriction: baggage.NewRestriction(false, 0), | ||
validRestriction: baggage.NewRestriction(true, defaultMaxValueLength), | ||
} | ||
if err := m.updateRestrictions(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this call happens on the critical path of application startup. What kind of timeout do we have for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ill fix in next PR
return nil | ||
} | ||
|
||
func (m *RestrictionManager) generateRestrictions(restrictions []*thrift.BaggageRestriction) map[string]*baggage.Restriction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is not "generating" restrictions. "parse" or "convert".
@@ -283,6 +287,9 @@ func (t *Tracer) Extract( | |||
func (t *Tracer) Close() error { | |||
t.reporter.Close() | |||
t.sampler.Close() | |||
if mgr, ok := t.baggageRestrictionManager.(io.Closer); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that your remote manager is not an io.Closer
: func (m *RestrictionManager) Close() {
(no error returned)
Should add var _ io.Closer = new(RemoteBaggageRestrictionManager)
in its test file.