github-vet / github-vet/rangeloop-pointer-findings

circonus-labs/irondb-prometheus-adapter: handlers/prometheus2_0.go; 37 LoC

Open
#16,275 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [circonus-labs/irondb-prometheus-adapter](https://www.github.com/circonus-labs/irondb-prometheus-adapter) at [handlers/prometheus2_0.go](https://github.com/circonus-labs/irondb-prometheus-adapter/blob/aa026c9e0fcc3b5c2cc286df9ee1e3f64ec8296e/handlers/prometheus2_0.go#L274-L310)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.

> range-loop variable v used in defer or goroutine at line 281

[Click here to see the code in its original context.](https://github.com/circonus-labs/irondb-prometheus-adapter/blob/aa026c9e0fcc3b5c2cc286df9ee1e3f64ec8296e/handlers/prometheus2_0.go#L274-L310)

Click here to show the 37 line(s) of Go which triggered the analyzer.

```go
for _, v := range tagResp {
wg.Add(1)
go func() {
defer wg.Done()
// for all of our tag responses, grab the rollups
start := time.Now()
values, err := snowthClient.ReadRollupValues(
node, prp.checkUUID.String(), v.MetricName, []string{}, step,
time.Unix(0, q.StartTimestampMs*int64(time.Millisecond)),
time.Unix(0, q.EndTimestampMs*int64(time.Millisecond)),
)

ctx.Logger().Warnf("timing rollup query: %s, %s, %d, %d, %d, result length: %d, duration: %v",
prp.checkUUID.String(), v.MetricName, int64(step), q.StartTimestampMs*int64(time.Millisecond),
q.EndTimestampMs*int64(time.Millisecond), len(values), time.Now().Sub(start))
ctx.Logger().Debugf("rollup results: %+v", values)
timeSeries := new(prompb.TimeSeries)
if err != nil {
ctx.Logger().Errorf("failed to read rollup: %s", err.Error())
tsChan <- timeSeries
return
}

timeSeries.Labels = metricNameToLabelPairs(v.MetricName)

for _, v := range values {
// convert value to time series
timeSeries.Samples = append(timeSeries.Samples,
&prompb.Sample{
Value: v.Value,
Timestamp: v.Timestamp * 1000, // prom does ms
})
}
// add the timeseries to the query result
tsChan <- timeSeries
}()
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: aa026c9e0fcc3b5c2cc286df9ee1e3f64ec8296e

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.