Skip to content

Commit

Permalink
Enabling custom sniffing time for pods (via label)
Browse files Browse the repository at this point in the history
Signed-off-by: Ben <[email protected]>
  • Loading branch information
slashben committed Jul 2, 2024
1 parent 3c2f628 commit a1d6d5d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/containerwatcher/v1/container_watcher_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (
"github.com/kubescape/node-agent/pkg/utils"
)

const (
MaxSniffingTimeLabel = "kubescape.io/max-sniffing-time"
)

func (ch *IGContainerWatcher) containerCallback(notif containercollection.PubSubEvent) {

// do not trace the node-agent pod
Expand All @@ -34,7 +38,18 @@ func (ch *IGContainerWatcher) containerCallback(notif containercollection.PubSub
switch notif.Type {
case containercollection.EventTypeAddContainer:
logger.L().Info("start monitor on container", helpers.String("container ID", notif.Container.Runtime.ContainerID), helpers.String("k8s workload", k8sContainerID))
time.AfterFunc(ch.cfg.MaxSniffingTime, func() {

// Check if Pod has a label of max sniffing time
sniffingTime := ch.cfg.MaxSniffingTime
if podLabelMaxSniffingTime, ok := notif.Container.K8s.PodLabels[MaxSniffingTimeLabel]; ok {
if duration, err := time.ParseDuration(podLabelMaxSniffingTime); err == nil {
sniffingTime = duration
} else {
logger.L().Error("parsing sniffing time in label", helpers.Error(err))
}
}

time.AfterFunc(sniffingTime, func() {
logger.L().Info("monitoring time ended", helpers.String("container ID", notif.Container.Runtime.ContainerID), helpers.String("k8s workload", k8sContainerID))
ch.timeBasedContainers.Remove(notif.Container.Runtime.ContainerID)
ch.applicationProfileManager.ContainerReachedMaxTime(notif.Container.Runtime.ContainerID)
Expand Down

0 comments on commit a1d6d5d

Please sign in to comment.