From 1cabcd9aa150b0656e6f07611f44712cf8cc2441 Mon Sep 17 00:00:00 2001 From: "M. Mert Yildiran" Date: Thu, 5 Sep 2024 20:09:20 +0300 Subject: [PATCH] Revert "Convert all `log.Error` calls to `log.Warn` calls" This reverts commit ad36f4bbc1cf7d1cdcf29a30cb388aa8e0da8b7f. --- bpf_logger.go | 2 +- main.go | 4 ++-- misc/data.go | 2 +- packet_sniffer.go | 8 ++++---- packet_sorter.go | 20 ++++++++++---------- pkg/health/health.go | 4 ++-- pkg/kubernetes/config.go | 4 ++-- pkg/kubernetes/target.go | 4 ++-- pkg/kubernetes/watcher.go | 2 +- server/server.go | 4 ++-- socket/event_unix_socket.go | 6 +++--- socket/packet_unix_socket.go | 2 +- socket/unix_socket.go | 4 ++-- tls_process_discoverer.go | 12 ++++++------ tls_stream.go | 4 ++-- tracer.go | 16 ++++++++-------- tracer_cgroup.go | 2 +- tracer_syscall_events.go | 4 ++-- tracer_system_events.go | 6 +++--- 19 files changed, 55 insertions(+), 55 deletions(-) diff --git a/bpf_logger.go b/bpf_logger.go index f332ac0..132caab 100644 --- a/bpf_logger.go +++ b/bpf_logger.go @@ -110,7 +110,7 @@ func (p *bpfLogger) log(msg *logMessage) { func (p *bpfLogger) logLevel(level uint32, format string, args ...interface{}) { if level == logLevelError { - log.Warn().Msg(fmt.Sprintf(logPrefix+format, args...)) + log.Error().Msg(fmt.Sprintf(logPrefix+format, args...)) } else if level == logLevelInfo { log.Info().Msg(fmt.Sprintf(logPrefix+format, args...)) } else if level == logLevelDebug { diff --git a/main.go b/main.go index 1cbcc5a..bb1ea8a 100644 --- a/main.go +++ b/main.go @@ -69,7 +69,7 @@ func main() { TracesSampleRate: 1.0, Release: version.Ver, }); err != nil { - log.Warn().Err(err).Msg("Sentry initialization failed:") + log.Error().Err(err).Msg("Sentry initialization failed:") } else { defer sentry.Flush(2 * time.Second) } @@ -121,7 +121,7 @@ func run() { errOut := make(chan error, 100) go func() { for err := range errOut { - log.Warn().Err(err).Msg("watch failed:") + log.Error().Err(err).Msg("watch failed:") } }() watcher := kubernetes.NewFromInCluster(errOut, tracer.updateTargets) diff --git a/misc/data.go b/misc/data.go index 8787f82..58bf3f2 100644 --- a/misc/data.go +++ b/misc/data.go @@ -12,7 +12,7 @@ var dataDir = "data" func InitDataDir() { err := os.MkdirAll(dataDir, os.ModePerm) if err != nil { - log.Warn().Err(err).Str("data-dir", dataDir).Msg("Unable to create the new data directory:") + log.Error().Err(err).Str("data-dir", dataDir).Msg("Unable to create the new data directory:") } else { log.Info().Str("data-dir", dataDir).Msg("Set the data directory to:") } diff --git a/packet_sniffer.go b/packet_sniffer.go index 0da038f..c1b5778 100644 --- a/packet_sniffer.go +++ b/packet_sniffer.go @@ -58,7 +58,7 @@ func (p *packetFilter) update(procfs string, pods map[types.UID]*podInfo) { var ifaces []int links, err := netlink.LinkList() if err != nil { - log.Warn().Err(err).Msg("Get link list failed:") + log.Error().Err(err).Msg("Get link list failed:") return } for _, link := range links { @@ -67,7 +67,7 @@ func (p *packetFilter) update(procfs string, pods map[types.UID]*podInfo) { for _, l := range ifaces { if err := p.tcClient.SetupTC(l, p.ingressPullProgram.FD(), p.egressPullProgram.FD()); err != nil { - log.Warn().Int("link", l).Err(err).Msg("Setup TC failed:") + log.Error().Int("link", l).Err(err).Msg("Setup TC failed:") continue } log.Info().Int("link", l).Msg("Attached TC programs:") @@ -131,7 +131,7 @@ func (p *packetFilter) update(procfs string, pods map[types.UID]*podInfo) { } if err := p.tcClient.SetupTC(lo, p.ingressPullProgram.FD(), p.egressPullProgram.FD()); err != nil { - log.Warn().Int("link", lo).Err(err).Msg("Setup TC failed:") + log.Error().Int("link", lo).Err(err).Msg("Setup TC failed:") errors <- fmt.Errorf("Unable to setup tc netns: %v iface: %v error: %v", h, lo, err) return } @@ -147,7 +147,7 @@ func (p *packetFilter) update(procfs string, pods map[types.UID]*podInfo) { select { case err := <-errors: - log.Warn().Err(err).Msg("Setup netns program failed:") + log.Error().Err(err).Msg("Setup netns program failed:") case <-done: } } diff --git a/packet_sorter.go b/packet_sorter.go index bf2e1b3..d2de861 100644 --- a/packet_sorter.go +++ b/packet_sorter.go @@ -33,7 +33,7 @@ func (s *PacketSorter) WriteTLSPacket(timestamp uint64, cgroupId uint64, directi err = gopacket.SerializeLayers(buf, opts, l...) if err != nil { - log.Warn().Err(err).Msg("Error serializing packet:") + log.Error().Err(err).Msg("Error serializing packet:") return } @@ -74,7 +74,7 @@ func (s *PacketSorter) WritePlanePacket(timestamp uint64, cgroupId uint64, pktDi err = gopacket.SerializeLayers(buf, opts, l...) if err != nil { - log.Warn().Err(err).Msg("Error serializing packet:") + log.Error().Err(err).Msg("Error serializing packet:") return } @@ -117,24 +117,24 @@ func (s *PacketSorter) initMasterPcap() { if _, err = os.Stat(misc.GetMasterPcapPath()); errors.Is(err, os.ErrNotExist) { err = syscall.Mkfifo(misc.GetMasterPcapPath(), 0666) if err != nil { - log.Warn().Err(err).Msg("Couldn't create the named pipe:") + log.Error().Err(err).Msg("Couldn't create the named pipe:") } file, err = os.OpenFile(misc.GetMasterPcapPath(), os.O_APPEND|os.O_WRONLY, os.ModeNamedPipe) if err != nil { - log.Warn().Err(err).Msg("Couldn't create master PCAP:") + log.Error().Err(err).Msg("Couldn't create master PCAP:") } else { s.Lock() defer s.Unlock() s.writer = pcapgo.NewWriter(file) err = s.writer.WriteFileHeader(uint32(misc.Snaplen), layers.LinkTypeEthernet) if err != nil { - log.Warn().Err(err).Msg("While writing the PCAP header:") + log.Error().Err(err).Msg("While writing the PCAP header:") } } } else { file, err = os.OpenFile(misc.GetMasterPcapPath(), os.O_APPEND|os.O_WRONLY, os.ModeNamedPipe) if err != nil { - log.Warn().Err(err).Msg("Couldn't open master PCAP:") + log.Error().Err(err).Msg("Couldn't open master PCAP:") } else { s.Lock() defer s.Unlock() @@ -148,14 +148,14 @@ func (s *PacketSorter) initCbufPcap() { return } if *globCbuf < 0 || *globCbuf > globCbufMax { - log.Warn().Msg(fmt.Sprintf("Circullar buffer size can not be greater than %v", globCbufMax)) + log.Error().Msg(fmt.Sprintf("Circullar buffer size can not be greater than %v", globCbufMax)) return } if _, err := os.Stat(misc.GetCbufPcapPath()); errors.Is(err, os.ErrNotExist) { err = syscall.Mkfifo(misc.GetCbufPcapPath(), 0666) if err != nil { - log.Warn().Err(err).Msg("Couldn't create the named pipe:") + log.Error().Err(err).Msg("Couldn't create the named pipe:") } } @@ -165,12 +165,12 @@ func (s *PacketSorter) initCbufPcap() { for { file, err := os.OpenFile(misc.GetCbufPcapPath(), os.O_APPEND|os.O_WRONLY, os.ModeNamedPipe) if err != nil { - log.Warn().Err(err).Msg("Couldn't create cbuf PCAP:") + log.Error().Err(err).Msg("Couldn't create cbuf PCAP:") break } err = s.cbufPcap.DumptoPcapFile(file, *globCbuf) if err != nil { - log.Warn().Err(err).Msg("Couldn't dump cbuf PCAP:") + log.Error().Err(err).Msg("Couldn't dump cbuf PCAP:") } file.Close() // wait read side to close the file diff --git a/pkg/health/health.go b/pkg/health/health.go index 776a880..64592f9 100644 --- a/pkg/health/health.go +++ b/pkg/health/health.go @@ -39,7 +39,7 @@ func DumpHealthEvery10Seconds(nodeName string) { for range ticker.C { err := dumpHealth(nodeName) if err != nil { - log.Warn().Err(err).Msg("Failed to dump health data") + log.Error().Err(err).Msg("Failed to dump health data") } } } @@ -87,7 +87,7 @@ func initTracerHealth() { } if clientSet == nil { - log.Warn().Msg("Failed to create clientSet") + log.Error().Msg("Failed to create clientSet") return } diff --git a/pkg/kubernetes/config.go b/pkg/kubernetes/config.go index bbc4e03..ecb9bad 100644 --- a/pkg/kubernetes/config.go +++ b/pkg/kubernetes/config.go @@ -25,7 +25,7 @@ func SyncConfig(configMap *v1.ConfigMap) (*regexp2.Regexp, []string, uint32) { configPodRegex := configMap.Data[CONFIG_POD_REGEX] regex, err := regexp2.Compile(configPodRegex, regexp2.Multiline) if err != nil { - log.Warn().Err(err).Str("config", CONFIG_POD_REGEX).Send() + log.Error().Err(err).Str("config", CONFIG_POD_REGEX).Send() } configNamespaces := configMap.Data[CONFIG_NAMESPACES] @@ -33,7 +33,7 @@ func SyncConfig(configMap *v1.ConfigMap) (*regexp2.Regexp, []string, uint32) { var settings uint32 if stopped, err := strconv.ParseBool(configMap.Data[CONFIG_STOPPED]); err != nil { - log.Warn().Err(err).Str("config", CONFIG_STOPPED).Send() + log.Error().Err(err).Str("config", CONFIG_STOPPED).Send() } else if stopped { settings |= CONFIGURATION_FLAG_CAPTURE_STOPPED } diff --git a/pkg/kubernetes/target.go b/pkg/kubernetes/target.go index fb4b0f0..dcb71e2 100644 --- a/pkg/kubernetes/target.go +++ b/pkg/kubernetes/target.go @@ -75,12 +75,12 @@ func updateCurrentlyTargetedPods( newAllTargetPods, err := getAllTargetPodsFromHub() if err != nil { - log.Warn().Err(err).Msg("Failed to get all targeted pods") + log.Error().Err(err).Msg("Failed to get all targeted pods") } newSelectedTargetPods, err := getSelectedTargetedPodsFromHub() if err != nil { - log.Warn().Err(err).Msg("Failed to get selected targeted pods") + log.Error().Err(err).Msg("Failed to get selected targeted pods") } addedWatchedPods, removedWatchedPods := getPodArrayDiff(GetAllTargetPods(), newAllTargetPods) diff --git a/pkg/kubernetes/watcher.go b/pkg/kubernetes/watcher.go index 66f8dfb..218e110 100644 --- a/pkg/kubernetes/watcher.go +++ b/pkg/kubernetes/watcher.go @@ -68,7 +68,7 @@ func (watcher *Watcher) watchKubesharkConfigMap(ctx context.Context) error { err = updateCurrentlyTargetedPods(watcher.callback, settings) if err != nil { - log.Warn().Err(err).Send() + log.Error().Err(err).Send() } watcher.lastUpdatedAt = event.Object.(*v1.ConfigMap).ObjectMeta.Annotations[resolverHistoryAnnotation] case <-ctx.Done(): diff --git a/server/server.go b/server/server.go index ad7664e..48fe5ce 100644 --- a/server/server.go +++ b/server/server.go @@ -62,7 +62,7 @@ func Start(app *gin.Engine, port int) { // Run server. log.Info().Int("port", port).Msg("Starting the server...") if err := app.Run(fmt.Sprintf(":%d", port)); err != nil { - log.Warn().Err(err).Msg("Server is not running!") + log.Error().Err(err).Msg("Server is not running!") } }() @@ -72,6 +72,6 @@ func Start(app *gin.Engine, port int) { defer cancel() err := srv.Shutdown(ctx) if err != nil { - log.Warn().Err(err).Send() + log.Error().Err(err).Send() } } diff --git a/socket/event_unix_socket.go b/socket/event_unix_socket.go index f57fabe..5ae3c6c 100644 --- a/socket/event_unix_socket.go +++ b/socket/event_unix_socket.go @@ -32,13 +32,13 @@ func (s *SocketEvent) processSocket() { _ = os.Remove(s.unixSocketFileName) l, err := net.ListenUnix("unixpacket", &net.UnixAddr{Name: s.unixSocketFileName, Net: "unixpacket"}) if err != nil { - log.Warn().Err(err).Str("Name", s.unixSocketFileName).Msg("Listen event unix socket failed:") + log.Error().Err(err).Str("Name", s.unixSocketFileName).Msg("Listen event unix socket failed:") return } conn, err := l.AcceptUnix() if err != nil { - log.Warn().Err(err).Str("Name", s.unixSocketFileName).Msg("Accept event unix socket failed:") + log.Error().Err(err).Str("Name", s.unixSocketFileName).Msg("Accept event unix socket failed:") time.Sleep(time.Second) continue } @@ -59,7 +59,7 @@ func (s *SocketEvent) processSocket() { for ev := range s.events { if err := encoder.Encode(ev); err != nil { - log.Warn().Err(err).Str("Name", s.unixSocketFileName).Msg("Encode to unix socket failed:") + log.Error().Err(err).Str("Name", s.unixSocketFileName).Msg("Encode to unix socket failed:") conn.Close() break } diff --git a/socket/packet_unix_socket.go b/socket/packet_unix_socket.go index 8e95488..cb9a8e7 100644 --- a/socket/packet_unix_socket.go +++ b/socket/packet_unix_socket.go @@ -96,7 +96,7 @@ func (s *SocketPcap) getTAIOffset() uint64 { func (s *SocketPcap) assignTAI() { tai, err := getTAIOffset() if err != nil { - log.Warn().Err(err).Msg("Get TAI failed:") + log.Error().Err(err).Msg("Get TAI failed:") return } s.taiMtx.Lock() diff --git a/socket/unix_socket.go b/socket/unix_socket.go index b25fd35..d4653fc 100644 --- a/socket/unix_socket.go +++ b/socket/unix_socket.go @@ -80,7 +80,7 @@ func (s *Connection) Run(conn *net.UnixConn, sock *Socket) { if errors.Is(err, syscall.EPIPE) { log.Info().Str("Address", conn.RemoteAddr().String()).Msg("Unix socket connection closed:") } else { - log.Warn().Err(err).Str("Address", conn.RemoteAddr().String()).Msg("Unix socket connection error:") + log.Error().Err(err).Str("Address", conn.RemoteAddr().String()).Msg("Unix socket connection error:") } sock.Disconnected(conn) return @@ -124,7 +124,7 @@ func (c *Socket) acceptClients(l *net.UnixListener) { for { conn, err := l.AcceptUnix() if err != nil { - log.Warn().Err(err).Msg("Accept unix socket failed:") + log.Error().Err(err).Msg("Accept unix socket failed:") time.Sleep(time.Second) continue } diff --git a/tls_process_discoverer.go b/tls_process_discoverer.go index 7ef9f5c..222cb0c 100644 --- a/tls_process_discoverer.go +++ b/tls_process_discoverer.go @@ -17,14 +17,14 @@ type podInfo struct { func (t *Tracer) updateTargets(addedWatchedPods []api.TargetPod, removedWatchedPods []api.TargetPod, addedTargetedPods []api.TargetPod, removedTargetedPods []api.TargetPod, settings uint32) error { if err := t.bpfObjects.tracerMaps.Settings.Update(uint32(0), settings, ebpf.UpdateAny); err != nil { - log.Warn().Err(err).Msg("Update capture settings failed:") + log.Error().Err(err).Msg("Update capture settings failed:") } for _, pod := range removedTargetedPods { if t.packetFilter != nil { if err := t.packetFilter.DetachPod(string(pod.UID)); err == nil { log.Info().Str("pod", pod.Name).Msg("Detached pod from cgroup:") } else { - log.Warn().Err(err).Str("pod", pod.Name).Msg("Detach pod failed from cgroup:") + log.Error().Err(err).Str("pod", pod.Name).Msg("Detach pod failed from cgroup:") } } wInfo, ok := t.watchingPods[pod.UID] @@ -88,7 +88,7 @@ func (t *Tracer) updateTargets(addedWatchedPods []api.TargetPod, removedWatchedP } if _, ok = t.watchingPods[pod.UID]; ok { - log.Warn().Str("pod", pod.Name).Msg("pod already watched:") + log.Error().Str("pod", pod.Name).Msg("pod already watched:") continue } @@ -99,7 +99,7 @@ func (t *Tracer) updateTargets(addedWatchedPods []api.TargetPod, removedWatchedP for _, containerPid := range pInfo.pids { pw, err := NewPodWatcher(t.procfs, &t.bpfObjects, containerPid) if err != nil { - log.Warn().Err(err).Str("pod", pod.Name).Uint32("pid", containerPid).Msg("create pod watcher failed:") + log.Error().Err(err).Str("pod", pod.Name).Uint32("pid", containerPid).Msg("create pod watcher failed:") continue } if pw == nil { @@ -120,7 +120,7 @@ func (t *Tracer) updateTargets(addedWatchedPods []api.TargetPod, removedWatchedP if t.packetFilter != nil { if err := t.packetFilter.AttachPod(string(pod.UID), pInfo.cgroupV2Path, pInfo.cgroupIDs); err != nil { - log.Warn().Err(err).Str("pod", pod.Name).Msg("Attach pod to cgroup failed:") + log.Error().Err(err).Str("pod", pod.Name).Msg("Attach pod to cgroup failed:") return err } log.Info().Str("pod", pod.Name).Msg("Attached pod to cgroup:") @@ -137,7 +137,7 @@ func (t *Tracer) updateTargets(addedWatchedPods []api.TargetPod, removedWatchedP for _, p := range wInfo.tlsPids { err := p.Target(&t.bpfObjects) if err != nil { - log.Warn().Err(err).Str("pod", pod.Name).Msg("target pod failed:") + log.Error().Err(err).Str("pod", pod.Name).Msg("target pod failed:") continue } } diff --git a/tls_stream.go b/tls_stream.go index b3daa8e..748ed09 100644 --- a/tls_stream.go +++ b/tls_stream.go @@ -110,7 +110,7 @@ func (t *tlsStream) writePacket(timestamp uint64, cgroupId uint64, direction uin err := t.poller.sorter.WriteTLSPacket(timestamp, cgroupId, direction, firstLayerType, l...) if err != nil { - log.Warn().Err(err).Msg("Error writing PCAP:") + log.Error().Err(err).Msg("Error writing PCAP:") return } } @@ -142,7 +142,7 @@ func (t *tlsStream) setLayers(timestamp uint64, cgroupId uint64, direction uint8 tcp := t.newTCPLayer(reader) err := tcp.SetNetworkLayerForChecksum(ipv4) if err != nil { - log.Warn().Err(err).Send() + log.Error().Err(err).Send() } if t.layers == nil { diff --git a/tracer.go b/tracer.go index dd6caf2..a108fae 100644 --- a/tracer.go +++ b/tracer.go @@ -124,7 +124,7 @@ func (t *Tracer) Init( t.isCgroupV2, err = isCgroupV2() if err != nil { - log.Warn().Err(err).Msg("read cgroups information failed:") + log.Error().Err(err).Msg("read cgroups information failed:") } log.Info().Msg(fmt.Sprintf("Detected Linux kernel version: %s cgroups version2: %v", kernelVersion, t.isCgroupV2)) @@ -180,7 +180,7 @@ func (t *Tracer) Init( } if err != nil { - log.Warn().Msg(fmt.Sprintf("load bpf objects failed: %v", err)) + log.Error().Msg(fmt.Sprintf("load bpf objects failed: %v", err)) return err } } @@ -242,10 +242,10 @@ func (t *Tracer) Init( if t.isCgroupV2 && *enableSyscallEvents { systemEventsTracer, err := newSystemEventsTracer(t.checkCgroupID) if err != nil { - log.Warn().Err(err).Msg("System events tracer create failed") + log.Error().Err(err).Msg("System events tracer create failed") } else { if err = systemEventsTracer.start(); err != nil { - log.Warn().Err(err).Msg("System events tracer start failed") + log.Error().Err(err).Msg("System events tracer start failed") } } @@ -254,10 +254,10 @@ func (t *Tracer) Init( if !CompatibleMode { syscallEventsTracer, err := newSyscallEventsTracer(t.bpfObjects.SyscallEvents, os.Getpagesize(), socket.NewSocketEvent(misc.GetSyscallEventSocketPath())) if err != nil { - log.Warn().Err(err).Msg("Syscall events tracer create failed") + log.Error().Err(err).Msg("Syscall events tracer create failed") } else { if err = syscallEventsTracer.start(); err != nil { - log.Warn().Err(err).Msg("Syscall events tracer start failed") + log.Error().Err(err).Msg("Syscall events tracer start failed") } } } @@ -369,8 +369,8 @@ func setupRLimit() error { func logError(err error) { var e *errors.Error if errors.As(err, &e) { - log.Warn().Str("stack", e.ErrorStack()).Send() + log.Error().Str("stack", e.ErrorStack()).Send() } else { - log.Warn().Err(err).Send() + log.Error().Err(err).Send() } } diff --git a/tracer_cgroup.go b/tracer_cgroup.go index ba48616..30e336b 100644 --- a/tracer_cgroup.go +++ b/tracer_cgroup.go @@ -268,7 +268,7 @@ func (t *tracerCgroup) scanPidsV1(procfs string, pids []os.DirEntry, containerId } if cgroupPath == "" { - log.Warn().Str("pid", pid.Name()).Msg(fmt.Sprintf("Cgroup path not found. Lines: %v", lines)) + log.Error().Str("pid", pid.Name()).Msg(fmt.Sprintf("Cgroup path not found. Lines: %v", lines)) continue } diff --git a/tracer_syscall_events.go b/tracer_syscall_events.go index 5cf429d..528d0d4 100644 --- a/tracer_syscall_events.go +++ b/tracer_syscall_events.go @@ -55,7 +55,7 @@ func (t *syscallEventsTracer) pollEvents() { return } - log.Warn().Err(err).Msg("Reading syscall event failed") + log.Error().Err(err).Msg("Reading syscall event failed") return } @@ -69,7 +69,7 @@ func (t *syscallEventsTracer) pollEvents() { var ev events.SyscallEventMessage if err := binary.Read(buffer, binary.LittleEndian, &ev); err != nil { - log.Warn().Err(err).Msg("Parse syscall event failed") + log.Error().Err(err).Msg("Parse syscall event failed") continue } diff --git a/tracer_system_events.go b/tracer_system_events.go index de5776c..88e287c 100644 --- a/tracer_system_events.go +++ b/tracer_system_events.go @@ -44,7 +44,7 @@ type systemEventsTracer struct { func processTraceLog() { file, err := os.Open(traceeLogFile) if err != nil { - log.Warn().Err(err).Msg(fmt.Sprintf("open tracee log file failed: %v", traceeLogFile)) + log.Error().Err(err).Msg(fmt.Sprintf("open tracee log file failed: %v", traceeLogFile)) return } defer file.Close() @@ -295,7 +295,7 @@ func (t *systemEventsTracer) start() (err error) { prettyJSON, err := json.MarshalIndent(event, "", " ") if err != nil { - log.Warn().Err(err).Msg("Marshal failed:") + log.Error().Err(err).Msg("Marshal failed:") continue } log.Debug().Str("event", string(prettyJSON)).Msg("event received") @@ -313,7 +313,7 @@ func (t *systemEventsTracer) start() (err error) { defer t.tracee.Unsubscribe(stream) err = t.tracee.Run(ctx) if err != nil { - log.Warn().Err(err).Msg("tracee start failed") + log.Error().Err(err).Msg("tracee start failed") return } log.Info().Msg("tracee stopped")