Skip to content

Commit

Permalink
add nil pointer check on tags injection (#634)
Browse files Browse the repository at this point in the history
* add nil pointer check on tags injection

Signed-off-by: James Ranson <[email protected]>

* add nil pointer check on tags injection

Signed-off-by: James Ranson <[email protected]>

* add nil pointer check on tags injection

Signed-off-by: James Ranson <[email protected]>

Signed-off-by: James Ranson <[email protected]>
  • Loading branch information
jranson authored Jan 25, 2023
1 parent 6bdd63a commit 4a7077e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
21 changes: 21 additions & 0 deletions pkg/timeseries/dataset/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func (ds *DataSet) CroppedClone(e timeseries.Extent) timeseries.Timeseries {
// range, return empty set and bail
if ds.ExtentList.OutsideOf(e) {
for i := range ds.Results {
if ds.Results[i] == nil {
continue
}
clone.Results[i] = &Result{
StatementID: ds.Results[i].StatementID,
Error: ds.Results[i].Error,
Expand Down Expand Up @@ -196,6 +199,9 @@ func (ds *DataSet) Clone() timeseries.Timeseries {
}

for i := range ds.Results {
if ds.Results[i] == nil {
continue
}
clone.Results[i] = ds.Results[i].Clone()
}
return clone
Expand Down Expand Up @@ -367,6 +373,9 @@ func (ds *DataSet) DefaultRangeCropper(e timeseries.Extent) {
// The DataSet has no extents, so no need to do anything
if x == 0 {
for i := range ds.Results {
if ds.Results[i] == nil {
continue
}
ds.Results[i].SeriesList = make([]*Series, 0)
}
ds.ExtentList = timeseries.ExtentList{}
Expand All @@ -376,6 +385,9 @@ func (ds *DataSet) DefaultRangeCropper(e timeseries.Extent) {
// range, return empty set and bail
if ds.ExtentList.OutsideOf(e) {
for i := range ds.Results {
if ds.Results[i] == nil {
continue
}
ds.Results[i].SeriesList = make([]*Series, 0)
}
ds.ExtentList = timeseries.ExtentList{}
Expand All @@ -401,6 +413,9 @@ func (ds *DataSet) DefaultRangeCropper(e timeseries.Extent) {
endNS := epoch.Epoch(e.End.UnixNano())

for i := range ds.Results {
if ds.Results[i] == nil {
continue
}
var wg sync.WaitGroup
if len(ds.Results[i].SeriesList) == 0 {
continue
Expand Down Expand Up @@ -441,6 +456,9 @@ func (ds *DataSet) DefaultRangeCropper(e timeseries.Extent) {
func (ds *DataSet) SeriesCount() int {
var cnt int
for i := range ds.Results {
if ds.Results[i] == nil {
continue
}
cnt += len(ds.Results[i].SeriesList)
}
return cnt
Expand All @@ -450,6 +468,9 @@ func (ds *DataSet) SeriesCount() int {
func (ds *DataSet) ValueCount() int64 {
var cnt int64
for i := range ds.Results {
if ds.Results[i] == nil {
continue
}
if len(ds.Results[i].SeriesList) == 0 {
continue
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/timeseries/dataset/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func testDataSet2() *DataSet {
StatementID: 0,
SeriesList: []*Series{
{sh1, newPoints(), s},
nil,
},
}

Expand All @@ -113,7 +114,7 @@ func testDataSet2() *DataSet {

ds := &DataSet{
TimeRangeQuery: &timeseries.TimeRangeQuery{Step: time.Duration(5 * timeseries.Second)},
Results: []*Result{r1, r2},
Results: []*Result{r1, r2, nil},
ExtentList: timeseries.ExtentList{timeseries.Extent{Start: time.Unix(5, 0), End: time.Unix(30, 0)}},
}

Expand Down Expand Up @@ -213,7 +214,7 @@ func TestMerge(t *testing.T) {

ds.Merge(false, ds2)

if ds.SeriesCount() != 4 {
if ds.SeriesCount() != 5 {
t.Errorf("expected %d got %d", 4, ds.SeriesCount())
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/timeseries/dataset/series_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ func (sl SeriesList) Equal(sl2 SeriesList) bool {
return false
}
for i, v := range sl {
if v == nil {
continue
}
if v.Header.CalculateHash() != sl2[i].Header.CalculateHash() {
return false
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/timeseries/dataset/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ func (ds *DataSet) InjectTags(tags Tags) {
var wg sync.WaitGroup
var mtx sync.Mutex
for _, r := range ds.Results {
if r == nil {
continue
}
for _, s := range r.SeriesList {
if s == nil {
continue
}
wg.Add(1)
go func(s1 *Series) {
mtx.Lock()
Expand Down

0 comments on commit 4a7077e

Please sign in to comment.