Skip to content

Commit

Permalink
drop NaN count series to match average ones
Browse files Browse the repository at this point in the history
  • Loading branch information
javiermolinar committed Oct 29, 2024
1 parent 85dd9c1 commit a859d3f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pkg/traceql/engine_metrics_average.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (b *averageOverTimeSeriesAggregator) Combine(in []*tempopb.TimeSeries) {
// This is a counter label, we can skip it
continue
}
for _, sample := range ts.Samples {
for i, sample := range ts.Samples {
pos := IntervalOfMs(sample.TimestampMs, b.start, b.end, b.step)
if pos < 0 || pos >= len(b.weightedAverageSeries[ts.PromLabels].values) {
continue
Expand All @@ -225,7 +225,7 @@ func (b *averageOverTimeSeriesAggregator) Combine(in []*tempopb.TimeSeries) {
currentWeight := b.weightedAverageSeries[counterLabel].values[pos]

newAvg := sample.Value
newWeight := in[countPosMapper[counterLabel]].Samples[pos].Value
newWeight := in[countPosMapper[counterLabel]].Samples[i].Value

mean, weight := b.addWeigthedMean(currentMean, currentWeight, newAvg, newWeight)

Expand Down Expand Up @@ -419,18 +419,18 @@ func (g *avgOverTimeSpanAggregator[F, S]) Observe(span Span) {
}

s := g.getSeries(span)

s.count[interval]++
if math.IsNaN(s.avg[interval]) && !math.IsNaN(inc) {
// When we have a proper value in the span we need to initialize to 0
s.avg[interval] = 0
s.count[interval] = 1
}
mean, c := averageInc(s.avg[interval], inc, s.count[interval], s.compensation[interval])
s.count[interval]++
s.avg[interval] = mean
s.compensation[interval] = c
}

func averageInc(mean, inc, count, compensation float64) (float64, float64) {
if math.IsNaN(mean) && !math.IsNaN(inc) {
// When we have a proper value in the span we need to initialize to 0
mean = 0
}
if math.IsInf(mean, 0) {
if math.IsInf(inc, 0) && (mean > 0) == (inc > 0) {
// The `current.val` and `new` values are `Inf` of the same sign. They
Expand Down Expand Up @@ -576,6 +576,7 @@ func (g *avgOverTimeSpanAggregator[F, S]) getSeries(span Span) avgOverTimeSeries
}
for i := 0; i < intervals; i++ {
s.avg[i] = math.Float64frombits(normalNaN)
s.count[i] = math.Float64frombits(normalNaN)
}

g.series[g.buf.fast] = s
Expand Down

0 comments on commit a859d3f

Please sign in to comment.