Skip to content

Commit fc9efa4

Browse files
committed
fix bug of not updating map in ContainsSameLabelset
Signed-off-by: Harsh Agarwal <[email protected]>
1 parent cf36d49 commit fc9efa4

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

promql/engine.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -719,9 +719,6 @@ func (ev *evaluator) rangeEval(f func([]Value, *EvalNodeHelper) Vector, exprs ..
719719
// Make the function call.
720720
enh.ts = ts
721721
result := f(args, enh)
722-
if result.ContainsSameLabelset() {
723-
panic(fmt.Errorf("vector cannot contain metrics with the same labelset"))
724-
}
725722
enh.out = result[:0] // Reuse result vector.
726723
// If this could be an instant query, shortcut so as not to change sort order.
727724
if ev.endTimestamp == ev.startTimestamp {
@@ -730,6 +727,9 @@ func (ev *evaluator) rangeEval(f func([]Value, *EvalNodeHelper) Vector, exprs ..
730727
s.Point.T = ts
731728
mat[i] = Series{Metric: s.Metric, Points: []Point{s.Point}}
732729
}
730+
if mat.ContainsSameLabelset() {
731+
ev.errorf("vector cannot contain metrics with the same labelset")
732+
}
733733
return mat
734734
}
735735
// Add samples in output vector to output series.
@@ -758,6 +758,9 @@ func (ev *evaluator) rangeEval(f func([]Value, *EvalNodeHelper) Vector, exprs ..
758758
for _, ss := range seriess {
759759
mat = append(mat, ss)
760760
}
761+
if mat.ContainsSameLabelset() {
762+
ev.errorf("vector cannot contain metrics with the same labelset")
763+
}
761764
return mat
762765
}
763766

@@ -874,9 +877,6 @@ func (ev *evaluator) eval(expr Expr) Value {
874877
enh.ts = ts
875878
// Make the function call.
876879
outVec := e.Func.Call(inArgs, e.Args, enh)
877-
if outVec.ContainsSameLabelset() {
878-
panic(fmt.Errorf("vector cannot contain metrics with the same labelset"))
879-
}
880880
enh.out = outVec[:0]
881881
if len(outVec) > 0 {
882882
ss.Points = append(ss.Points, Point{V: outVec[0].Point.V, T: ts})
@@ -888,6 +888,10 @@ func (ev *evaluator) eval(expr Expr) Value {
888888
mat = append(mat, ss)
889889
}
890890
}
891+
if mat.ContainsSameLabelset() {
892+
ev.errorf("vector cannot contain metrics with the same labelset")
893+
}
894+
891895
putPointSlice(points)
892896
return mat
893897

promql/value.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ func (vec Vector) ContainsSameLabelset() bool {
149149
hash := s.Metric.Hash()
150150
if _, ok := l[hash]; ok {
151151
return true
152+
} else {
153+
l[hash] = struct{}{}
152154
}
153155
}
154156
return false
@@ -182,6 +184,8 @@ func (m Matrix) ContainsSameLabelset() bool {
182184
hash := ss.Metric.Hash()
183185
if _, ok := l[hash]; ok {
184186
return true
187+
} else {
188+
l[hash] = struct{}{}
185189
}
186190
}
187191
return false

0 commit comments

Comments
 (0)