forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
union.go
77 lines (71 loc) · 1.61 KB
/
union.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
76
77
package kapacitor
import (
"log"
"github.com/influxdata/kapacitor/pipeline"
"github.com/influxdata/kapacitor/timer"
)
type UnionNode struct {
node
u *pipeline.UnionNode
timers []timer.Timer
}
// Create a new UnionNode which combines all parent data streams into a single stream.
// No transformation of any kind is performed.
func newUnionNode(et *ExecutingTask, n *pipeline.UnionNode, l *log.Logger) (*UnionNode, error) {
un := &UnionNode{
u: n,
node: node{Node: n, et: et, logger: l},
}
un.node.runF = un.runUnion
return un, nil
}
func (u *UnionNode) runUnion([]byte) error {
rename := u.u.Rename
if rename == "" {
//the calling node is always the last node
rename = u.parents[len(u.parents)-1].Name()
}
errors := make(chan error, len(u.ins))
for _, in := range u.ins {
t := u.et.tm.TimingService.NewTimer(u.avgExecVar)
u.timers = append(u.timers, t)
go func(e *Edge, t timer.Timer) {
switch u.Wants() {
case pipeline.StreamEdge:
for p, ok := e.NextPoint(); ok; p, ok = e.NextPoint() {
t.Start()
p.Name = rename
t.Stop()
for _, out := range u.outs {
err := out.CollectPoint(p)
if err != nil {
errors <- err
return
}
}
}
case pipeline.BatchEdge:
for b, ok := e.NextBatch(); ok; b, ok = e.NextBatch() {
t.Start()
b.Name = rename
t.Stop()
for _, out := range u.outs {
err := out.CollectBatch(b)
if err != nil {
errors <- err
return
}
}
}
}
errors <- nil
}(in, t)
}
for range u.ins {
err := <-errors
if err != nil {
return err
}
}
return nil
}