Skip to content
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

Fix bug where blank limit was being interpreted as 0 #615

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading