Skip to content

web/api: add limit parameter#12823

Closed
rexagod wants to merge 1 commit intoprometheus:mainfrom
rexagod:12795
Closed

web/api: add limit parameter#12823
rexagod wants to merge 1 commit intoprometheus:mainfrom
rexagod:12795

Conversation

@rexagod
Copy link
Copy Markdown
Collaborator

@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 <[email protected]>
}

func parseLimitParam(limitStr string) (limit int, err error) {
limit = int(^uint(0) >> 1) // MaxInt
Copy link
Copy Markdown
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 :)


func parseLimitParam(limitStr string) (limit int, err error) {
limit = int(^uint(0) >> 1) // MaxInt
if limitStr != "" {
Copy link
Copy Markdown
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
}
...

names = []string{}
}

// Respect the "limit" parameter.
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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