Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine: add offending lset to error message #314

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 6 additions & 10 deletions extlabels/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import (
"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 +21,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 errors.Newf("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))
Expand All @@ -48,11 +44,11 @@ func ContainsDuplicateLabelSetAfterDroppingName(series []labels.Labels) bool {

h := xxhash.Sum64(lbls.Bytes(buf))
if _, ok := seen[h]; ok {
return true
return errors.Newf("vector cannot contain metrics with the 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.
Expand Down
Loading