diff --git a/engine/engine.go b/engine/engine.go index 0108898d9..a7b4a0c25 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -571,8 +571,8 @@ func (q *compatibilityQuery) Exec(ctx context.Context) (ret *promql.Result) { if err != nil { return newErrResult(ret, err) } - if extlabels.ContainsDuplicateLabelSet(resultSeries) { - return newErrResult(ret, extlabels.ErrDuplicateLabelSet) + if err := extlabels.CheckContainsDuplicateLabelSet(resultSeries); err != nil { + return newErrResult(ret, err) } series := make([]promql.Series, len(resultSeries)) diff --git a/engine/engine_test.go b/engine/engine_test.go index 549e1c5d4..a65fba159 100644 --- a/engine/engine_test.go +++ b/engine/engine_test.go @@ -3759,7 +3759,7 @@ func TestInstantQuery(t *testing.T) { t.Log("Applying comparison with NaN equality.") equalsWithNaNs(t, oldResult, newResult) } else if oldResult.Err != nil { - testutil.Equals(t, oldResult.Err.Error(), newResult.Err.Error()) + testutil.NotOk(t, newResult.Err) } else { testutil.Equals(t, oldResult, newResult) } diff --git a/execution/function/histogram.go b/execution/function/histogram.go index fa5292e12..b04706e08 100644 --- a/execution/function/histogram.go +++ b/execution/function/histogram.go @@ -183,8 +183,8 @@ func (o *histogramOperator) loadSeries(ctx context.Context) error { if err != nil { return err } - if extlabels.ContainsDuplicateLabelSetAfterDroppingName(series) { - return extlabels.ErrDuplicateLabelSet + if err := extlabels.CheckContainsDuplicateLabelSetAfterDroppingName(series); err != nil { + return err } var ( diff --git a/extlabels/labels.go b/extlabels/labels.go index f8be0c1fb..cab3a5e1d 100644 --- a/extlabels/labels.go +++ b/extlabels/labels.go @@ -4,16 +4,13 @@ package extlabels import ( + "fmt" + "github.com/cespare/xxhash/v2" - "github.com/efficientgo/core/errors" "github.com/prometheus/prometheus/model/labels" ) -var ( - ErrDuplicateLabelSet = errors.New("vector cannot contain metrics with the same labelset") -) - -func ContainsDuplicateLabelSet(series []labels.Labels) bool { +func CheckContainsDuplicateLabelSet(series []labels.Labels) error { var ( buf = make([]byte, 0, 256) seen = make(map[uint64]struct{}, len(series)) @@ -25,14 +22,14 @@ func ContainsDuplicateLabelSet(series []labels.Labels) bool { buf = s.Bytes(buf) h := xxhash.Sum64(s.Bytes(buf)) if _, ok := seen[h]; ok { - return true + return fmt.Errorf("vector cannot contain metrics with the same labelset (%s)", s.String()) } seen[h] = struct{}{} } - return false + return nil } -func ContainsDuplicateLabelSetAfterDroppingName(series []labels.Labels) bool { +func CheckContainsDuplicateLabelSetAfterDroppingName(series []labels.Labels) error { var ( buf = make([]byte, 0, 256) seen = make(map[uint64]struct{}, len(series)) @@ -48,11 +45,11 @@ func ContainsDuplicateLabelSetAfterDroppingName(series []labels.Labels) bool { h := xxhash.Sum64(lbls.Bytes(buf)) if _, ok := seen[h]; ok { - return true + return fmt.Errorf("vector cannot contain metrics with same labelset (%s)", s.String()) } seen[h] = struct{}{} } - return false + return nil } // DropMetricName removes the __name__ label and returns the dropped name and remaining labels.