Skip to content

Commit 0555dc4

Browse files
authored
fix: ReadTCPRequestIntoSpan missing unmatched debug print (#945)
1 parent 40f26e3 commit 0555dc4

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

pkg/ebpf/common/tcp_detect_transform.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func ReadTCPRequestIntoSpan(parseCtx *EBPFParseContext, cfg *config.EBPFTracer,
139139
return request.Span{}, true, nil // ignore for now, next event will be parsed
140140
} else {
141141
k, ignore, err := ProcessPossibleKafkaEvent(event, requestBuffer, responseBuffer, parseCtx.kafkaTopicUUIDToName)
142-
if ignore {
142+
if ignore && err == nil {
143143
return request.Span{}, true, nil // parsed kafka event, but we don't want to create a span for it
144144
}
145145
if err == nil {

pkg/ebpf/common/tcp_detect_transform_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ package ebpfcommon
66
import (
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

5087
func TestSQLDetection(t *testing.T) {

0 commit comments

Comments
 (0)