mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Fix interjections even more
Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
parent
dc1c744169
commit
01957eee2b
tsdb
|
@ -387,7 +387,6 @@ func (a *HistoAppender) Recode(posInterjections, negInterjections []Interjection
|
|||
}
|
||||
app.AppendHistogram(tOld, hOld)
|
||||
}
|
||||
|
||||
return hc, app
|
||||
}
|
||||
|
||||
|
|
|
@ -159,41 +159,36 @@ func compareSpans(a, b []histogram.Span) ([]Interjection, bool) {
|
|||
|
||||
av, aok := ai.Next()
|
||||
bv, bok := bi.Next()
|
||||
loop:
|
||||
for {
|
||||
if aok && bok {
|
||||
if av == bv { // both have an identical value. move on!
|
||||
// finish WIP interjection and reset
|
||||
switch {
|
||||
case aok && bok:
|
||||
switch {
|
||||
case av == bv: // Both have an identical value. move on!
|
||||
// Finish WIP interjection and reset.
|
||||
if inter.num > 0 {
|
||||
interjections = append(interjections, inter)
|
||||
}
|
||||
inter.num = 0
|
||||
av, aok = ai.Next()
|
||||
bv, bok = bi.Next()
|
||||
if aok {
|
||||
inter.pos++
|
||||
}
|
||||
continue
|
||||
}
|
||||
if av < bv { // b misses a value that is in a.
|
||||
inter.pos++
|
||||
case av < bv: // b misses a value that is in a.
|
||||
return interjections, false
|
||||
}
|
||||
if av > bv { // a misses a value that is in b. forward b and recompare
|
||||
case av > bv: // a misses a value that is in b. Forward b and recompare.
|
||||
inter.num++
|
||||
bv, bok = bi.Next()
|
||||
continue
|
||||
}
|
||||
} else if aok && !bok { // b misses a value that is in a.
|
||||
case aok && !bok: // b misses a value that is in a.
|
||||
return interjections, false
|
||||
} else if !aok && bok { // a misses a value that is in b. forward b and recompare
|
||||
case !aok && bok: // a misses a value that is in b. Forward b and recompare.
|
||||
inter.num++
|
||||
inter.pos++
|
||||
bv, bok = bi.Next()
|
||||
continue
|
||||
} else { // both iterators ran out. we're done
|
||||
default: // Both iterators ran out. We're done.
|
||||
if inter.num > 0 {
|
||||
interjections = append(interjections, inter)
|
||||
}
|
||||
break
|
||||
break loop
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -187,6 +187,28 @@ func TestInterjection(t *testing.T) {
|
|||
bucketsIn: []int64{6, -3, 0},
|
||||
bucketsOut: []int64{6, -3, 0, -3, 0},
|
||||
},
|
||||
{
|
||||
description: "double prepond at the beginning and double append at the end",
|
||||
spansA: []histogram.Span{
|
||||
{Offset: -10, Length: 3},
|
||||
},
|
||||
spansB: []histogram.Span{
|
||||
{Offset: -12, Length: 7},
|
||||
},
|
||||
valid: true,
|
||||
interjections: []Interjection{
|
||||
{
|
||||
pos: 0,
|
||||
num: 2,
|
||||
},
|
||||
{
|
||||
pos: 3,
|
||||
num: 2,
|
||||
},
|
||||
},
|
||||
bucketsIn: []int64{6, -3, 0},
|
||||
bucketsOut: []int64{0, 0, 6, -3, 0, -3, 0},
|
||||
},
|
||||
{
|
||||
description: "single removal of bucket at the start",
|
||||
spansA: []histogram.Span{
|
||||
|
@ -218,7 +240,6 @@ func TestInterjection(t *testing.T) {
|
|||
},
|
||||
valid: false,
|
||||
},
|
||||
// TODO(beorn7): Add more scenarios.
|
||||
{
|
||||
description: "as described in doc comment",
|
||||
spansA: []histogram.Span{
|
||||
|
|
|
@ -16,7 +16,6 @@ package tsdb
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/prometheus/prometheus/pkg/histogram"
|
||||
"math"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -32,6 +31,7 @@ import (
|
|||
"go.uber.org/atomic"
|
||||
|
||||
"github.com/prometheus/prometheus/pkg/exemplar"
|
||||
"github.com/prometheus/prometheus/pkg/histogram"
|
||||
"github.com/prometheus/prometheus/pkg/labels"
|
||||
"github.com/prometheus/prometheus/storage"
|
||||
"github.com/prometheus/prometheus/tsdb/chunkenc"
|
||||
|
|
Loading…
Reference in a new issue