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)
|
app.AppendHistogram(tOld, hOld)
|
||||||
}
|
}
|
||||||
|
|
||||||
return hc, app
|
return hc, app
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,41 +159,36 @@ func compareSpans(a, b []histogram.Span) ([]Interjection, bool) {
|
||||||
|
|
||||||
av, aok := ai.Next()
|
av, aok := ai.Next()
|
||||||
bv, bok := bi.Next()
|
bv, bok := bi.Next()
|
||||||
|
loop:
|
||||||
for {
|
for {
|
||||||
if aok && bok {
|
switch {
|
||||||
if av == bv { // both have an identical value. move on!
|
case aok && bok:
|
||||||
// finish WIP interjection and reset
|
switch {
|
||||||
|
case av == bv: // Both have an identical value. move on!
|
||||||
|
// Finish WIP interjection and reset.
|
||||||
if inter.num > 0 {
|
if inter.num > 0 {
|
||||||
interjections = append(interjections, inter)
|
interjections = append(interjections, inter)
|
||||||
}
|
}
|
||||||
inter.num = 0
|
inter.num = 0
|
||||||
av, aok = ai.Next()
|
av, aok = ai.Next()
|
||||||
bv, bok = bi.Next()
|
bv, bok = bi.Next()
|
||||||
if aok {
|
inter.pos++
|
||||||
inter.pos++
|
case av < bv: // b misses a value that is in a.
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if av < bv { // b misses a value that is in a.
|
|
||||||
return interjections, false
|
return interjections, false
|
||||||
}
|
case av > bv: // a misses a value that is in b. Forward b and recompare.
|
||||||
if av > bv { // a misses a value that is in b. forward b and recompare
|
|
||||||
inter.num++
|
inter.num++
|
||||||
bv, bok = bi.Next()
|
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
|
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.num++
|
||||||
inter.pos++
|
|
||||||
bv, bok = bi.Next()
|
bv, bok = bi.Next()
|
||||||
continue
|
default: // Both iterators ran out. We're done.
|
||||||
} else { // both iterators ran out. we're done
|
|
||||||
if inter.num > 0 {
|
if inter.num > 0 {
|
||||||
interjections = append(interjections, inter)
|
interjections = append(interjections, inter)
|
||||||
}
|
}
|
||||||
break
|
break loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,6 +187,28 @@ func TestInterjection(t *testing.T) {
|
||||||
bucketsIn: []int64{6, -3, 0},
|
bucketsIn: []int64{6, -3, 0},
|
||||||
bucketsOut: []int64{6, -3, 0, -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",
|
description: "single removal of bucket at the start",
|
||||||
spansA: []histogram.Span{
|
spansA: []histogram.Span{
|
||||||
|
@ -218,7 +240,6 @@ func TestInterjection(t *testing.T) {
|
||||||
},
|
},
|
||||||
valid: false,
|
valid: false,
|
||||||
},
|
},
|
||||||
// TODO(beorn7): Add more scenarios.
|
|
||||||
{
|
{
|
||||||
description: "as described in doc comment",
|
description: "as described in doc comment",
|
||||||
spansA: []histogram.Span{
|
spansA: []histogram.Span{
|
||||||
|
|
|
@ -16,7 +16,6 @@ package tsdb
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/prometheus/prometheus/pkg/histogram"
|
|
||||||
"math"
|
"math"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
@ -32,6 +31,7 @@ import (
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
|
|
||||||
"github.com/prometheus/prometheus/pkg/exemplar"
|
"github.com/prometheus/prometheus/pkg/exemplar"
|
||||||
|
"github.com/prometheus/prometheus/pkg/histogram"
|
||||||
"github.com/prometheus/prometheus/pkg/labels"
|
"github.com/prometheus/prometheus/pkg/labels"
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
"github.com/prometheus/prometheus/tsdb/chunkenc"
|
"github.com/prometheus/prometheus/tsdb/chunkenc"
|
||||||
|
|
Loading…
Reference in a new issue