-
Notifications
You must be signed in to change notification settings - Fork 51
/
monitor.go
87 lines (69 loc) · 2.29 KB
/
monitor.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
package uidmonitor
import (
"context"
"fmt"
"regexp"
"go.aporeto.io/trireme-lib/common"
"go.aporeto.io/trireme-lib/monitor/config"
"go.aporeto.io/trireme-lib/monitor/registerer"
"go.aporeto.io/trireme-lib/utils/cache"
"go.aporeto.io/trireme-lib/utils/cgnetcls"
)
// UIDMonitor captures all the monitor processor information for a UIDLoginPU
// It implements the EventProcessor interface of the rpc monitor
type UIDMonitor struct {
proc *uidProcessor
}
// New returns a new implmentation of a monitor implmentation
func New() *UIDMonitor {
return &UIDMonitor{
proc: &uidProcessor{},
}
}
// Run implements Implementation interface
func (u *UIDMonitor) Run(ctx context.Context) error {
if err := u.proc.config.IsComplete(); err != nil {
return fmt.Errorf("uid: %s", err)
}
return u.Resync(ctx)
}
// SetupConfig provides a configuration to implmentations. Every implmentation
// can have its own config type.
func (u *UIDMonitor) SetupConfig(registerer registerer.Registerer, cfg interface{}) error {
defaultConfig := DefaultConfig()
if cfg == nil {
cfg = defaultConfig
}
uidConfig, ok := cfg.(*Config)
if !ok {
return fmt.Errorf("Invalid configuration specified")
}
if registerer != nil {
if err := registerer.RegisterProcessor(common.UIDLoginPU, u.proc); err != nil {
return err
}
}
// Setup defaults
uidConfig = SetupDefaultConfig(uidConfig)
// Setup config
u.proc.netcls = cgnetcls.NewCgroupNetController(common.TriremeUIDCgroupPath, uidConfig.ReleasePath)
u.proc.regStart = regexp.MustCompile("^[a-zA-Z0-9_]{1,11}$")
u.proc.regStop = regexp.MustCompile("^/trireme/[a-zA-Z0-9_]{1,11}$")
u.proc.putoPidMap = cache.NewCache("putoPidMap")
u.proc.pidToPU = cache.NewCache("pidToPU")
u.proc.metadataExtractor = uidConfig.EventMetadataExtractor
if u.proc.metadataExtractor == nil {
return fmt.Errorf("Unable to setup a metadata extractor")
}
return nil
}
// SetupHandlers sets up handlers for monitors to invoke for various events such as
// processing unit events and synchronization events. This will be called before Start()
// by the consumer of the monitor
func (u *UIDMonitor) SetupHandlers(m *config.ProcessorConfig) {
u.proc.config = m
}
// Resync asks the monitor to do a resync
func (u *UIDMonitor) Resync(ctx context.Context) error {
return u.proc.Resync(ctx, nil)
}