Sfoglia il codice sorgente

Fixed #JiraBug28136 ebpf pg 抓不到 sql

roger.wang 1 anno fa
parent
commit
f655ef94bf
2 ha cambiato i file con 12 aggiunte e 5 eliminazioni
  1. 6 0
      ebpftracer/ebpf/l7/postgres.c
  2. 6 5
      tracing/apm_tracing.go

+ 6 - 0
ebpftracer/ebpf/l7/postgres.c

@@ -45,6 +45,12 @@ int is_postgres_response(char *buf, __u64 buf_size, __u32 *status) {
     if ((cmd == '1' || cmd == '2') && length == 4 && buf_size >= 10) {
         bpf_read(buf+5, cmd);
         bpf_read(buf+5+1, length);
+        length = bpf_htonl(length);
+    }
+    if ((cmd == '1' || cmd == '2') && length == 4 && buf_size >= 15) {
+        bpf_read(buf+5+5, cmd);
+        bpf_read(buf+5+5+1, length);
+        length = bpf_htonl(length);
     }
     if (cmd == 'E') {
         *status = STATUS_FAILED;

+ 6 - 5
tracing/apm_tracing.go

@@ -3,6 +3,11 @@ package tracing
 import (
 	"context"
 	"fmt"
+	"strconv"
+	"strings"
+	"sync/atomic"
+	"time"
+
 	"github.com/coroot/coroot-node-agent/ebpftracer"
 	"github.com/coroot/coroot-node-agent/ebpftracer/l7"
 	"github.com/coroot/coroot-node-agent/utils"
@@ -13,10 +18,6 @@ import (
 	semconv "go.opentelemetry.io/otel/semconv/v1.18.0"
 	"go.opentelemetry.io/otel/trace"
 	"inet.af/netaddr"
-	"strconv"
-	"strings"
-	"sync/atomic"
-	"time"
 )
 
 /**
@@ -319,7 +320,7 @@ func isCURDOperation(q string) bool {
 		return false
 	}
 	q = strings.ToUpper(q[:6])
-	return q == "SELECT" || q == "INSERT" || q == "UPDATE" || q == "DELETE"
+	return q == "SELECT" || q == "INSERT" || q == "UPDATE" || q == "DELETE" || q == "PREPAR"
 }
 
 func (t *Trace) SQLTraceQueryEvent(l7Type l7.Protocol, semconvVal attribute.KeyValue, query string, r *l7.RequestData, destination netaddr.IPPort) {