-
Notifications
You must be signed in to change notification settings - Fork 9.8k
web/api: add limit
parameter
#12823
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
web/api: add limit
parameter
#12823
Conversation
Support "limit" parameter in queries to restrict output data to the specified size. Changes were made towards the following endpoints: * /api/v1/series * /api/v1/labels * /api/v1/label/:name:/values Fixes: prometheus#12795. Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
@@ -1774,6 +1802,20 @@ func (api *API) respondError(w http.ResponseWriter, apiErr *apiError, data inter | |||
} | |||
} | |||
|
|||
func parseLimitParam(limitStr string) (limit int, err error) { | |||
limit = int(^uint(0) >> 1) // MaxInt |
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.
Let's just use math.MaxInt
:)
@@ -1774,6 +1802,20 @@ func (api *API) respondError(w http.ResponseWriter, apiErr *apiError, data inter | |||
} | |||
} | |||
|
|||
func parseLimitParam(limitStr string) (limit int, err error) { | |||
limit = int(^uint(0) >> 1) // MaxInt | |||
if limitStr != "" { |
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.
Return early:
if limitStr == "" {
return limit, nil
}
...
@@ -700,6 +700,16 @@ func (api *API) labelNames(r *http.Request) apiFuncResult { | |||
if names == nil { | |||
names = []string{} | |||
} | |||
|
|||
// Respect the "limit" parameter. |
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.
Probably also not worth adding all these comments because it's clear what this does.
Hi @rexagod, thanks for the PR. This looks useful, but the comments from @GiedriusS look reasonable. Would you like to update the PR? We looked at this at our bug scrub. |
Closing as this was picked up in #13396 |
Support
limit
parameter in queries to restrict output data to the specified size. Changes were made towards the following endpoints:Fixes: #12795.