forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shift.go
59 lines (53 loc) · 1.21 KB
/
shift.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package kapacitor
import (
"errors"
"log"
"time"
"github.com/influxdata/kapacitor/pipeline"
)
type ShiftNode struct {
node
s *pipeline.ShiftNode
shift time.Duration
}
// Create a new ShiftNode which shifts points and batches in time.
func newShiftNode(et *ExecutingTask, n *pipeline.ShiftNode, l *log.Logger) (*ShiftNode, error) {
sn := &ShiftNode{
node: node{Node: n, et: et, logger: l},
s: n,
shift: n.Shift,
}
sn.node.runF = sn.runShift
if n.Shift == 0 {
return nil, errors.New("invalid shift value: must be non zero duration")
}
return sn, nil
}
func (s *ShiftNode) runShift([]byte) error {
switch s.Wants() {
case pipeline.StreamEdge:
for p, ok := s.ins[0].NextPoint(); ok; p, ok = s.ins[0].NextPoint() {
p.Time = p.Time.Add(s.shift)
for _, child := range s.outs {
err := child.CollectPoint(p)
if err != nil {
return err
}
}
}
case pipeline.BatchEdge:
for b, ok := s.ins[0].NextBatch(); ok; b, ok = s.ins[0].NextBatch() {
b.TMax = b.TMax.Add(s.shift)
for i, p := range b.Points {
b.Points[i].Time = p.Time.Add(s.shift)
}
for _, child := range s.outs {
err := child.CollectBatch(b)
if err != nil {
return err
}
}
}
}
return nil
}