Skip to content

Commit

Permalink
Fix bug where blank limit was being interpreted as 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksontj committed Sep 10, 2023
1 parent 9bb757c commit 81fdb1f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/proxystorage/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,24 +201,25 @@ func (p *ProxyStorage) ConfigHandler(w http.ResponseWriter, r *http.Request) {
// MetadataHandler is an implementation of the metadata handler within the prometheus API
func (p *ProxyStorage) MetadataHandler(w http.ResponseWriter, r *http.Request) {
// Check that "limit" is valid
var limit int
var limit *int
if s := r.FormValue("limit"); s != "" {
var err error
if limit, err = strconv.Atoi(s); err != nil {
i, err := strconv.Atoi(s)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
limit = &i
}

// Do the metadata lookup
state := p.GetState()
metadata, err := state.client.Metadata(r.Context(), r.FormValue("metric"), r.FormValue("limit"))

// Trim the results to the requested limit
if len(metadata) > limit {
if limit != nil && len(metadata) > *limit {
count := 0
for k := range metadata {
if count < limit {
if count < *limit {
count++
} else {
delete(metadata, k)
Expand Down

0 comments on commit 81fdb1f

Please sign in to comment.