-
Notifications
You must be signed in to change notification settings - Fork 493
/
shift.go
75 lines (63 loc) · 1.64 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package kapacitor
import (
"errors"
"time"
"github.com/influxdata/kapacitor/edge"
"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, d NodeDiagnostic) (*ShiftNode, error) {
sn := &ShiftNode{
node: node{Node: n, et: et, diag: d},
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 (n *ShiftNode) runShift([]byte) error {
consumer := edge.NewConsumerWithReceiver(
n.ins[0],
edge.NewReceiverFromForwardReceiverWithStats(
n.outs,
edge.NewTimedForwardReceiver(n.timer, n),
),
)
return consumer.Consume()
}
func (n *ShiftNode) doShift(t edge.TimeSetter) {
t.SetTime(t.Time().Add(n.shift))
}
func (n *ShiftNode) BeginBatch(begin edge.BeginBatchMessage) (edge.Message, error) {
begin = begin.ShallowCopy()
n.doShift(begin)
return begin, nil
}
func (n *ShiftNode) BatchPoint(bp edge.BatchPointMessage) (edge.Message, error) {
bp = bp.ShallowCopy()
n.doShift(bp)
return bp, nil
}
func (n *ShiftNode) EndBatch(end edge.EndBatchMessage) (edge.Message, error) {
return end, nil
}
func (n *ShiftNode) Point(p edge.PointMessage) (edge.Message, error) {
p = p.ShallowCopy()
n.doShift(p)
return p, nil
}
func (n *ShiftNode) Barrier(b edge.BarrierMessage) (edge.Message, error) {
return b, nil
}
func (n *ShiftNode) DeleteGroup(d edge.DeleteGroupMessage) (edge.Message, error) {
return d, nil
}
func (n *ShiftNode) Done() {}