mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -08:00
promql: fix unconvert issues (#4040)
See, $ gometalinter --vendor --disable-all --enable=unconvert --deadline 6m ./... promql/engine.go:1396:26⚠️ unnecessary conversion (unconvert) promql/engine.go:1396:40⚠️ unnecessary conversion (unconvert) promql/engine.go:1398:26⚠️ unnecessary conversion (unconvert) promql/engine.go:1398:40⚠️ unnecessary conversion (unconvert) promql/engine.go:1427:26⚠️ unnecessary conversion (unconvert) promql/engine.go:1427:40⚠️ unnecessary conversion (unconvert) promql/engine.go:1429:26⚠️ unnecessary conversion (unconvert) promql/engine.go:1429:40⚠️ unnecessary conversion (unconvert) promql/engine.go:1505:50⚠️ unnecessary conversion (unconvert) promql/engine.go:1573:46⚠️ unnecessary conversion (unconvert) promql/engine.go:1578:46⚠️ unnecessary conversion (unconvert) promql/engine.go:1591:80⚠️ unnecessary conversion (unconvert) promql/engine.go:1602:94⚠️ unnecessary conversion (unconvert) promql/engine.go:1630:18⚠️ unnecessary conversion (unconvert) promql/engine.go:1631:24⚠️ unnecessary conversion (unconvert) promql/engine.go:1634:18⚠️ unnecessary conversion (unconvert) promql/engine.go:1635:34⚠️ unnecessary conversion (unconvert) promql/functions.go:302:42⚠️ unnecessary conversion (unconvert) promql/functions.go:315:42⚠️ unnecessary conversion (unconvert) promql/functions.go:334:26⚠️ unnecessary conversion (unconvert) promql/functions.go:395:31⚠️ unnecessary conversion (unconvert) promql/functions.go:406:31⚠️ unnecessary conversion (unconvert) promql/functions.go:454:27⚠️ unnecessary conversion (unconvert) promql/functions.go:701:46⚠️ unnecessary conversion (unconvert) promql/functions.go:701:78⚠️ unnecessary conversion (unconvert) promql/functions.go:730:43⚠️ unnecessary conversion (unconvert) promql/functions.go:1220:23⚠️ unnecessary conversion (unconvert) promql/functions.go:1249:23⚠️ unnecessary conversion (unconvert) promql/quantile.go:107:54⚠️ unnecessary conversion (unconvert) promql/quantile.go:182:16⚠️ unnecessary conversion (unconvert) promql/quantile.go:182:64⚠️ unnecessary conversion (unconvert) Signed-off-by: Mario Trangoni <mjtrangoni@gmail.com>
This commit is contained in:
parent
e4bb42208f
commit
0e2aa35771
|
@ -1393,9 +1393,9 @@ func scalarBinop(op ItemType, lhs, rhs float64) float64 {
|
|||
case itemDIV:
|
||||
return lhs / rhs
|
||||
case itemPOW:
|
||||
return math.Pow(float64(lhs), float64(rhs))
|
||||
return math.Pow(lhs, rhs)
|
||||
case itemMOD:
|
||||
return math.Mod(float64(lhs), float64(rhs))
|
||||
return math.Mod(lhs, rhs)
|
||||
case itemEQL:
|
||||
return btos(lhs == rhs)
|
||||
case itemNEQ:
|
||||
|
@ -1424,9 +1424,9 @@ func vectorElemBinop(op ItemType, lhs, rhs float64) (float64, bool) {
|
|||
case itemDIV:
|
||||
return lhs / rhs, true
|
||||
case itemPOW:
|
||||
return math.Pow(float64(lhs), float64(rhs)), true
|
||||
return math.Pow(lhs, rhs), true
|
||||
case itemMOD:
|
||||
return math.Mod(float64(lhs), float64(rhs)), true
|
||||
return math.Mod(lhs, rhs), true
|
||||
case itemEQL:
|
||||
return lhs, lhs == rhs
|
||||
case itemNEQ:
|
||||
|
@ -1502,7 +1502,7 @@ func (ev *evaluator) aggregation(op ItemType, grouping []string, without bool, p
|
|||
lb.Del(labels.MetricName)
|
||||
}
|
||||
if op == itemCountValues {
|
||||
lb.Set(valueLabel, strconv.FormatFloat(float64(s.V), 'f', -1, 64))
|
||||
lb.Set(valueLabel, strconv.FormatFloat(s.V, 'f', -1, 64))
|
||||
}
|
||||
|
||||
var (
|
||||
|
@ -1570,12 +1570,12 @@ func (ev *evaluator) aggregation(op ItemType, grouping []string, without bool, p
|
|||
group.groupCount++
|
||||
|
||||
case itemMax:
|
||||
if group.value < s.V || math.IsNaN(float64(group.value)) {
|
||||
if group.value < s.V || math.IsNaN(group.value) {
|
||||
group.value = s.V
|
||||
}
|
||||
|
||||
case itemMin:
|
||||
if group.value > s.V || math.IsNaN(float64(group.value)) {
|
||||
if group.value > s.V || math.IsNaN(group.value) {
|
||||
group.value = s.V
|
||||
}
|
||||
|
||||
|
@ -1588,7 +1588,7 @@ func (ev *evaluator) aggregation(op ItemType, grouping []string, without bool, p
|
|||
group.groupCount++
|
||||
|
||||
case itemTopK:
|
||||
if int64(len(group.heap)) < k || group.heap[0].V < s.V || math.IsNaN(float64(group.heap[0].V)) {
|
||||
if int64(len(group.heap)) < k || group.heap[0].V < s.V || math.IsNaN(group.heap[0].V) {
|
||||
if int64(len(group.heap)) == k {
|
||||
heap.Pop(&group.heap)
|
||||
}
|
||||
|
@ -1599,7 +1599,7 @@ func (ev *evaluator) aggregation(op ItemType, grouping []string, without bool, p
|
|||
}
|
||||
|
||||
case itemBottomK:
|
||||
if int64(len(group.reverseHeap)) < k || group.reverseHeap[0].V > s.V || math.IsNaN(float64(group.reverseHeap[0].V)) {
|
||||
if int64(len(group.reverseHeap)) < k || group.reverseHeap[0].V > s.V || math.IsNaN(group.reverseHeap[0].V) {
|
||||
if int64(len(group.reverseHeap)) == k {
|
||||
heap.Pop(&group.reverseHeap)
|
||||
}
|
||||
|
@ -1627,12 +1627,12 @@ func (ev *evaluator) aggregation(op ItemType, grouping []string, without bool, p
|
|||
aggr.value = float64(aggr.groupCount)
|
||||
|
||||
case itemStdvar:
|
||||
avg := float64(aggr.value) / float64(aggr.groupCount)
|
||||
aggr.value = float64(aggr.valuesSquaredSum)/float64(aggr.groupCount) - avg*avg
|
||||
avg := aggr.value / float64(aggr.groupCount)
|
||||
aggr.value = aggr.valuesSquaredSum/float64(aggr.groupCount) - avg*avg
|
||||
|
||||
case itemStddev:
|
||||
avg := float64(aggr.value) / float64(aggr.groupCount)
|
||||
aggr.value = math.Sqrt(float64(aggr.valuesSquaredSum)/float64(aggr.groupCount) - avg*avg)
|
||||
avg := aggr.value / float64(aggr.groupCount)
|
||||
aggr.value = math.Sqrt(aggr.valuesSquaredSum/float64(aggr.groupCount) - avg*avg)
|
||||
|
||||
case itemTopK:
|
||||
// The heap keeps the lowest value on top, so reverse it.
|
||||
|
|
|
@ -299,7 +299,7 @@ func funcClampMax(vals []Value, args Expressions, enh *EvalNodeHelper) Vector {
|
|||
for _, el := range vec {
|
||||
enh.out = append(enh.out, Sample{
|
||||
Metric: enh.dropMetricName(el.Metric),
|
||||
Point: Point{V: math.Min(max, float64(el.V))},
|
||||
Point: Point{V: math.Min(max, el.V)},
|
||||
})
|
||||
}
|
||||
return enh.out
|
||||
|
@ -312,7 +312,7 @@ func funcClampMin(vals []Value, args Expressions, enh *EvalNodeHelper) Vector {
|
|||
for _, el := range vec {
|
||||
enh.out = append(enh.out, Sample{
|
||||
Metric: enh.dropMetricName(el.Metric),
|
||||
Point: Point{V: math.Max(min, float64(el.V))},
|
||||
Point: Point{V: math.Max(min, el.V)},
|
||||
})
|
||||
}
|
||||
return enh.out
|
||||
|
@ -331,7 +331,7 @@ func funcRound(vals []Value, args Expressions, enh *EvalNodeHelper) Vector {
|
|||
toNearestInverse := 1.0 / toNearest
|
||||
|
||||
for _, el := range vec {
|
||||
v := math.Floor(float64(el.V)*toNearestInverse+0.5) / toNearestInverse
|
||||
v := math.Floor(el.V*toNearestInverse+0.5) / toNearestInverse
|
||||
enh.out = append(enh.out, Sample{
|
||||
Metric: enh.dropMetricName(el.Metric),
|
||||
Point: Point{V: v},
|
||||
|
@ -392,7 +392,7 @@ func funcMaxOverTime(vals []Value, args Expressions, enh *EvalNodeHelper) Vector
|
|||
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
||||
max := math.Inf(-1)
|
||||
for _, v := range values {
|
||||
max = math.Max(max, float64(v.V))
|
||||
max = math.Max(max, v.V)
|
||||
}
|
||||
return max
|
||||
})
|
||||
|
@ -403,7 +403,7 @@ func funcMinOverTime(vals []Value, args Expressions, enh *EvalNodeHelper) Vector
|
|||
return aggrOverTime(vals, enh, func(values []Point) float64 {
|
||||
min := math.Inf(1)
|
||||
for _, v := range values {
|
||||
min = math.Min(min, float64(v.V))
|
||||
min = math.Min(min, v.V)
|
||||
}
|
||||
return min
|
||||
})
|
||||
|
@ -451,7 +451,7 @@ func funcStddevOverTime(vals []Value, args Expressions, enh *EvalNodeHelper) Vec
|
|||
count++
|
||||
}
|
||||
avg := sum / count
|
||||
return math.Sqrt(float64(squaredSum/count - avg*avg))
|
||||
return math.Sqrt(squaredSum/count - avg*avg)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -698,7 +698,7 @@ func funcChanges(vals []Value, args Expressions, enh *EvalNodeHelper) Vector {
|
|||
prev := samples.Points[0].V
|
||||
for _, sample := range samples.Points[1:] {
|
||||
current := sample.V
|
||||
if current != prev && !(math.IsNaN(float64(current)) && math.IsNaN(float64(prev))) {
|
||||
if current != prev && !(math.IsNaN(current) && math.IsNaN(prev)) {
|
||||
changes++
|
||||
}
|
||||
prev = current
|
||||
|
@ -727,7 +727,7 @@ func funcLabelReplace(vals []Value, args Expressions, enh *EvalNodeHelper) Vecto
|
|||
if err != nil {
|
||||
panic(fmt.Errorf("invalid regular expression in label_replace(): %s", regexStr))
|
||||
}
|
||||
if !model.LabelNameRE.MatchString(string(dst)) {
|
||||
if !model.LabelNameRE.MatchString(dst) {
|
||||
panic(fmt.Errorf("invalid destination label name in label_replace(): %s", dst))
|
||||
}
|
||||
enh.dmn = make(map[uint64]labels.Labels, len(enh.out))
|
||||
|
@ -1217,7 +1217,7 @@ func (s vectorByValueHeap) Len() int {
|
|||
}
|
||||
|
||||
func (s vectorByValueHeap) Less(i, j int) bool {
|
||||
if math.IsNaN(float64(s[i].V)) {
|
||||
if math.IsNaN(s[i].V) {
|
||||
return true
|
||||
}
|
||||
return s[i].V < s[j].V
|
||||
|
@ -1246,7 +1246,7 @@ func (s vectorByReverseValueHeap) Len() int {
|
|||
}
|
||||
|
||||
func (s vectorByReverseValueHeap) Less(i, j int) bool {
|
||||
if math.IsNaN(float64(s[i].V)) {
|
||||
if math.IsNaN(s[i].V) {
|
||||
return true
|
||||
}
|
||||
return s[i].V > s[j].V
|
||||
|
|
|
@ -104,7 +104,7 @@ func bucketQuantile(q float64, buckets buckets) float64 {
|
|||
count -= buckets[b-1].count
|
||||
rank -= buckets[b-1].count
|
||||
}
|
||||
return bucketStart + (bucketEnd-bucketStart)*float64(rank/count)
|
||||
return bucketStart + (bucketEnd-bucketStart)*(rank/count)
|
||||
}
|
||||
|
||||
// The assumption that bucket counts increase monotonically with increasing
|
||||
|
@ -179,5 +179,5 @@ func quantile(q float64, values vectorByValueHeap) float64 {
|
|||
upperIndex := math.Min(n-1, lowerIndex+1)
|
||||
|
||||
weight := rank - math.Floor(rank)
|
||||
return float64(values[int(lowerIndex)].V)*(1-weight) + float64(values[int(upperIndex)].V)*weight
|
||||
return values[int(lowerIndex)].V*(1-weight) + values[int(upperIndex)].V*weight
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue