Skip to content

Commit

Permalink
Revert "Convert all log.Error calls to log.Warn calls"
Browse files Browse the repository at this point in the history
This reverts commit ad36f4b.
  • Loading branch information
mertyildiran committed Sep 5, 2024
1 parent ad36f4b commit 1cabcd9
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion bpf_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion misc/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
}
Expand Down
8 changes: 4 additions & 4 deletions packet_sniffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:")
Expand Down Expand Up @@ -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
}
Expand All @@ -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:
}
}
Expand Down
20 changes: 10 additions & 10 deletions packet_sorter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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()
Expand All @@ -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:")
}
}

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func initTracerHealth() {
}

if clientSet == nil {
log.Warn().Msg("Failed to create clientSet")
log.Error().Msg("Failed to create clientSet")
return
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ 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]
namespaces := strings.Split(configNamespaces, ",")

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
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubernetes/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubernetes/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
}()

Expand All @@ -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()
}
}
6 changes: 3 additions & 3 deletions socket/event_unix_socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion socket/packet_unix_socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions socket/unix_socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions tls_process_discoverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
}

Expand All @@ -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 {
Expand All @@ -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:")
Expand All @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions tls_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 1cabcd9

Please sign in to comment.