Skip to content

Commit

Permalink
Chore: use strconv.ParseInt() with 32bit when parsing 32bit numbers (g…
Browse files Browse the repository at this point in the history
…rafana#10201)

* Chore: use strconv.ParseInt() with 32bit when parsing ingester ID

Signed-off-by: Marco Pracucci <[email protected]>

* Address parsing in NewMetadataHandler()

Signed-off-by: Marco Pracucci <[email protected]>

* Fix linter issue

Signed-off-by: Marco Pracucci <[email protected]>

* Remove noop casting

Signed-off-by: Marco Pracucci <[email protected]>

---------

Signed-off-by: Marco Pracucci <[email protected]>
  • Loading branch information
pracucci authored and bjorns163 committed Dec 30, 2024
1 parent ee1c0b4 commit 530aa0c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
26 changes: 16 additions & 10 deletions pkg/querier/metadata_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,34 @@ type metadataErrorResult struct {
// Mimir for a given tenant. It is kept and returned as a set.
func NewMetadataHandler(m MetadataSupplier) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
limit := -1
limit := int32(-1)
if s := r.FormValue("limit"); s != "" {
var err error
if limit, err = strconv.Atoi(s); err != nil {
parsed, err := strconv.ParseInt(s, 10, 32)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
util.WriteJSONResponse(w, metadataErrorResult{Status: statusError, Error: "limit must be a number"})
return
}

limit = int32(parsed)
}
limitPerMetric := -1

limitPerMetric := int32(-1)
if s := r.FormValue("limit_per_metric"); s != "" {
var err error
if limitPerMetric, err = strconv.Atoi(s); err != nil {
parsed, err := strconv.ParseInt(s, 10, 32)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
util.WriteJSONResponse(w, metadataErrorResult{Status: statusError, Error: "limit_per_metric must be a number"})
return
}

limitPerMetric = int32(parsed)
}

metric := r.FormValue("metric")
req := &client.MetricsMetadataRequest{
Limit: int32(limit),
LimitPerMetric: int32(limitPerMetric),
Limit: limit,
LimitPerMetric: limitPerMetric,
Metric: metric,
}

Expand All @@ -87,11 +93,11 @@ func NewMetadataHandler(m MetadataSupplier) http.Handler {
// We enforce this both here and in the ingesters. Doing it in the ingesters is
// more efficient as it is earlier in the process, but since that one is per user,
// we still need to do it here after all the results are merged.
if limitPerMetric > 0 && len(ms) >= limitPerMetric {
if limitPerMetric > 0 && len(ms) >= int(limitPerMetric) {
continue
}
if !ok {
if limit >= 0 && len(metrics) >= limit {
if limit >= 0 && len(metrics) >= int(limit) {
break
}
// Most metrics will only hold 1 copy of the same metadata.
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/ingest/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func IngesterPartitionID(ingesterID string) (int32, error) {
}

// Parse the ingester sequence number.
ingesterSeq, err := strconv.Atoi(match[1])
ingesterSeq, err := strconv.ParseInt(match[1], 10, 32)
if err != nil {
return 0, fmt.Errorf("no ingester sequence number in ingester ID %s", ingesterID)
}
Expand Down

0 comments on commit 530aa0c

Please sign in to comment.