diff --git a/pkg/containerwatcher/v1/container_watcher_private.go b/pkg/containerwatcher/v1/container_watcher_private.go index c6c16bc0..74e7921d 100644 --- a/pkg/containerwatcher/v1/container_watcher_private.go +++ b/pkg/containerwatcher/v1/container_watcher_private.go @@ -24,7 +24,10 @@ func (ch *IGContainerWatcher) containerCallback(notif containercollection.PubSub // do not trace the node-agent pod if ch.ignoreContainer(notif.Container.K8s.Namespace, notif.Container.K8s.PodName) { - ch.unregisterContainer(notif.Container) + // avoid loops when the container is being removed + if notif.Type == containercollection.EventTypeAddContainer { + ch.unregisterContainer(notif.Container) + } return } @@ -66,6 +69,7 @@ func (ch *IGContainerWatcher) containerCallback(notif containercollection.PubSub ch.timeBasedContainers.Remove(notif.Container.Runtime.ContainerID) } } + func (ch *IGContainerWatcher) startContainerCollection(ctx context.Context) error { ch.ctx = ctx @@ -345,7 +349,7 @@ func (ch *IGContainerWatcher) unregisterContainer(container *containercollection return } - logger.L().Info("stopping to monitor on container", helpers.String("container ID", container.Runtime.ContainerID), helpers.String("namespace", container.K8s.Namespace), helpers.String("PodName", container.K8s.PodName), helpers.String("ContainerName", container.K8s.ContainerName)) + logger.L().Debug("stopping to monitor on container", helpers.String("container ID", container.Runtime.ContainerID), helpers.String("namespace", container.K8s.Namespace), helpers.String("PodName", container.K8s.PodName), helpers.String("ContainerName", container.K8s.ContainerName)) ch.containerCollection.RemoveContainer(container.Runtime.ContainerID) diff --git a/pkg/containerwatcher/v1/network.go b/pkg/containerwatcher/v1/network.go index 49bb9e88..4eff8642 100644 --- a/pkg/containerwatcher/v1/network.go +++ b/pkg/containerwatcher/v1/network.go @@ -2,6 +2,7 @@ package containerwatcher import ( "fmt" + "strings" "github.com/inspektor-gadget/inspektor-gadget/pkg/container-collection/networktracer" tracernetwork "github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets/trace/network/tracer" @@ -21,9 +22,10 @@ func (ch *IGContainerWatcher) networkEventCallback(event *tracernetworktypes.Eve if event.Type != types.NORMAL { // dropped event - logger.L().Ctx(ch.ctx).Warning("network tracer got drop events - we may miss some realtime data", helpers.Interface("event", event), helpers.String("error", event.Message)) + if !strings.Contains(event.Message, "stop tracing container") { + logger.L().Ctx(ch.ctx).Warning("network tracer got drop events - we may miss some realtime data", helpers.Interface("event", event), helpers.String("error", event.Message)) + } } else { - ch.containerCollection.EnrichByMntNs(&event.CommonData, event.MountNsID) ch.containerCollection.EnrichByNetNs(&event.CommonData, event.NetNsID)