From eed4401d0d5717585531fb6cea92ab39526f466a Mon Sep 17 00:00:00 2001 From: gauravmann Date: Wed, 12 Nov 2025 12:18:04 +0530 Subject: [PATCH 1/2] dbeug direction --- trafficUtil/kafkaUtil/parser.go | 19 +++++++++++-------- trafficUtil/kafkaUtil/podinformer.go | 11 ++++++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/trafficUtil/kafkaUtil/parser.go b/trafficUtil/kafkaUtil/parser.go index b5acdfd..3fe09eb 100644 --- a/trafficUtil/kafkaUtil/parser.go +++ b/trafficUtil/kafkaUtil/parser.go @@ -125,6 +125,7 @@ func UpdateDebugStringsFromFile() { func checkDebugUrlAndPrint(url string, host string, message string) { // url or host. [array string] + message = "mannakto" + message if len(DebugStrings) > 0 { for _, debugString := range DebugStrings { if strings.Contains(url, debugString) { @@ -434,7 +435,7 @@ func ParseAndProduce(receiveBuffer []byte, sentBuffer []byte, sourceIp string, d // Process id was captured from the eBPF program using bpf_get_current_pid_tgid() // Shifting by 32 gives us the process id on host machine. var pid = idfd >> 32 - log := fmt.Sprintf("pod direction log: direction=%v, host=%v, path=%v, sourceIp=%v, destIp=%v, socketId=%v, processId=%v, hostName=%v", + log := fmt.Sprintf("direction=%v, host=%v, path=%v, sourceIp=%v, destIp=%v, socketId=%v, processId=%v, hostName=%v", direction, reqHeaderStr["host"], value["path"], @@ -444,27 +445,29 @@ func ParseAndProduce(receiveBuffer []byte, sentBuffer []byte, sourceIp string, d pid, hostName, ) - utils.PrintLog(log) - checkDebugUrlAndPrint(url, req.Host, log) + slog.Warn("before resolving labels pod direction log" + log) + checkDebugUrlAndPrint(url, req.Host, "before resolving labels pod direction log" + log) if PodInformerInstance != nil && direction == utils.DirectionInbound { if hostName == "" { - checkDebugUrlAndPrint(url, req.Host, "Failed to resolve pod name, hostName is empty for processId "+fmt.Sprint(pid)) - slog.Error("Failed to resolve pod name, hostName is empty for ", "processId", pid, "hostName", hostName) + checkDebugUrlAndPrint(url, req.Host, "Failed to resolve pod name, hostName is empty for processId "+fmt.Sprint(pid) + log) + slog.Error("Failed to resolve pod name, hostName is empty for ", "processId", pid, "hostName", hostName, "log", log) } else { + slog.Warn("Resolving Pod Name to labels", "podName", hostName, "log", log) podLabels, err := PodInformerInstance.ResolvePodLabels(hostName, url, req.Host) if err != nil { slog.Error("Failed to resolve pod labels", "hostName", hostName, "error", err) - checkDebugUrlAndPrint(url, req.Host, "Error resolving pod labels "+hostName) + checkDebugUrlAndPrint(url, req.Host, "Error resolving pod labels "+hostName + "log: " + log) } else { value["tag"] = podLabels - checkDebugUrlAndPrint(url, req.Host, "Pod labels found in ParseAndProduce, podLabels found "+fmt.Sprint(podLabels)+" for hostName "+hostName) + checkDebugUrlAndPrint(url, req.Host, "Pod labels found in ParseAndProduce, podLabels found "+fmt.Sprint(podLabels)+" for hostName "+hostName + "log: " + log) slog.Debug("Pod labels", "podName", hostName, "labels", podLabels) } } } else { - checkDebugUrlAndPrint(url, req.Host, "Pod labels not resolved, PodInformerInstance is nil or direction is not inbound, direction: "+fmt.Sprint(direction)) + slog.Warn("Pod labels not resolved, PodInformerInstance is nil or direction is not inbound", "log", log) + checkDebugUrlAndPrint(url, req.Host, "Pod labels not resolved, PodInformerInstance is nil or direction is not inbound" + "log: " + log) } out, _ := json.Marshal(value) diff --git a/trafficUtil/kafkaUtil/podinformer.go b/trafficUtil/kafkaUtil/podinformer.go index 14a54c2..83baf4b 100644 --- a/trafficUtil/kafkaUtil/podinformer.go +++ b/trafficUtil/kafkaUtil/podinformer.go @@ -124,7 +124,13 @@ func (w *PodInformer) GetPodNameByProcessId(pid int32) string { if hostName, ok := w.pidHostNameMap[pid]; ok { return hostName } - slog.Warn("Hostname not found for", "processId", pid) + cmd := exec.Command("sh", "-c", fmt.Sprintf("ps -p %d -o comm=", pid)) + output, err := cmd.Output() + if err != nil { + slog.Error("Failed to get process name", "pid", pid) + } + slog.Warn("Hostname not found for", "processId", pid, "commandName", output) + return "" } @@ -152,7 +158,6 @@ func (w *PodInformer) BuildPidHostNameMap() { } func (w *PodInformer) ResolvePodLabels(podName string, url, reqHost string) (string, error) { - slog.Debug("Resolving Pod Name to labels", "podName", podName) checkDebugUrlAndPrint(url, reqHost, "Resolving Pod Name to labels for "+podName) // Step 1: Use the pod name as the key to find labels in podNameLabelsMap @@ -345,4 +350,4 @@ func (w *PodInformer) handlePodDelete(obj interface{}) { // Build the PID to Hostname map again to ensure it is up-to-date // TODO: Optimize this ? What's the rate of pod add events? w.BuildPidHostNameMap() -} \ No newline at end of file +} From 2a4977457bffb2293586991d66f8f25fbe6972cd Mon Sep 17 00:00:00 2001 From: gauravmann Date: Wed, 12 Nov 2025 14:35:15 +0530 Subject: [PATCH 2/2] label resolving add --- trafficUtil/kafkaUtil/parser.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trafficUtil/kafkaUtil/parser.go b/trafficUtil/kafkaUtil/parser.go index 3fe09eb..7a5168e 100644 --- a/trafficUtil/kafkaUtil/parser.go +++ b/trafficUtil/kafkaUtil/parser.go @@ -125,7 +125,7 @@ func UpdateDebugStringsFromFile() { func checkDebugUrlAndPrint(url string, host string, message string) { // url or host. [array string] - message = "mannakto" + message + message = "mannakto: " + message if len(DebugStrings) > 0 { for _, debugString := range DebugStrings { if strings.Contains(url, debugString) { @@ -454,7 +454,7 @@ func ParseAndProduce(receiveBuffer []byte, sentBuffer []byte, sourceIp string, d checkDebugUrlAndPrint(url, req.Host, "Failed to resolve pod name, hostName is empty for processId "+fmt.Sprint(pid) + log) slog.Error("Failed to resolve pod name, hostName is empty for ", "processId", pid, "hostName", hostName, "log", log) } else { - slog.Warn("Resolving Pod Name to labels", "podName", hostName, "log", log) + checkDebugUrlAndPrint(url, req.Host, "Resolving Pod Name to labels podName: " + hostName + "log: " + log) podLabels, err := PodInformerInstance.ResolvePodLabels(hostName, url, req.Host) if err != nil { slog.Error("Failed to resolve pod labels", "hostName", hostName, "error", err)