-
Notifications
You must be signed in to change notification settings - Fork 51
/
collector_trireme.go
94 lines (73 loc) · 2.59 KB
/
collector_trireme.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package statscollector
import (
"go.aporeto.io/enforcerd/trireme-lib/collector"
"go.uber.org/zap"
)
// CollectFlowEvent collects a new flow event and adds it to a local list it shares with SendStats
func (c *collectorImpl) CollectFlowEvent(record *collector.FlowRecord) {
hash := collector.StatsFlowContentHash(record)
// If flow event doesn't have a count make it equal to 1. At least one flow is collected
if record.Count == 0 {
record.Count = 1
}
c.Lock()
defer c.Unlock()
if r, ok := c.Flows[hash]; ok {
r.Count = r.Count + record.Count
return
}
c.Flows[hash] = record
c.Flows[hash].Tags = record.Tags
}
// CollectContainerEvent is called when container events are received
func (c *collectorImpl) CollectContainerEvent(record *collector.ContainerRecord) {
zap.L().Error("Unexpected call for collecting container event")
}
// CollectUserEvent collects a new user event and adds it to a local cache.
func (c *collectorImpl) CollectUserEvent(record *collector.UserRecord) {
if err := collector.StatsUserHash(record); err != nil {
zap.L().Error("Cannot store user record", zap.Error(err))
return
}
c.Lock()
defer c.Unlock()
if _, ok := c.ProcessedUsers[record.ID]; !ok {
c.Users[record.ID] = record
c.ProcessedUsers[record.ID] = true
}
}
// CollectTraceEvent collect trace events
func (c *collectorImpl) CollectTraceEvent(records []string) {
//We will leave this unimplemented
// trace event collection in done from the main enforcer
}
// CollectTraceEvent collect trace events
func (c *collectorImpl) CollectPacketEvent(report *collector.PacketReport) {
c.send(PacketReport, report)
}
// CollectCounterEvent collect counters from the datapath
func (c *collectorImpl) CollectCounterEvent(report *collector.CounterReport) {
c.send(CounterReport, report)
}
// CollectCounterEvent collect counters from the datapath
func (c *collectorImpl) CollectDNSRequests(report *collector.DNSRequestReport) {
c.send(DNSReport, report)
}
// CollectPingEvent collect ping events from the datapath
func (c *collectorImpl) CollectPingEvent(report *collector.PingReport) {
c.send(PingReport, report)
}
// CollectConnectionExceptionReport collect collect connection exception reports from the datapath
func (c *collectorImpl) CollectConnectionExceptionReport(report *collector.ConnectionExceptionReport) {
c.send(ConnectionExceptionReport, report)
}
func (c *collectorImpl) send(rtype ReportType, report interface{}) {
select {
case c.Reports <- &Report{rtype, report}:
default:
zap.L().Warn("Reports queue full, dropped",
zap.Reflect("reportType", rtype),
zap.Reflect("report", report),
)
}
}