Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddtrace/tracer: force trace stats flush on Stop #1393

Merged
merged 8 commits into from
Jul 26, 2022
Merged

Conversation

Kyle-Verhoog
Copy link
Member

The trace stats were not being sent on tracer.Stop() /
tracer.stats.Stop() so any unsent buckets would never be sent.

The fix is to add an option to force the bucket out on stop.

Copy link
Contributor

@ajgajg1134 ajgajg1134 left a comment

Choose a reason for hiding this comment

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

Thanks for finding this and making a change here! Can we add a unit test here to make sure we don't regress on this at some point in the future?

@ajgajg1134 ajgajg1134 added this to the 1.41.0 milestone Jul 19, 2022
Copy link
Contributor

@gbbr gbbr left a comment

Choose a reason for hiding this comment

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

Just some nits 🙏🏻

ddtrace/tracer/stats.go Outdated Show resolved Hide resolved
gbbr
gbbr previously approved these changes Jul 21, 2022
Copy link
Contributor

@gbbr gbbr left a comment

Choose a reason for hiding this comment

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

Thanks Kyle! 🙏🏻 LGTM

ddtrace/tracer/stats.go Outdated Show resolved Hide resolved
The trace stats were not being sent on tracer.Stop() /
tracer.stats.Stop() so any unsent buckets would never be sent.

The fix is to add an option to force the bucket out on stop.
Leave flush as-is so that the lock acquisition doesn't cover the
transport call.
waitForBuckets was not releasing the lock when the function would return
true... and then the transport needed to be specified to avoid a nil
pointer dereference...

Thank you Andrew!!
ddtrace/tracer/stats.go Outdated Show resolved Hide resolved
bucketSize int64 // the size of a bucket in nanoseconds
stop chan struct{} // closing this channel triggers shutdown
cfg *config // tracer startup configuration
wg *sync.WaitGroup // waits for any active goroutines
Copy link
Contributor

@gbbr gbbr Jul 23, 2022

Choose a reason for hiding this comment

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

Please don't make a pointer out of this. Waitgroups are generally not declared as such.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, I've always used the opposite approach to make accidentally copying the waitgroup more difficult, what's the reasoning behind keeping it as not a pointer?

Copy link
Contributor

@gbbr gbbr Jul 25, 2022

Choose a reason for hiding this comment

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

I think the question goes the other way: what's the reason to have it as a pointer? You never have to initialise it, it's ready-to-use. How often does it happen that you need to pass it around? And if you do need to pass it around, it can always be dereferenced.

I frankly have never seen it passed as a pointer in official Go projects (e.g. the lang), unless it's an argument to a function that is supposed to receive a copy.

I don't think that declaring things as pointers to make sure we don't accidentally copy them is a good enough reason to IMHO.

Copy link
Contributor

Choose a reason for hiding this comment

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

My thought process was that all the methods on wait group have a pointer receiver so using it as a pointer makes it slightly more obvious that's the typical way to use it. In this specific spot I changed it to a pointer as part of debugging to make sure we weren't accidentally copying it since the tests were failing in an odd way. I'll switch this back to non-pointer since it's not really bringing a ton of value (and if we do accidentally copy it the unit tests will protect us)

Copy link
Contributor

Choose a reason for hiding this comment

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

Please ping me if you do discover that having it as a pointer provides some kind of benefit or that not having it has caused some sort of issue. Currently, it just seems a lot easier to use because it's ready-to-use without the need for initialising.

ddtrace/tracer/stats.go Outdated Show resolved Hide resolved
ddtrace/tracer/stats.go Outdated Show resolved Hide resolved
ddtrace/tracer/stats.go Outdated Show resolved Hide resolved
Kyle-Verhoog and others added 2 commits July 25, 2022 16:38
There is no reason to use either of these functions individually so
makes sense to merge them.
@ajgajg1134 ajgajg1134 requested a review from gbbr July 25, 2022 20:56
ddtrace/tracer/stats.go Outdated Show resolved Hide resolved
@ajgajg1134 ajgajg1134 merged commit 596c50e into main Jul 26, 2022
@ajgajg1134 ajgajg1134 deleted the kylev/force-stats branch July 26, 2022 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants