mirror of https://github.com/prometheus/prometheus
Simplfied loops and functions
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>pull/5805/head
parent
0908b0d27e
commit
5d2e72269b
59
head_test.go
59
head_test.go
|
@ -226,7 +226,7 @@ func TestHeadBlock_e2e(t *testing.T) {
|
||||||
|
|
||||||
for _, l := range lbls {
|
for _, l := range lbls {
|
||||||
ls := labels.New(l...)
|
ls := labels.New(l...)
|
||||||
series := seriesMap[labels.New(l...).String()]
|
series := []sample{}
|
||||||
|
|
||||||
ts := rand.Int63n(300)
|
ts := rand.Int63n(300)
|
||||||
for i := 0; i < numDatapoints; i++ {
|
for i := 0; i < numDatapoints; i++ {
|
||||||
|
@ -268,21 +268,15 @@ func TestHeadBlock_e2e(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, qry := range queries {
|
for _, qry := range queries {
|
||||||
matched := []labels.Labels{}
|
matched := labels.Slice{}
|
||||||
Outer:
|
|
||||||
for _, ls := range lbls {
|
for _, ls := range lbls {
|
||||||
for _, m := range qry.ms {
|
s := labels.Selector(qry.ms)
|
||||||
if !matchLSet(m, ls) {
|
if s.Matches(ls) {
|
||||||
continue Outer
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
matched = append(matched, ls)
|
matched = append(matched, ls)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sort.Slice(matched, func(i, j int) bool {
|
sort.Sort(matched)
|
||||||
return labels.Compare(matched[i], matched[j]) < 0
|
|
||||||
})
|
|
||||||
|
|
||||||
for i := 0; i < numRanges; i++ {
|
for i := 0; i < numRanges; i++ {
|
||||||
mint := rand.Int63n(300)
|
mint := rand.Int63n(300)
|
||||||
|
@ -312,7 +306,7 @@ func TestHeadBlock_e2e(t *testing.T) {
|
||||||
for {
|
for {
|
||||||
eok, rok := expSs.Next(), ss.Next()
|
eok, rok := expSs.Next(), ss.Next()
|
||||||
|
|
||||||
// HACK: Skip a series if iterator is empty.
|
// Skip a series if iterator is empty.
|
||||||
if rok {
|
if rok {
|
||||||
for !ss.At().Iterator().Next() {
|
for !ss.At().Iterator().Next() {
|
||||||
rok = ss.Next()
|
rok = ss.Next()
|
||||||
|
@ -345,37 +339,18 @@ func TestHeadBlock_e2e(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func boundedSamples(full []sample, mint, maxt int64) []sample {
|
func boundedSamples(full []sample, mint, maxt int64) []sample {
|
||||||
start, end := -1, -1
|
for len(full) > 0 {
|
||||||
|
if full[0].t >= mint {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
full = full[1:]
|
||||||
|
}
|
||||||
for i, s := range full {
|
for i, s := range full {
|
||||||
if s.t >= mint {
|
// Terminate on the first sample larger than maxt.
|
||||||
start = i
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if start == -1 {
|
|
||||||
start = len(full)
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, s := range full[start:] {
|
|
||||||
if s.t > maxt {
|
if s.t > maxt {
|
||||||
end = start + i
|
return full[:i]
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// maxt is after highest sample.
|
||||||
if end == -1 {
|
return full
|
||||||
end = len(full)
|
|
||||||
}
|
|
||||||
|
|
||||||
return full[start:end]
|
|
||||||
}
|
|
||||||
|
|
||||||
func matchLSet(m labels.Matcher, ls labels.Labels) bool {
|
|
||||||
for _, l := range ls {
|
|
||||||
if m.Name() == l.Name && m.Matches(l.Value) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue