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

Track dropped spans #11

Closed
wants to merge 1 commit into from

Conversation

KevinMGranger
Copy link
Contributor

@KevinMGranger KevinMGranger commented Feb 28, 2018

The second half of the work from #9.

This is a bigger change, so I'd appreciate feedback.

I'd like to add in more unit testing for this stuff, but haven't yet.

@@ -111,4 +112,51 @@ void Tracer::reportSpan(Span &&span) {
void Tracer::setReporter(ReporterPtr reporter) {
reporter_ = std::move(reporter);
}

uint64_t Tracer::getDroppedSpanCount() const {
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 we want to expose these as part of the Reporter, we wouldn't have to cast anything.

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, that would be better.

Even if you want to cast, reinterpret_cast isn't the right one to use.

if (spans_.addSpan(span)) {
num_spans_reported_++;
} else {
dropped_span_count_++;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might be able to have loser memory ordering because of the mutex, but that might be a premature optimization.

uint64_t Tracer::getDroppedSpanCount() const {
ReporterImpl *reporter = reinterpret_cast<ReporterImpl *>(reporter_.get());
if (reporter) {
return reporter->getDroppedSpanCount();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These technically have race conditions. One could set the reporter to a nullptr, which would run the destructor on this pointer. Past that point, accessing the pointer is undefined behavior.

I say let's make it so you can't set the reporter pointer after construction.

Copy link
Owner

Choose a reason for hiding this comment

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

👍

@rnburn
Copy link
Owner

rnburn commented Feb 28, 2018

Instead of naming methods getXyz can you simply use xyz. The code was originally taken from Envoy and that matches with the style used elsewhere.

private:
TransporterPtr transporter_;

std::atomic_uint64_t dropped_span_count_{0};
Copy link
Owner

Choose a reason for hiding this comment

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

Can you use std::atomic<uint64_t> so that it matches what's used elsewhere.

@KevinMGranger
Copy link
Contributor Author

Feedback implemented.

@@ -123,6 +158,39 @@ class Tracer : public TracerInterface {
*/
void setReporter(ReporterPtr reporter);
Copy link
Owner

Choose a reason for hiding this comment

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

Weren't you going to remove the setReporter method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Co-authored-by: Kevin M Granger <git@kevinmgranger.me>
* @param report_period The new size of the span buffer
*/
void setReportPeriod(SteadyClock::duration reporting_period) override {
reporting_period_ = reporting_period;
Copy link
Owner

Choose a reason for hiding this comment

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

This has a race condition, no? Since reporting_period_ is read from another thread.

}

uint64_t Tracer::getAndResetDroppedSpanCount() {
return reporter_->getAndResetDroppedSpanCount();
Copy link
Owner

Choose a reason for hiding this comment

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

What would you think of adding a reporter accessor method to the Tracer class? Then you can get rid of all of these forwarding methods.

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 think that makes sense.

/**
* @return the number of spans that can be stored in the buffer
*/
virtual size_t bufferSpanCount() const { return 0; }
Copy link
Owner

Choose a reason for hiding this comment

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

Could we rename bufferSpanCount to maxBufferedSpans or spanBufferSize? -- the name doesn't seem quite right.

@rnburn
Copy link
Owner

rnburn commented Mar 14, 2018

@KevinMGranger -- how's this going? it looked like there was only a few issues left.

@KevinMGranger
Copy link
Contributor Author

Sorry for the holdup, I've been busy with some other work.

I've also been trying to figure out a good testing strategy for this, unless you think the changes are simple enough that we don't need to worry about it.

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