@@ -48,6 +48,8 @@ type AnalyzeQueue struct {
48
48
context * common.AccessLogContext
49
49
eventQueue * btf.EventQueue
50
50
perCPUBuffer int64
51
+
52
+ detailSupplier func () events.SocketDetail
51
53
}
52
54
53
55
func NewAnalyzeQueue (ctx * common.AccessLogContext ) (* AnalyzeQueue , error ) {
@@ -71,14 +73,17 @@ func NewAnalyzeQueue(ctx *common.AccessLogContext) (*AnalyzeQueue, error) {
71
73
eventQueue : btf .NewEventQueue (ctx .Config .ProtocolAnalyze .Parallels , ctx .Config .ProtocolAnalyze .QueueSize , func () btf.PartitionContext {
72
74
return NewPartitionContext (ctx )
73
75
}),
76
+ detailSupplier : func () events.SocketDetail {
77
+ return & events.SocketDetailEvent {}
78
+ },
74
79
}, nil
75
80
}
76
81
77
82
func (q * AnalyzeQueue ) Start (ctx context.Context ) {
78
83
q .eventQueue .RegisterReceiver (q .context .BPF .SocketDetailDataQueue , int (q .perCPUBuffer ), func () interface {} {
79
- return & events. SocketDetailEvent {}
84
+ return q . detailSupplier ()
80
85
}, func (data interface {}) string {
81
- return fmt .Sprintf ("%d" , data .(* events.SocketDetailEvent ).GetConnectionID ())
86
+ return fmt .Sprintf ("%d" , data .(events.SocketDetail ).GetConnectionID ())
82
87
})
83
88
q .eventQueue .RegisterReceiver (q .context .BPF .SocketDataUploadEventQueue , int (q .perCPUBuffer ), func () interface {} {
84
89
return & events.SocketDataUploadEvent {}
@@ -89,6 +94,10 @@ func (q *AnalyzeQueue) Start(ctx context.Context) {
89
94
q .eventQueue .Start (ctx , q .context .BPF .Linker )
90
95
}
91
96
97
+ func (q * AnalyzeQueue ) ChangeDetailSupplier (supplier func () events.SocketDetail ) {
98
+ q .detailSupplier = supplier
99
+ }
100
+
92
101
type PartitionContext struct {
93
102
context * common.AccessLogContext
94
103
protocolMgr * ProtocolManager
@@ -164,18 +173,18 @@ func (p *PartitionContext) Start(ctx context.Context) {
164
173
165
174
func (p * PartitionContext ) Consume (data interface {}) {
166
175
switch event := data .(type ) {
167
- case * events.SocketDetailEvent :
168
- pid , _ := events .ParseConnectionID (event .ConnectionID )
176
+ case events.SocketDetail :
177
+ pid , _ := events .ParseConnectionID (event .GetConnectionID () )
169
178
log .Debugf ("receive the socket detail event, connection ID: %d, random ID: %d, pid: %d, data id: %d, " +
170
- "function name: %s, package count: %d, package size: %d, l4 duration: %d, ssl: %d" ,
171
- event .ConnectionID , event .RandomID , pid , event .DataID0 , event .FunctionName ,
172
- event .L4PackageCount , event .L4TotalPackageSize , event .L4Duration , event . SSL )
173
- if event .Protocol == enums .ConnectionProtocolUnknown {
179
+ "function name: %s, package count: %d, package size: %d, ssl: %d" ,
180
+ event .GetConnectionID () , event .GetRandomID () , pid , event .DataID () , event .GetFunctionName () ,
181
+ event .GetL4PackageCount () , event .GetL4TotalPackageSize () , event .GetSSL () )
182
+ if event .GetProtocol () == enums .ConnectionProtocolUnknown {
174
183
// if the connection protocol is unknown, we just needs to add this into the kernel log
175
184
forwarder .SendTransferNoProtocolEvent (p .context , event )
176
185
return
177
186
}
178
- connection := p .getConnectionContext (event .GetConnectionID (), event .GetRandomID (), event .Protocol )
187
+ connection := p .getConnectionContext (event .GetConnectionID (), event .GetRandomID (), event .GetProtocol () )
179
188
connection .appendDetail (p .context , event )
180
189
case * events.SocketDataUploadEvent :
181
190
pid , _ := events .ParseConnectionID (event .ConnectionID )
@@ -303,7 +312,7 @@ type PartitionConnection struct {
303
312
lastCheckCloseTime time.Time
304
313
}
305
314
306
- func (p * PartitionConnection ) appendDetail (ctx * common.AccessLogContext , detail * events.SocketDetailEvent ) {
315
+ func (p * PartitionConnection ) appendDetail (ctx * common.AccessLogContext , detail events.SocketDetail ) {
307
316
if p .skipAllDataAnalyze {
308
317
// if the connection is already skip all data analyze, then just send the detail event
309
318
forwarder .SendTransferNoProtocolEvent (ctx , detail )
0 commit comments