Skip to content

Commit 84119c5

Browse files
author
Vladimir Smirnov
committed
Fix panic when combining graphiteWeb function with maxDataPoints
Fixes #330
1 parent a6cf73a commit 84119c5

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

expr/functions/graphiteWeb/function.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,17 +410,22 @@ func (f *graphiteWeb) Do(e parser.Expr, from, until int64, values map[parser.Met
410410
return nil, err
411411
}
412412

413-
res := make([]*types.MetricData, len(tmp))
413+
res := make([]*types.MetricData, 0, len(tmp))
414414

415415
for _, m := range tmp {
416416
stepTime := int64(60)
417417
if len(m.Datapoints) > 1 {
418-
stepTime = int64(m.Datapoints[1][0] - m.Datapoints[0][0])
418+
stepTime = int64(m.Datapoints[1][1] - m.Datapoints[0][1])
419419
}
420+
421+
if m.ConsolidationFunc == "" {
422+
m.ConsolidationFunc = "avg"
423+
}
424+
420425
pbResp := pb.FetchResponse{
421426
Name: string(m.Target),
422-
StartTime: int64(m.Datapoints[0][0]),
423-
StopTime: int64(m.Datapoints[len(m.Datapoints)-1][0]),
427+
StartTime: int64(m.Datapoints[0][1]),
428+
StopTime: int64(m.Datapoints[len(m.Datapoints)-1][1]),
424429
StepTime: stepTime,
425430
Values: make([]float64, len(m.Datapoints)),
426431
XFilesFactor: m.XFilesFactor,

0 commit comments

Comments
 (0)