-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix index out of bound bug when comparing ZLabelSets #3520
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,7 @@ func (c queryRangeCodec) DecodeRequest(_ context.Context, r *http.Request) (quer | |
result.ReplicaLabels = r.Form[queryv1.ReplicaLabelsParam] | ||
} | ||
|
||
result.StoreMatchers, err = parseMatchersParam(r.Form[queryv1.StoreMatcherParam]) | ||
result.StoreMatchers, err = parseMatchersParam(r.Form[queryv1.StoreMatcherParam], queryv1.StoreMatcherParam) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is bad code smell - passing same information twice. Maybe we should pass just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -221,12 +221,12 @@ func parsePartialResponseParam(s string, defaultEnablePartialResponse bool) (boo | |
return defaultEnablePartialResponse, nil | ||
} | ||
|
||
func parseMatchersParam(ss []string) ([][]*labels.Matcher, error) { | ||
func parseMatchersParam(ss []string, matcherParam string) ([][]*labels.Matcher, error) { | ||
matchers := make([][]*labels.Matcher, 0, len(ss)) | ||
for _, s := range ss { | ||
ms, err := parser.ParseMetricSelector(s) | ||
if err != nil { | ||
return nil, httpgrpc.Errorf(http.StatusBadRequest, errCannotParse, queryv1.StoreMatcherParam) | ||
return nil, httpgrpc.Errorf(http.StatusBadRequest, errCannotParse, matcherParam) | ||
} | ||
matchers = append(matchers, ms) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -307,7 +307,8 @@ func (z ZLabelSets) Less(i, j int) bool { | |
l := 0 | ||
r := 0 | ||
var result int | ||
for l < z[i].Size() && r < z[j].Size() { | ||
lenI, lenJ := len(z[i].Labels), len(z[j].Labels) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 (: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :( |
||
for l < lenI && r < lenJ { | ||
result = z[i].Labels[l].Compare(z[j].Labels[r]) | ||
if result == 0 { | ||
l++ | ||
|
@@ -317,5 +318,5 @@ func (z ZLabelSets) Less(i, j int) bool { | |
return result < 0 | ||
} | ||
|
||
return l == z[i].Size() | ||
return l == lenI | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get this, why we cannot check this in loop below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. As you mentioned I ll remove this change since it is unrelated and I ll fix them in next pr against master