-
Notifications
You must be signed in to change notification settings - Fork 524
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
query-frontend: pass on limit
parameter for label names and values requests
#7722
Merged
dimitarvdimitrov
merged 7 commits into
main
from
dimitar/query-frontend/pass-limit-parameter-on-labels-requests
Apr 12, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
53f5f4f
query-frontend: pass on `limit` parameter for label names and values …
dimitarvdimitrov d750bb4
Add CHANGELOG.md entry
dimitarvdimitrov 81b3329
Use uint64 for limit
dimitarvdimitrov 663121c
Make limit setting more explicit
dimitarvdimitrov 67982cb
Merge branch 'main' into dimitar/query-frontend/pass-limit-parameter-…
dimitarvdimitrov f566012
Merge branch 'refs/heads/main' into dimitar/query-frontend/pass-limit…
dimitarvdimitrov dbd10c2
Add Limit to structs
dimitarvdimitrov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,8 @@ func TestLabelsQueryRequest(t *testing.T) { | |
expectedGetLabelName string | ||
expectedGetStartOrDefault int64 | ||
expectedGetEndOrDefault int64 | ||
expectedErr error | ||
expectedErr string | ||
expectedLimit uint64 | ||
}{ | ||
{ | ||
name: "label names with start and end timestamps, no matcher sets", | ||
|
@@ -205,7 +206,7 @@ func TestLabelsQueryRequest(t *testing.T) { | |
expectedGetEndOrDefault: 1708588800 * 1e3, | ||
}, | ||
{ | ||
name: "label names with start timestamp, no end timestamp, multiple matcher sets", | ||
name: "label names with start and end timestamp, multiple matcher sets", | ||
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. noticed that the test description here and below doesn't match the actual test case. Confirmed with @francoposa that it's the description that's wrong not the implementation |
||
url: "/api/v1/labels?end=1708588800&match%5B%5D=go_goroutines%7Bcontainer%3D~%22quer.%2A%22%7D&match%5B%5D=go_goroutines%7Bcontainer%21%3D%22query-scheduler%22%7D&start=1708502400", | ||
expectedStruct: &PrometheusLabelNamesQueryRequest{ | ||
Path: "/api/v1/labels", | ||
|
@@ -221,7 +222,7 @@ func TestLabelsQueryRequest(t *testing.T) { | |
expectedGetEndOrDefault: 1708588800 * 1e3, | ||
}, | ||
{ | ||
name: "label values with start timestamp, no end timestamp, multiple matcher sets", | ||
name: "label values with start and end timestamp, multiple matcher sets", | ||
url: "/api/v1/label/job/values?end=1708588800&match%5B%5D=go_goroutines%7Bcontainer%3D~%22quer.%2A%22%7D&match%5B%5D=go_goroutines%7Bcontainer%21%3D%22query-scheduler%22%7D&start=1708502400", | ||
expectedStruct: &PrometheusLabelValuesQueryRequest{ | ||
Path: "/api/v1/label/job/values", | ||
|
@@ -237,6 +238,53 @@ func TestLabelsQueryRequest(t *testing.T) { | |
expectedGetStartOrDefault: 1708502400 * 1e3, | ||
expectedGetEndOrDefault: 1708588800 * 1e3, | ||
}, | ||
{ | ||
name: "label names with start and end timestamp, multiple matcher sets, limit", | ||
url: "/api/v1/labels?end=1708588800&limit=10&match%5B%5D=go_goroutines%7Bcontainer%3D~%22quer.%2A%22%7D&match%5B%5D=go_goroutines%7Bcontainer%21%3D%22query-scheduler%22%7D&start=1708502400", | ||
expectedStruct: &PrometheusLabelNamesQueryRequest{ | ||
Path: "/api/v1/labels", | ||
Start: 1708502400 * 1e3, | ||
End: 1708588800 * 1e3, | ||
Limit: 10, | ||
LabelMatcherSets: []string{ | ||
"go_goroutines{container=~\"quer.*\"}", | ||
"go_goroutines{container!=\"query-scheduler\"}", | ||
}, | ||
}, | ||
expectedGetLabelName: "", | ||
expectedLimit: 10, | ||
expectedGetStartOrDefault: 1708502400 * 1e3, | ||
expectedGetEndOrDefault: 1708588800 * 1e3, | ||
}, | ||
{ | ||
name: "label values with start and end timestamp, multiple matcher sets, limit", | ||
url: "/api/v1/label/job/values?end=1708588800&limit=10&match%5B%5D=go_goroutines%7Bcontainer%3D~%22quer.%2A%22%7D&match%5B%5D=go_goroutines%7Bcontainer%21%3D%22query-scheduler%22%7D&start=1708502400", | ||
expectedStruct: &PrometheusLabelValuesQueryRequest{ | ||
Path: "/api/v1/label/job/values", | ||
LabelName: "job", | ||
Start: 1708502400 * 1e3, | ||
End: 1708588800 * 1e3, | ||
Limit: 10, | ||
LabelMatcherSets: []string{ | ||
"go_goroutines{container=~\"quer.*\"}", | ||
"go_goroutines{container!=\"query-scheduler\"}", | ||
}, | ||
}, | ||
expectedGetLabelName: "job", | ||
expectedLimit: 10, | ||
expectedGetStartOrDefault: 1708502400 * 1e3, | ||
expectedGetEndOrDefault: 1708588800 * 1e3, | ||
}, | ||
{ | ||
name: "zero limit is not allowed", | ||
url: "/api/v1/label/job/values?limit=0", | ||
expectedErr: "limit parameter must be a positive number: 0", | ||
}, | ||
{ | ||
name: "negative limit is not allowed", | ||
url: "/api/v1/label/job/values?limit=-1", | ||
expectedErr: "limit parameter must be a positive number: -1", | ||
}, | ||
} { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
for _, reqMethod := range []string{http.MethodGet, http.MethodPost} { | ||
|
@@ -261,13 +309,14 @@ func TestLabelsQueryRequest(t *testing.T) { | |
r = r.WithContext(ctx) | ||
|
||
reqDecoded, err := codec.DecodeLabelsQueryRequest(ctx, r) | ||
if err != nil || testCase.expectedErr != nil { | ||
require.EqualValues(t, testCase.expectedErr, err) | ||
if err != nil || testCase.expectedErr != "" { | ||
require.EqualError(t, err, testCase.expectedErr) | ||
return | ||
} | ||
require.EqualValues(t, testCase.expectedStruct, reqDecoded) | ||
require.EqualValues(t, testCase.expectedGetStartOrDefault, reqDecoded.GetStartOrDefault()) | ||
require.EqualValues(t, testCase.expectedGetEndOrDefault, reqDecoded.GetEndOrDefault()) | ||
require.EqualValues(t, testCase.expectedLimit, reqDecoded.GetLimit()) | ||
|
||
reqEncoded, err := codec.EncodeLabelsQueryRequest(context.Background(), reqDecoded) | ||
require.NoError(t, err) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
IIUC, passing the limit value no matter what means we rely on whatever
ParseInt()
returns in the error case when there's no limit. Would it be better (more obvious) to set a default value above and conditionally callParseInt()
?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.
this made me realize that I had missed setting the
limit
parameter on the HTTP request which the query-frontend creates (after processing the protobuf model). This wasn't a problem because the protobufs were only being used in caching logic (so no encoding into HTTP happens). Fixed in the last commit 663121c and added some more tests to make sure this happens properly