Skip to content

Commit e51d5cd

Browse files
authored
Add large buffer debug logs under protocol_debug_print (#833)
Signed-off-by: Mattia Meleleo <[email protected]>
1 parent b0f1aca commit e51d5cd

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

internal/test/integration/docker-compose-elasticsearch.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ services:
5555
OTEL_EBPF_METRICS_FEATURES: "application"
5656
OTEL_EBPF_BPF_BUFFER_SIZE_HTTP: 1024
5757
OTEL_EBPF_HTTP_ELASTICSEARCH_ENABLED: true
58+
OTEL_EBPF_PROTOCOL_DEBUG_PRINT: true
5859
depends_on:
5960
testserver:
6061
condition: service_started

internal/test/integration/docker-compose-python-aws.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ services:
5252
OTEL_EBPF_METRICS_FEATURES: "application"
5353
OTEL_EBPF_BPF_BUFFER_SIZE_HTTP: 2048
5454
OTEL_EBPF_HTTP_AWS_ENABLED: true
55+
OTEL_EBPF_PROTOCOL_DEBUG_PRINT: true
5556
depends_on:
5657
testserver:
5758
condition: service_started

pkg/ebpf/common/common.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ type MisclassifiedEvent struct {
128128
}
129129

130130
type EBPFParseContext struct {
131+
protocolDebug bool
131132
h2c *lru.Cache[uint64, h2Connection]
132133
redisDBCache *simplelru.LRU[BpfConnectionInfoT, int]
133134
largeBuffers *expirable.LRU[largeBufferKey, *largeBuffer]
@@ -156,6 +157,7 @@ func ptlog() *slog.Logger { return slog.With("component", "ebpf.ProcessTracer")
156157
func NewEBPFParseContext(cfg *config.EBPFTracer, spansChan *msg.Queue[[]request.Span], filter ServiceFilter) *EBPFParseContext {
157158
var (
158159
err error
160+
protocolDebug bool
159161
redisDBCache *simplelru.LRU[BpfConnectionInfoT, int]
160162
mysqlPreparedStatements *simplelru.LRU[mysqlPreparedStatementsKey, string]
161163
postgresPreparedStatements *simplelru.LRU[postgresPreparedStatementsKey, string]
@@ -170,6 +172,8 @@ func NewEBPFParseContext(cfg *config.EBPFTracer, spansChan *msg.Queue[[]request.
170172
largeBuffers := expirable.NewLRU[largeBufferKey, *largeBuffer](1024, nil, 5*time.Minute)
171173

172174
if cfg != nil {
175+
protocolDebug = cfg.ProtocolDebug
176+
173177
if cfg.RedisDBCache.Enabled {
174178
redisDBCache, err = simplelru.NewLRU[BpfConnectionInfoT, int](cfg.RedisDBCache.MaxSize, nil)
175179
if err != nil {
@@ -206,6 +210,7 @@ func NewEBPFParseContext(cfg *config.EBPFTracer, spansChan *msg.Queue[[]request.
206210
}
207211

208212
return &EBPFParseContext{
213+
protocolDebug: protocolDebug,
209214
h2c: h2c,
210215
redisDBCache: redisDBCache,
211216
largeBuffers: largeBuffers,

pkg/ebpf/common/tcp_large_buffer.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func appendTCPLargeBuffer(parseCtx *EBPFParseContext, record *ringbuf.Record) (r
4242
connInfo: event.ConnInfo,
4343
}
4444

45+
if parseCtx.protocolDebug {
46+
fmt.Printf(">>> LargeBufferAppend: (packet=%d direction=%d action=%d)\n%s\n", event.PacketType, event.Direction, event.Action, string(record.RawSample[hdrSize:hdrSize+event.Len]))
47+
}
48+
4549
switch event.Action {
4650
case largeBufferActionInit:
4751
newBuffer := make([]byte, event.Len)
@@ -70,9 +74,17 @@ func extractTCPLargeBuffer(parseCtx *EBPFParseContext, traceID [16]uint8, packet
7074
connInfo: connInfo,
7175
}
7276

77+
//nolint:gocritic
7378
if lb, ok := parseCtx.largeBuffers.Get(key); ok {
79+
if parseCtx.protocolDebug {
80+
fmt.Printf("<<< LargeBufferExtract: (packet=%d direction=%d)\n%s\n", key.packetType, key.direction, string(lb.buf))
81+
}
7482
parseCtx.largeBuffers.Remove(key)
7583
return lb.buf, true
84+
} else {
85+
if parseCtx.protocolDebug {
86+
fmt.Println("<<< LargeBufferExtract: not found!")
87+
}
7688
}
7789

7890
return nil, false

0 commit comments

Comments
 (0)