Skip to content

Conversation

rexagod
Copy link
Contributor

@rexagod rexagod commented Sep 10, 2023

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: #12795.


┌[rexagod@nebuchadnezzar] [/dev/ttys002]
└[~]> curl '0.0.0.0:9090/api/v1/series?match[]=kube_configmap_info&limit=1'
{"status":"success","data":[{"__name__":"kube_configmap_info","configmap":"cluster-info","instance":"127.0.0.1:8080","job":"prometheus","namespace":"kube-public"}]}%

┌[rexagod@nebuchadnezzar] [/dev/ttys002]
└[~]> curl '0.0.0.0:9090/api/v1/labels?limit=4'
{"status":"success","data":["__name__","call","cluster_ip","code"]}%

┌[rexagod@nebuchadnezzar] [/dev/ttys002]
└[~]> curl '0.0.0.0:9090/api/v1/label/__name__/values?limit=2'
{"status":"success","data":["go_gc_duration_seconds","go_gc_duration_seconds_count"]}%

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
Copy link
Contributor

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 != "" {
Copy link
Contributor

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.
Copy link
Contributor

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.

@gouthamve
Copy link
Member

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.

@beorn7
Copy link
Member

beorn7 commented Jan 15, 2024

Closing as this was picked up in #13396

@beorn7 beorn7 closed this Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a limit parameter to /api/v1/series and /api/v1/labels and /api/v1/label/{name}/values
4 participants