MCPcopy
hub / github.com/microsoft/retina / main

Function main

test/plugin/packetparser/main_linux.go:25–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23)
24
25func main() {
26 opts := log.GetDefaultLogOpts()
27 opts.Level = "debug"
28 log.SetupZapLogger(opts)
29 l := log.Logger().Named("test-packetparser")
30
31 metrics.InitializeMetrics(slog.Default())
32
33 ctxTimeout, cancel := context.WithTimeout(context.Background(), 30*time.Second)
34
35 // watcher manager
36 wm := watchermanager.NewWatcherManager(kcfg.DefaultFilterMapMaxEntries)
37 wm.Watchers = []watchermanager.IWatcher{endpoint.Watcher()}
38
39 err := wm.Start(ctxTimeout)
40 if err != nil {
41 panic(err)
42 }
43
44 defer func() {
45 if err := wm.Stop(ctxTimeout); err != nil {
46 l.Error("Stop endpoint watcher failed", zap.Error(err))
47 }
48 }()
49 // Filtermanager.
50 f, err := filtermanager.Init(3, kcfg.DefaultFilterMapMaxEntries)
51 if err != nil {
52 l.Error("Start filtermanager failed", zap.Error(err))
53 return
54 }
55 defer func() {
56 if err := f.Stop(); err != nil {
57 l.Error("Stop filtermanager failed", zap.Error(err))
58 }
59 }()
60
61 ipsToAdd := []string{"20.69.116.85"}
62 ips := []net.IP{}
63 for _, ip := range ipsToAdd {
64 x := net.ParseIP(ip).To4()
65 if x == nil {
66 l.Fatal("Invalid IP address", zap.String("ip", ip))
67 }
68 ips = append(ips, x)
69 }
70 err = f.AddIPs(ips, "packetparser-test", filtermanager.RequestMetadata{RuleID: "test"})
71 if err != nil {
72 l.Error("AddIPs failed", zap.Error(err))
73 return
74 }
75
76 // Start packetparser plugin.
77 cfg := &kcfg.Config{
78 MetricsInterval: 1 * time.Second,
79 EnablePodLevel: true,
80 }
81 p := packetparser.New(cfg)
82 if err = p.Stop(); err != nil {

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
StopMethod · 0.95
GetDefaultLogOptsFunction · 0.92
SetupZapLoggerFunction · 0.92
LoggerFunction · 0.92
InitializeMetricsFunction · 0.92
NewWatcherManagerFunction · 0.92
WatcherFunction · 0.92
InitFunction · 0.92
NewFunction · 0.92
NamedMethod · 0.80
InfoMethod · 0.80

Tested by

no test coverage detected