forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
76 lines (62 loc) · 1.79 KB
/
log.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
package kapacitor
import (
"bytes"
"encoding/json"
"strings"
"github.com/influxdata/kapacitor/edge"
"github.com/influxdata/kapacitor/pipeline"
)
type LogNode struct {
node
level string
prefix string
buf bytes.Buffer
enc *json.Encoder
batchBuffer *edge.BatchBuffer
}
// Create a new LogNode which logs all data it receives
func newLogNode(et *ExecutingTask, n *pipeline.LogNode, d NodeDiagnostic) (*LogNode, error) {
nn := &LogNode{
node: node{Node: n, et: et, diag: d},
level: strings.ToUpper(n.Level),
prefix: n.Prefix,
batchBuffer: new(edge.BatchBuffer),
}
nn.enc = json.NewEncoder(&nn.buf)
nn.node.runF = nn.runLog
return nn, nil
}
func (n *LogNode) runLog([]byte) error {
consumer := edge.NewConsumerWithReceiver(
n.ins[0],
edge.NewReceiverFromForwardReceiverWithStats(
n.outs,
edge.NewTimedForwardReceiver(n.timer, n),
),
)
return consumer.Consume()
}
func (n *LogNode) BeginBatch(begin edge.BeginBatchMessage) (edge.Message, error) {
return nil, n.batchBuffer.BeginBatch(begin)
}
func (n *LogNode) BatchPoint(bp edge.BatchPointMessage) (edge.Message, error) {
return nil, n.batchBuffer.BatchPoint(bp)
}
func (n *LogNode) EndBatch(end edge.EndBatchMessage) (edge.Message, error) {
return n.BufferedBatch(n.batchBuffer.BufferedBatchMessage(end))
}
func (n *LogNode) BufferedBatch(batch edge.BufferedBatchMessage) (edge.Message, error) {
n.diag.LogBatchData(n.level, n.prefix, batch)
return batch, nil
}
func (n *LogNode) Point(p edge.PointMessage) (edge.Message, error) {
n.diag.LogPointData(n.level, n.prefix, p)
return p, nil
}
func (n *LogNode) Barrier(b edge.BarrierMessage) (edge.Message, error) {
return b, nil
}
func (n *LogNode) DeleteGroup(d edge.DeleteGroupMessage) (edge.Message, error) {
return d, nil
}
func (n *LogNode) Done() {}