Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

weight spans using their sample rate #226

Merged
merged 1 commit into from
Feb 8, 2017
Merged

weight spans using their sample rate #226

merged 1 commit into from
Feb 8, 2017

Conversation

galdor
Copy link

@galdor galdor commented Feb 7, 2017

The root span of a trace can contain a _sample_rate value if the client
sampled spans. When this is the case, we scale stats (hit and error
counts, and durations) by a factor, or weight, equal to 1.0 / _sample_rate.

This also means that we have to use floating point values to accumulate
values for StatsRawBucket.

model/span.go Outdated
@@ -59,3 +64,14 @@ func NewFlushMarker() Span {
func (s *Span) End() int64 {
return s.Start + s.Duration
}

// Weight returns the weigth of the span as defined for sampling, i.e. the
Copy link
Member

Choose a reason for hiding this comment

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

typo: weight

model/span.go Outdated
// Weight returns the weigth of the span as defined for sampling, i.e. the
// inverse of the sampling rate.
func (s *Span) Weight() float64 {
sampleRate, found := s.Metrics[SpanSampleRateMetricKey]
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: but for consistency we use ok rather than found for maps

Copy link
Author

Choose a reason for hiding this comment

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

Having an element in a map is not "ok" (or not), but as you wish.

} else {
b.HandleSpan(s, t.Env, c.aggregators, nil)
b.HandleSpan(s, t.Env, c.aggregators, t.Root, nil)
Copy link
Member

Choose a reason for hiding this comment

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

For the API if we just use the weight of the root span can we consider passing just the weight rather than a pointer to the full span? Would avoid having to check for nil pointers downstream etc.

Copy link
Author

Choose a reason for hiding this comment

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

Sure.

The root span of a trace can contain a _sample_rate value if the client
sampled spans. When this is the case, we scale stats (hit and error
counts, and durations) by a factor, or weight, equal to 1.0 /
_sample_rate.

This also means that we have to use floating point values to accumulate
values in StatsRawBucket.
Copy link
Member

@LeoCavaille LeoCavaille left a comment

Choose a reason for hiding this comment

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

LGTM.
But as side note, we'll need to add a shit ton of documentation to make user understand that once they use that the stats will be really weird for certain cases.

@galdor galdor merged commit 622fa02 into master Feb 8, 2017
@galdor galdor deleted the nicolas/sampling branch February 8, 2017 13:43
duration int64
hits float64
errors float64
duration float64

Choose a reason for hiding this comment

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

Since we are ns here, we can stick to in64 without any significant lose of precision.

Copy link
Author

Choose a reason for hiding this comment

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

Or we can use float64 without losing precision, since it will be exported to a float64 value anyway (see next comment).

hits int64
errors int64
duration int64
hits float64

Choose a reason for hiding this comment

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

Is the move from int64 to float64 going to impact anything in the serialization/payload to the API? Is the API compatible?

Copy link
Member

Choose a reason for hiding this comment

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

I think this in an internal format only that we then export to the API payload format.

Copy link
Author

@galdor galdor Feb 8, 2017

Choose a reason for hiding this comment

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

These counters are for internal computations in StatsRawBucket. (*StatsRawBucket).Export() returns a StatsBucket which already stores data using Count structures which use float64 values.

@ufoot ufoot added this to the 5.12 milestone Mar 20, 2017
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