Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

nilpointer bugfix: in[0] may not exist. fix #674 #676

Merged
merged 1 commit into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions expr/func_avgseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,9 @@ func (s *FuncAvgSeries) Context(context Context) Context {
}

func (s *FuncAvgSeries) Exec(cache map[Req][]models.Series) ([]models.Series, error) {
var series []models.Series
var queryPatts []string
for i := range s.in {
in, err := s.in[i].Exec(cache)
if err != nil {
return nil, err
}
series = append(series, in...)
queryPatts = append(queryPatts, in[0].QueryPatt)
series, queryPatts, err := consumeFuncs(cache, s.in)
if err != nil {
return nil, err
}

if len(series) == 0 {
Expand Down
10 changes: 3 additions & 7 deletions expr/func_persecond.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,9 @@ func (s *FuncPerSecond) Context(context Context) Context {
}

func (s *FuncPerSecond) Exec(cache map[Req][]models.Series) ([]models.Series, error) {
var series []models.Series
for i := range s.in {
serie, err := s.in[i].Exec(cache)
if err != nil {
return nil, err
}
series = append(series, serie...)
series, _, err := consumeFuncs(cache, s.in)
if err != nil {
return nil, err
}
maxValue := math.NaN()
if s.maxValue > 0 {
Expand Down
12 changes: 3 additions & 9 deletions expr/func_sumseries.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,9 @@ func (s *FuncSumSeries) Context(context Context) Context {
}

func (s *FuncSumSeries) Exec(cache map[Req][]models.Series) ([]models.Series, error) {
var series []models.Series
var queryPatts []string
for i := range s.in {
in, err := s.in[i].Exec(cache)
if err != nil {
return nil, err
}
series = append(series, in...)
queryPatts = append(queryPatts, in[0].QueryPatt)
series, queryPatts, err := consumeFuncs(cache, s.in)
if err != nil {
return nil, err
}

if len(series) == 0 {
Expand Down
16 changes: 16 additions & 0 deletions expr/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,19 @@ func summarizeCons(series []models.Series) (consolidation.Consolidator, consolid
}
return series[0].Consolidator, series[0].QueryCons
}

func consumeFuncs(cache map[Req][]models.Series, fns []GraphiteFunc) ([]models.Series, []string, error) {
var series []models.Series
var queryPatts []string
for i := range fns {
in, err := fns[i].Exec(cache)
if err != nil {
return nil, nil, err
}
if len(in) != 0 {
series = append(series, in...)
queryPatts = append(queryPatts, in[0].QueryPatt)
}
}
return series, queryPatts, nil
}