Skip to content

Commit

Permalink
engine: add offending lset to error message
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Hoffmann <[email protected]>
  • Loading branch information
MichaHoffmann committed Sep 3, 2023
1 parent e1ae427 commit f3e1488
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions execution/function/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
19 changes: 8 additions & 11 deletions extlabels/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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())

Check failure on line 25 in extlabels/labels.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

declaration "Errorf" from package "fmt" shouldn't be used, suggested: "github.com/efficientgo/core/errors.{Wrap,Wrapf}"
}
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))
Expand All @@ -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())

Check failure on line 48 in extlabels/labels.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

declaration "Errorf" from package "fmt" shouldn't be used, suggested: "github.com/efficientgo/core/errors.{Wrap,Wrapf}"
}
seen[h] = struct{}{}
}
return false
return nil
}

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

0 comments on commit f3e1488

Please sign in to comment.