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

Add remoteBaggageRestrictionManager #182

Merged
merged 9 commits into from
Aug 7, 2017

Conversation

black-adder
Copy link
Contributor

@black-adder black-adder commented Aug 1, 2017

  • Tests


func (tracerOptions) BaggageRestrictionsConfig(cfg *BaggageRestrictionsConfig) TracerOption {
return func(tracer *Tracer) {
tracer.baggageRestrictionsConfig = cfg
Copy link
Contributor Author

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?

Copy link
Member

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?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 85.355% when pulling 28607fc on Add_RemoteBaggageRestrictionManager into 08628f9 on master.

@yurishkuro
Copy link
Member

This design affects all languages, and the API visibility issues are similar. Can the following work?

  • jaeger/
    • interface BaggageSetter { SetBaggage() }
    • span checks if baggageSetter == null then it stores the baggage manually, no additional logic, otherwise calls baggageSetter.SetBaggage(self, key value)
  • internal/baggage
    • struct DefaultBaggageSetter
    • deals with metrics and logging
    • may want to rename baggageSetter to baggageActor (whatever)
    • contains pointer to BaggageRestrictionManager that it uses for the rules
      • default BRM is - allow all
      • RemoteBaggageRestrictionManager pulls the rules from the agent
  • config
    • BaggageManagerConfig
    • creates BaggageRestrictionManager with RemoteBaggageRestrictionManager

This way the two API additions are BaggageSetter interface and BaggageManagerConfig struct. Everything else is either private or stashed under internal/. There don't seem to be any circular dependencies.

We could also go a bit further and move RemoteBRM under internal/baggage/remote. This way if people are not using config package, and don't want the RemoteBRM, they don't even need to compile that package into their app. Right now we're forcing everyone to compile almost everything from the client, we should really be doing a better job at isolation.

@black-adder
Copy link
Contributor Author

black-adder commented Aug 2, 2017

What we can do instead:

  • jaeger/
    • interface BaggageRestrictionManager { GetRestriction(key) (bool, int) }
    • private baggageSetter initialized by tracer that has ptr to BaggageRestrictionManager (baggageSetter handles metrics and logs)
  • internal/baggage
    • struct Default BRM - allow all
    • struct Remote BRM pulls the rules from the agent
  • config
    • BaggageManagerConfig
    • creates BaggageRestrictionManager with RemoteBaggageRestrictionManager

We can take your approach in other languages, just not in go.

@yurishkuro
Copy link
Member

interface BaggageRestrictionManager { GetRestriction(key) (bool, int) }

well my goal was to come up with a unified API across all languages. (bool, int) won't work in Java

@black-adder
Copy link
Contributor Author

my bad

interface BaggageRestrictionManager { GetRestriction(key) Restriction }

type Restriction struct {
    valid bool
    maxValueLength int
    whatever in the future we want to add
}

and restriction is generated once in the DBRM and once a minute in RBRM

@yurishkuro
Copy link
Member

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 - :-( ...

@black-adder black-adder changed the title Add remoteBaggageRestrictionManager [WIP] Add remoteBaggageRestrictionManager Aug 2, 2017
@black-adder
Copy link
Contributor Author

black-adder commented Aug 2, 2017

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 {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-4.2%) to 81.231% when pulling 17e0565 on Add_RemoteBaggageRestrictionManager into 08628f9 on master.

@@ -0,0 +1,216 @@
// Copyright (c) 2017 Uber Technologies, Inc.
Copy link

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?

Copy link
Contributor Author

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

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.

approach looks ok. Surprised there are no changes to Span in this diff - who calls tracer.setBaggage?

}

func logFields(span *Span, key, value, prevItem string, truncated, invalid bool) {
func logFields(span *Span, key, value, prevItem string, truncated, valid bool) {
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

s/valid/keyAllowed/ ?

@black-adder
Copy link
Contributor Author

span calls tracer.setBaggage, but that was already done in a previous PR. Information hiding ftw

@black-adder black-adder changed the title [WIP] Add remoteBaggageRestrictionManager Add remoteBaggageRestrictionManager Aug 4, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 85.057% when pulling ecc0680 on Add_RemoteBaggageRestrictionManager into 08628f9 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 85.573% when pulling fe802ec on Add_RemoteBaggageRestrictionManager into 08628f9 on master.

}
}

func (s *defaultBaggageSetter) setBaggage(span *Span, key, value string) {
func (s baggageSetter) setBaggage(span *Span, key, value string) {
Copy link
Member

Choose a reason for hiding this comment

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

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.

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).

}
}

func (s *defaultBaggageSetter) setBaggage(span *Span, key, value string) {
func (s baggageSetter) setBaggage(span *Span, key, value string) {
Copy link
Member

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"
Copy link
Member

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

Copy link
Contributor Author

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

var Options options

type options struct {
failClosed bool
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 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 {
Copy link
Member

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?

Copy link
Contributor Author

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 {
Copy link
Member

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 {
Copy link
Member

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.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 85.578% when pulling 5cc274e on Add_RemoteBaggageRestrictionManager into 08628f9 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 85.578% when pulling 7ed2a48 on Add_RemoteBaggageRestrictionManager into 08628f9 on master.

@black-adder black-adder merged commit c8f7cd8 into master Aug 7, 2017
@black-adder black-adder deleted the Add_RemoteBaggageRestrictionManager branch August 7, 2017 14:05
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.

4 participants