Skip to content

various improvements#4

Merged
clutchski merged 7 commits into
masterfrom
matt
Sep 27, 2016
Merged

various improvements#4
clutchski merged 7 commits into
masterfrom
matt

Conversation

@clutchski

@clutchski clutchski commented Sep 23, 2016

Copy link
Copy Markdown
Contributor
  • ensure nil or empty spans can't cause a panic on span.Finish and co.
  • added Span.Print() and a debug logging flag so we can see what's flowing while developing / debugging.
  • added max # of spans buffered in memory so we can't blow up the program if downstream issues occur
  • fixed race condition

@LeoCavaille LeoCavaille changed the title Matt make code more defensive on nil spans + thread safety Sep 26, 2016
@LeoCavaille

Copy link
Copy Markdown
Member

The code looks good, but you are failing the test suite because of your test case.

tracer/span_test.go:61: assignment copies lock value to span: tracer.Span contains sync.Mutex

- adds max size so that we can't take infinite memory of something breaks
  downstream
- easier to reason about concurrency
- fixes the following race condition:

    if len(t.finishedSpans) > 0 {
            t.mu.Lock()
            spans := t.finishedSpans
            t.finishedSpans = nil
so we can switch on and see info about what you're producing.
very good for debugging.
@clutchski clutchski changed the title make code more defensive on nil spans + thread safety various improvements Sep 27, 2016
Comment thread tracer/tracer.go
// buffer list if some fields are missing. The trace agent
// will discard this span in any case so it's better to prevent
// more useless work.
if t.enabled && span.Name != "" && span.Service != "" && span.Resource != "" {

@clutchski clutchski Sep 27, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i removed this because it means misconfigured spans will silently disappear with no feedback. this is really bad for a user perspective. i'd rather (a) send the data (b) have a validation error appear in the agent logs (c) have the validation code in as few places as possible.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok

@clutchski clutchski merged commit d2de94e into master Sep 27, 2016
Comment thread tracer/buffer.go
sb.spans = append(sb.spans, span)
} else {
idx := rand.Intn(sb.maxSize)
sb.spans[idx] = span

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it correct to remove a previously random span if the buffer is full? what happen if we remove a root span and all children lose their parents?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good question. i was actually thinking that we need to start pushing things as a trace rather than as a list of spans. i will work on this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as a trace you mean when the root span is closed and so the children?

Comment thread tracer/span.go
}
}

// Strin returns a human readable representation of the span. Not for

@palazzem palazzem Sep 27, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

String instead of Strin

Comment thread tracer/tracer.go
// Background worker that handles data delivery through the Transport instance.
// It waits for a flush interval and then it tries to find an available dispatcher
// if there is something to send.
// worker flushes

@palazzem palazzem Sep 27, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is it intentional to remove the comment? maybe it wasn't so helpful but I think that if it's not useful to explain a little bit the overview of the worker function, we can remove it at all

Comment thread tracer/tracer.go
// buffer list if some fields are missing. The trace agent
// will discard this span in any case so it's better to prevent
// more useless work.
if t.enabled && span.Name != "" && span.Service != "" && span.Resource != "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok

Comment thread tracer/tracer.go
}
}

if t.enabled && t.transport != nil && 0 < len(spans) {

@palazzem palazzem Sep 27, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the t.transport may be nil? can it be changed by users? or is it used only to be really sure and robust? (just asking)

About the 0 < len(spans) can't it be len(spans) > 0? I mean for the code style (I know that is stupid but just asking because this should become an open source project).

Comment thread tracer/buffer.go
}

// FIXME[matt] on rotation, we could re-use the slices and spans here
// and avoid re-allocing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants