@@ -6,8 +6,12 @@ package ebpfcommon
66import (
77 "bytes"
88 "encoding/binary"
9+ "errors"
910 "fmt"
11+ "io"
12+ "log"
1013 "math/rand/v2"
14+ "os"
1115 "strings"
1216 "testing"
1317
@@ -45,6 +49,39 @@ func TestTCPReqParsing(t *testing.T) {
4549 assert .Empty (t , op )
4650 assert .Empty (t , table )
4751 assert .NotNil (t , r )
52+
53+ // Verify fallback debug logs appear when no protocol matches
54+ cfg := config.EBPFTracer {HeuristicSQLDetect : false , ProtocolDebug : true }
55+ ctx := NewEBPFParseContext (& cfg , nil , nil )
56+
57+ pipeR , pipeW , _ := os .Pipe ()
58+ stdout := os .Stdout
59+ os .Stdout = pipeW
60+ var output bytes.Buffer
61+ done := make (chan bool )
62+ go func () {
63+ _ , err := io .Copy (& output , pipeR )
64+ if err != nil && ! errors .Is (err , io .EOF ) {
65+ log .Printf ("io.Copy error: %v" , err )
66+ }
67+ done <- true
68+ }()
69+
70+ binaryRecord := bytes.Buffer {}
71+ require .NoError (t , binary .Write (& binaryRecord , binary .LittleEndian , r ))
72+ fltr := TestPidsFilter {services : map [uint32 ]svc.Attrs {}}
73+ span , ignore , err := ReadTCPRequestIntoSpan (ctx , & cfg , & ringbuf.Record {RawSample : binaryRecord .Bytes ()}, & fltr )
74+ require .NoError (t , err )
75+ assert .Equal (t , request.Span {}, span )
76+ assert .True (t , ignore )
77+
78+ pipeW .Close ()
79+ os .Stdout = stdout
80+ <- done
81+ pipeR .Close ()
82+
83+ assert .Contains (t , output .String (), "![>]" )
84+ assert .Contains (t , output .String (), "![<]" )
4885}
4986
5087func TestSQLDetection (t * testing.T ) {
0 commit comments