Chore: Enable more go-ruleguard rules (#29781)

* Chore: Enable more go-ruleguard rules

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen
2020-12-14 15:51:59 +01:00
committed by GitHub
parent e33c7cfbd2
commit 3fdf4be529
8 changed files with 56 additions and 62 deletions

View File

@@ -5,7 +5,6 @@ import (
"math"
"reflect"
"runtime"
"time"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/expr/mathexp/parse"
@@ -130,7 +129,7 @@ func (e *State) walkUnary(node *parse.UnaryNode) (Results, error) {
}
func (e *State) unarySeries(s Series, op string) (Series, error) {
newSeries := NewSeries(e.RefID, s.GetLabels(), s.TimeIdx, s.TimeIsNullable, s.ValueIdx, s.ValueIsNullabe, s.Len())
newSeries := NewSeries(e.RefID, s.GetLabels(), s.TimeIdx, s.TimeIsNullable, s.ValueIdx, s.ValueIsNullable, s.Len())
for i := 0; i < s.Len(); i++ {
t, f := s.GetPoint(i)
if f == nil {
@@ -432,7 +431,7 @@ func (e *State) biScalarNumber(labels data.Labels, op string, number Number, sca
}
func (e *State) biSeriesNumber(labels data.Labels, op string, s Series, scalarVal *float64, seriesFirst bool) (Series, error) {
newSeries := NewSeries(e.RefID, labels, s.TimeIdx, s.TimeIsNullable, s.ValueIdx, s.ValueIsNullabe, s.Len())
newSeries := NewSeries(e.RefID, labels, s.TimeIdx, s.TimeIsNullable, s.ValueIdx, s.ValueIsNullable, s.Len())
var err error
for i := 0; i < s.Len(); i++ {
nF := math.NaN()
@@ -462,18 +461,21 @@ func (e *State) biSeriesNumber(labels data.Labels, op string, s Series, scalarVa
// biSeriesSeries performs a the binary operation for each value in the two series where the times
// are equal. If there are datapoints in A or B that do not share a time, they will be dropped.
func (e *State) biSeriesSeries(labels data.Labels, op string, aSeries, bSeries Series) (Series, error) {
bPoints := make(map[time.Time]*float64)
bPoints := make(map[string]*float64)
for i := 0; i < bSeries.Len(); i++ {
t, f := bSeries.GetPoint(i)
if t != nil {
bPoints[*t] = f
bPoints[t.UTC().String()] = f
}
}
newSeries := NewSeries(e.RefID, labels, aSeries.TimeIdx, aSeries.TimeIsNullable || bSeries.TimeIsNullable, aSeries.ValueIdx, aSeries.ValueIsNullabe || bSeries.ValueIsNullabe, 0)
newSeries := NewSeries(
e.RefID, labels, aSeries.TimeIdx, aSeries.TimeIsNullable || bSeries.TimeIsNullable, aSeries.ValueIdx,
aSeries.ValueIsNullable || bSeries.ValueIsNullable, 0,
)
for aIdx := 0; aIdx < aSeries.Len(); aIdx++ {
aTime, aF := aSeries.GetPoint(aIdx)
bF, ok := bPoints[*aTime]
bF, ok := bPoints[aTime.UTC().String()]
if !ok {
continue
}

View File

@@ -95,7 +95,10 @@ func perFloat(e *State, val Value, floatF func(x float64) float64) (Value, error
newVal = NewScalar(e.RefID, &nF)
case parse.TypeSeriesSet:
resSeries := val.(Series)
newSeries := NewSeries(e.RefID, resSeries.GetLabels(), resSeries.TimeIdx, resSeries.TimeIsNullable, resSeries.ValueIdx, resSeries.ValueIsNullabe, resSeries.Len())
newSeries := NewSeries(
e.RefID, resSeries.GetLabels(), resSeries.TimeIdx, resSeries.TimeIsNullable, resSeries.ValueIdx,
resSeries.ValueIsNullable, resSeries.Len(),
)
for i := 0; i < resSeries.Len(); i++ {
t, f := resSeries.GetPoint(i)
nF := math.NaN()

View File

@@ -14,7 +14,7 @@ func (s Series) Resample(refID string, interval time.Duration, downsampler strin
if newSeriesLength <= 0 {
return s, fmt.Errorf("the series cannot be sampled further; the time range is shorter than the interval")
}
resampled := NewSeries(refID, s.GetLabels(), s.TimeIdx, s.TimeIsNullable, s.ValueIdx, s.ValueIsNullabe, newSeriesLength+1)
resampled := NewSeries(refID, s.GetLabels(), s.TimeIdx, s.TimeIsNullable, s.ValueIdx, s.ValueIsNullable, newSeriesLength+1)
bookmark := 0
var lastSeen *float64
idx := 0

View File

@@ -11,11 +11,11 @@ import (
// Series has time.Time and ...? *float64 fields.
type Series struct {
Frame *data.Frame
TimeIsNullable bool
TimeIdx int
ValueIsNullabe bool
ValueIdx int
Frame *data.Frame
TimeIsNullable bool
TimeIdx int
ValueIsNullable bool
ValueIdx int
// TODO:
// - Multiple Value Fields
// - Value can be different number types
@@ -43,7 +43,7 @@ func SeriesFromFrame(frame *data.Frame) (s Series, err error) {
foundValue = true
s.ValueIdx = i
case data.FieldTypeNullableFloat64:
s.ValueIsNullabe = true
s.ValueIsNullable = true
foundValue = true
s.ValueIdx = i
default:
@@ -77,11 +77,11 @@ func NewSeries(refID string, labels data.Labels, timeIdx int, nullableTime bool,
}
return Series{
Frame: data.NewFrame("", fields...),
TimeIsNullable: nullableTime,
TimeIdx: timeIdx,
ValueIsNullabe: nullableValue,
ValueIdx: valueIdx,
Frame: data.NewFrame("", fields...),
TimeIsNullable: nullableTime,
TimeIdx: timeIdx,
ValueIsNullable: nullableValue,
ValueIdx: valueIdx,
}
}
@@ -115,7 +115,7 @@ func (s Series) SetPoint(pointIdx int, t *time.Time, f *float64) (err error) {
}
s.Frame.Fields[s.TimeIdx].Set(pointIdx, *t)
}
if s.ValueIsNullabe {
if s.ValueIsNullable {
s.Frame.Fields[s.ValueIdx].Set(pointIdx, f)
} else {
if f == nil {
@@ -136,7 +136,7 @@ func (s Series) AppendPoint(pointIdx int, t *time.Time, f *float64) (err error)
}
s.Frame.Fields[s.TimeIdx].Append(*t)
}
if s.ValueIsNullabe {
if s.ValueIsNullable {
s.Frame.Fields[s.ValueIdx].Append(f)
} else {
if f == nil {
@@ -163,7 +163,7 @@ func (s Series) GetTime(pointIdx int) *time.Time {
// GetValue returns the float value at the specified index.
func (s Series) GetValue(pointIdx int) *float64 {
if s.ValueIsNullabe {
if s.ValueIsNullable {
return s.Frame.Fields[s.ValueIdx].At(pointIdx).(*float64)
}
f := s.Frame.Fields[s.ValueIdx].At(pointIdx).(float64)

View File

@@ -92,10 +92,10 @@ func TestSeriesFromFrame(t *testing.T) {
data.NewField("value", nil, []float64{}),
},
},
TimeIdx: 0,
TimeIsNullable: false,
ValueIdx: 1,
ValueIsNullabe: false,
TimeIdx: 0,
TimeIsNullable: false,
ValueIdx: 1,
ValueIsNullable: false,
},
},
{
@@ -117,10 +117,10 @@ func TestSeriesFromFrame(t *testing.T) {
data.NewField("time", nil, []*time.Time{unixTimePointer(5, 0)}),
},
},
TimeIdx: 1,
TimeIsNullable: true,
ValueIdx: 0,
ValueIsNullabe: true,
TimeIdx: 1,
TimeIsNullable: true,
ValueIdx: 0,
ValueIsNullable: true,
},
},
{