Skip to content

Commit 4773b18

Browse files
committed
engine: add offending lset to error message
1 parent e1ae427 commit 4773b18

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

engine/engine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ func (q *compatibilityQuery) Exec(ctx context.Context) (ret *promql.Result) {
571571
if err != nil {
572572
return newErrResult(ret, err)
573573
}
574-
if extlabels.ContainsDuplicateLabelSet(resultSeries) {
575-
return newErrResult(ret, extlabels.ErrDuplicateLabelSet)
574+
if err := extlabels.CheckContainsDuplicateLabelSet(resultSeries); err != nil {
575+
return newErrResult(ret, err)
576576
}
577577

578578
series := make([]promql.Series, len(resultSeries))

engine/engine_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3759,7 +3759,7 @@ func TestInstantQuery(t *testing.T) {
37593759
t.Log("Applying comparison with NaN equality.")
37603760
equalsWithNaNs(t, oldResult, newResult)
37613761
} else if oldResult.Err != nil {
3762-
testutil.Equals(t, oldResult.Err.Error(), newResult.Err.Error())
3762+
testutil.NotOk(t, newResult.Err)
37633763
} else {
37643764
testutil.Equals(t, oldResult, newResult)
37653765
}

execution/function/histogram.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ func (o *histogramOperator) loadSeries(ctx context.Context) error {
183183
if err != nil {
184184
return err
185185
}
186-
if extlabels.ContainsDuplicateLabelSetAfterDroppingName(series) {
187-
return extlabels.ErrDuplicateLabelSet
186+
if err := extlabels.CheckContainsDuplicateLabelSetAfterDroppingName(series); err != nil {
187+
return err
188188
}
189189

190190
var (

extlabels/labels.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
package extlabels
55

66
import (
7+
"fmt"
8+
79
"github.com/cespare/xxhash/v2"
8-
"github.com/efficientgo/core/errors"
910
"github.com/prometheus/prometheus/model/labels"
1011
)
1112

12-
var (
13-
ErrDuplicateLabelSet = errors.New("vector cannot contain metrics with the same labelset")
14-
)
15-
16-
func ContainsDuplicateLabelSet(series []labels.Labels) bool {
13+
func CheckContainsDuplicateLabelSet(series []labels.Labels) error {
1714
var (
1815
buf = make([]byte, 0, 256)
1916
seen = make(map[uint64]struct{}, len(series))
@@ -25,14 +22,14 @@ func ContainsDuplicateLabelSet(series []labels.Labels) bool {
2522
buf = s.Bytes(buf)
2623
h := xxhash.Sum64(s.Bytes(buf))
2724
if _, ok := seen[h]; ok {
28-
return true
25+
return fmt.Errorf("vector cannot contain metrics with the same labelset (%s)", s.String())
2926
}
3027
seen[h] = struct{}{}
3128
}
32-
return false
29+
return nil
3330
}
3431

35-
func ContainsDuplicateLabelSetAfterDroppingName(series []labels.Labels) bool {
32+
func CheckContainsDuplicateLabelSetAfterDroppingName(series []labels.Labels) error {
3633
var (
3734
buf = make([]byte, 0, 256)
3835
seen = make(map[uint64]struct{}, len(series))
@@ -48,11 +45,11 @@ func ContainsDuplicateLabelSetAfterDroppingName(series []labels.Labels) bool {
4845

4946
h := xxhash.Sum64(lbls.Bytes(buf))
5047
if _, ok := seen[h]; ok {
51-
return true
48+
return fmt.Errorf("vector cannot contain metrics with same labelset (%s)", s.String())
5249
}
5350
seen[h] = struct{}{}
5451
}
55-
return false
52+
return nil
5653
}
5754

5855
// DropMetricName removes the __name__ label and returns the dropped name and remaining labels.

0 commit comments

Comments
 (0)