-
Notifications
You must be signed in to change notification settings - Fork 51
/
collector_trireme.go
79 lines (62 loc) · 2.16 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
package statscollector
import (
"go.aporeto.io/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.StatsFlowHash(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) {
//We will leave this unimplemented
// trace event collection in done from the main enforcer
c.Lock()
defer c.Unlock()
zap.L().Debug("Collected Packet Event")
c.DatapathPacketReports = append(c.DatapathPacketReports, report)
}
// CollectCounterEvent collect counters from the datapath
func (c *collectorImpl) CollectCounterEvent(report *collector.CounterReport) {
c.Lock()
defer c.Unlock()
c.CounterReports = append(c.CounterReports, report)
}
// CollectCounterEvent collect counters from the datapath
func (c *collectorImpl) CollectDNSRequests(report *collector.DNSRequestReport) {
c.DNSReport <- report
}