Fix span offset

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2020-04-13 15:50:40 +02:00
parent abe540f8c0
commit d1f5366b52
1 changed files with 4 additions and 4 deletions

View File

@ -473,20 +473,20 @@ func makeSparseBuckets(buckets *sync.Map) *dto.SparseBuckets {
sbs := dto.SparseBuckets{} sbs := dto.SparseBuckets{}
var prevCount uint64 var prevCount uint64
var prevI int var nextI int
for n, i := range ii { for n, i := range ii {
v, _ := buckets.Load(i) v, _ := buckets.Load(i)
count := atomic.LoadUint64(v.(*uint64)) count := atomic.LoadUint64(v.(*uint64))
if n == 0 || i-prevI != 1 { if n == 0 || i-nextI != 0 {
sbs.Span = append(sbs.Span, &dto.SparseBuckets_Span{ sbs.Span = append(sbs.Span, &dto.SparseBuckets_Span{
Offset: proto.Int(i - prevI), Offset: proto.Int(i - nextI),
Length: proto.Uint32(1), Length: proto.Uint32(1),
}) })
} else { } else {
*sbs.Span[len(sbs.Span)-1].Length++ *sbs.Span[len(sbs.Span)-1].Length++
} }
sbs.Delta = append(sbs.Delta, int64(count)-int64(prevCount)) // TODO(beorn7): Do proper overflow handling. sbs.Delta = append(sbs.Delta, int64(count)-int64(prevCount)) // TODO(beorn7): Do proper overflow handling.
prevI, prevCount = i, count nextI, prevCount = i+1, count
} }
return &sbs return &sbs
} }