Skip to content

Commit eed4401

Browse files
committed
dbeug direction
1 parent abf328c commit eed4401

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

trafficUtil/kafkaUtil/parser.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ func UpdateDebugStringsFromFile() {
125125

126126
func checkDebugUrlAndPrint(url string, host string, message string) {
127127
// url or host. [array string]
128+
message = "mannakto" + message
128129
if len(DebugStrings) > 0 {
129130
for _, debugString := range DebugStrings {
130131
if strings.Contains(url, debugString) {
@@ -434,7 +435,7 @@ func ParseAndProduce(receiveBuffer []byte, sentBuffer []byte, sourceIp string, d
434435
// Process id was captured from the eBPF program using bpf_get_current_pid_tgid()
435436
// Shifting by 32 gives us the process id on host machine.
436437
var pid = idfd >> 32
437-
log := fmt.Sprintf("pod direction log: direction=%v, host=%v, path=%v, sourceIp=%v, destIp=%v, socketId=%v, processId=%v, hostName=%v",
438+
log := fmt.Sprintf("direction=%v, host=%v, path=%v, sourceIp=%v, destIp=%v, socketId=%v, processId=%v, hostName=%v",
438439
direction,
439440
reqHeaderStr["host"],
440441
value["path"],
@@ -444,27 +445,29 @@ func ParseAndProduce(receiveBuffer []byte, sentBuffer []byte, sourceIp string, d
444445
pid,
445446
hostName,
446447
)
447-
utils.PrintLog(log)
448-
checkDebugUrlAndPrint(url, req.Host, log)
448+
slog.Warn("before resolving labels pod direction log" + log)
449+
checkDebugUrlAndPrint(url, req.Host, "before resolving labels pod direction log" + log)
449450

450451
if PodInformerInstance != nil && direction == utils.DirectionInbound {
451452

452453
if hostName == "" {
453-
checkDebugUrlAndPrint(url, req.Host, "Failed to resolve pod name, hostName is empty for processId "+fmt.Sprint(pid))
454-
slog.Error("Failed to resolve pod name, hostName is empty for ", "processId", pid, "hostName", hostName)
454+
checkDebugUrlAndPrint(url, req.Host, "Failed to resolve pod name, hostName is empty for processId "+fmt.Sprint(pid) + log)
455+
slog.Error("Failed to resolve pod name, hostName is empty for ", "processId", pid, "hostName", hostName, "log", log)
455456
} else {
457+
slog.Warn("Resolving Pod Name to labels", "podName", hostName, "log", log)
456458
podLabels, err := PodInformerInstance.ResolvePodLabels(hostName, url, req.Host)
457459
if err != nil {
458460
slog.Error("Failed to resolve pod labels", "hostName", hostName, "error", err)
459-
checkDebugUrlAndPrint(url, req.Host, "Error resolving pod labels "+hostName)
461+
checkDebugUrlAndPrint(url, req.Host, "Error resolving pod labels "+hostName + "log: " + log)
460462
} else {
461463
value["tag"] = podLabels
462-
checkDebugUrlAndPrint(url, req.Host, "Pod labels found in ParseAndProduce, podLabels found "+fmt.Sprint(podLabels)+" for hostName "+hostName)
464+
checkDebugUrlAndPrint(url, req.Host, "Pod labels found in ParseAndProduce, podLabels found "+fmt.Sprint(podLabels)+" for hostName "+hostName + "log: " + log)
463465
slog.Debug("Pod labels", "podName", hostName, "labels", podLabels)
464466
}
465467
}
466468
} else {
467-
checkDebugUrlAndPrint(url, req.Host, "Pod labels not resolved, PodInformerInstance is nil or direction is not inbound, direction: "+fmt.Sprint(direction))
469+
slog.Warn("Pod labels not resolved, PodInformerInstance is nil or direction is not inbound", "log", log)
470+
checkDebugUrlAndPrint(url, req.Host, "Pod labels not resolved, PodInformerInstance is nil or direction is not inbound" + "log: " + log)
468471
}
469472

470473
out, _ := json.Marshal(value)

trafficUtil/kafkaUtil/podinformer.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ func (w *PodInformer) GetPodNameByProcessId(pid int32) string {
124124
if hostName, ok := w.pidHostNameMap[pid]; ok {
125125
return hostName
126126
}
127-
slog.Warn("Hostname not found for", "processId", pid)
127+
cmd := exec.Command("sh", "-c", fmt.Sprintf("ps -p %d -o comm=", pid))
128+
output, err := cmd.Output()
129+
if err != nil {
130+
slog.Error("Failed to get process name", "pid", pid)
131+
}
132+
slog.Warn("Hostname not found for", "processId", pid, "commandName", output)
133+
128134
return ""
129135
}
130136

@@ -152,7 +158,6 @@ func (w *PodInformer) BuildPidHostNameMap() {
152158
}
153159

154160
func (w *PodInformer) ResolvePodLabels(podName string, url, reqHost string) (string, error) {
155-
slog.Debug("Resolving Pod Name to labels", "podName", podName)
156161
checkDebugUrlAndPrint(url, reqHost, "Resolving Pod Name to labels for "+podName)
157162

158163
// Step 1: Use the pod name as the key to find labels in podNameLabelsMap
@@ -345,4 +350,4 @@ func (w *PodInformer) handlePodDelete(obj interface{}) {
345350
// Build the PID to Hostname map again to ensure it is up-to-date
346351
// TODO: Optimize this ? What's the rate of pod add events?
347352
w.BuildPidHostNameMap()
348-
}
353+
}

0 commit comments

Comments
 (0)