Fix the ztunnel process id not setting to the BPF when process changed (#199)
diff --git a/pkg/accesslog/collector/ztunnel.go b/pkg/accesslog/collector/ztunnel.go
index 550e2a9..be5c168 100644
--- a/pkg/accesslog/collector/ztunnel.go
+++ b/pkg/accesslog/collector/ztunnel.go
@@ -80,11 +80,6 @@
return nil
}
- // setting the ztunnel pid in the BPF
- if err = ctx.BPF.ZtunnelProcessPid.Set(z.collectingProcess.Pid); err != nil {
- return fmt.Errorf("failed to set ztunnel process pid: %v", err)
- }
-
ctx.BPF.ReadEventAsync(ctx.BPF.ZtunnelLbSocketMappingEventQueue, func(data interface{}) {
event := data.(*events.ZTunnelSocketMappingEvent)
localIP := z.convertBPFIPToString(event.OriginalSrcIP)
@@ -189,6 +184,7 @@
running, err := z.collectingProcess.IsRunning()
if err == nil && running {
// already collecting the process
+ log.Debugf("found the ztunnel process and collecting ztunnel data from pid: %d", z.collectingProcess.Pid)
return nil
}
log.Warnf("detected ztunnel process is not running, should re-scan process to find and collect it")
@@ -235,6 +231,11 @@
uprobeFile := z.alc.BPF.OpenUProbeExeFile(pidExeFile)
uprobeFile.AddLink(trackBoundSymbol[0].Name, z.alc.BPF.ConnectionManagerTrackOutbound, nil)
+
+ // setting the ztunnel pid in the BPF
+ if err = z.alc.BPF.ZtunnelProcessPid.Set(p.Pid); err != nil {
+ return fmt.Errorf("failed to set ztunnel process pid in the BPF: %v", err)
+ }
return nil
}