@@ -18,7 +18,7 @@ use std::cell::RefMut;
1818
1919use super :: flow:: PacketDirection ;
2020use enum_dispatch:: enum_dispatch;
21- use log:: { debug, error, warn } ;
21+ use log:: { debug, error} ;
2222use serde:: Serialize ;
2323
2424use crate :: {
@@ -224,15 +224,16 @@ where
224224
225225 /*
226226 calculate rrt
227- if have previous log cache:
227+ if session
228+ return stats
229+ if request
230+ update rrt cache
231+ return stats
232+ if response
228233 if previous is req and current is resp and current time > previous time
229234 rrt = current time - previous time
230- if previous is resp and current is req and current time < previous time, likely ebfp disorder
231- rrt = previous time - current time
232-
233- otherwise can not calculate rrt, cache current log rrt
234-
235- if have no previous log cache, cache the current log rrt
235+ remove rrt cache
236+ return stats
236237 */
237238 fn perf_stats ( & self , param : & ParseParam ) -> Option < L7PerfStats > {
238239 if param. time == 0 {
@@ -284,14 +285,16 @@ where
284285 //
285286 // If the first log is a response, its perf stats will not be counted here.
286287 // We need to know whether its corresponding request is on blacklist before accounting.
287- let ret = if cur_info. msg_type == LogMessageType :: Request && !cur_info. on_blacklist {
288- timeout_counter. in_cache [ index] += 1 ;
289- Some ( L7PerfStats :: from ( & cur_info) )
288+ return if !cur_info. on_blacklist {
289+ let stats = L7PerfStats :: from ( & cur_info) ;
290+ if cur_info. msg_type == LogMessageType :: Request {
291+ timeout_counter. in_cache [ index] += 1 ;
292+ rtt_cache. put ( key, cur_info) ;
293+ }
294+ Some ( stats)
290295 } else {
291296 None
292297 } ;
293- rtt_cache. put ( key, cur_info) ;
294- return ret;
295298 } ;
296299
297300 let mut keep_prev = false ;
@@ -343,85 +346,25 @@ where
343346 rtt_cache. pop ( & key) ;
344347 }
345348
346- result
347- } else if prev_info. is_response_of ( & cur_info) {
348- // cur_info is request, prev_info is response
349- // request not accounted before
350- let result = if !cur_info. on_blacklist {
351- let mut perf_stats = L7PerfStats :: from ( & cur_info) ;
352-
353- if !prev_info. on_blacklist {
354- let rrt = prev_info. time - cur_info. time ;
355- if rrt > param. rrt_timeout as u64 {
356- warn ! ( "l7 log info disorder with long time rrt {}" , rrt) ;
357- match prev_info. multi_merge_info . as_ref ( ) {
358- Some ( info) if info. merged => ( ) ,
359- _ => timeout_counter. timeout [ index] += 1 ,
360- }
361- }
362-
363- perf_stats. sequential_merge ( & L7PerfStats :: from ( & * prev_info) ) ;
364- perf_stats. update_rrt ( rrt) ;
365- }
366-
367- Some ( perf_stats)
368- } else {
369- None
370- } ;
371-
372- if !keep_prev {
373- rtt_cache. pop ( & key) ;
374- }
375-
376349 result
377350 } else if !self . need_merge ( ) {
378351 debug ! (
379352 "can not calculate rrt, flow_id: {}, previous log type: {:?}, previous time: {}, current log type: {:?}, current time: {}" ,
380353 param. flow_id, prev_info. msg_type, prev_info. time, cur_info. msg_type, cur_info. time,
381354 ) ;
382355
383- if prev_info. time > cur_info. time {
384- if !cur_info. on_blacklist && cur_info. msg_type == LogMessageType :: Request {
385- timeout_counter. timeout [ index] += 1 ;
386- }
387- if !prev_info. on_blacklist && prev_info. msg_type == LogMessageType :: Request {
388- timeout_counter. in_cache [ index] += 1 ;
389- }
390- if !cur_info. on_blacklist {
391- Some ( L7PerfStats :: from ( & cur_info) )
392- } else {
393- None
356+ if !keep_prev {
357+ rtt_cache. pop ( & key) ;
358+ }
359+
360+ if !cur_info. on_blacklist {
361+ let stats = L7PerfStats :: from ( & cur_info) ;
362+ if cur_info. msg_type == LogMessageType :: Request {
363+ rtt_cache. put ( key, cur_info) ;
394364 }
365+ Some ( stats)
395366 } else {
396- if !prev_info. on_blacklist && prev_info. msg_type == LogMessageType :: Request {
397- timeout_counter. timeout [ index] += 1 ;
398- }
399- if !cur_info. on_blacklist && cur_info. msg_type == LogMessageType :: Request {
400- timeout_counter. in_cache [ index] += 1 ;
401- }
402- let cur_is_req = cur_info. msg_type == LogMessageType :: Request ;
403- let cur_on_blacklist = cur_info. on_blacklist ;
404- let prev_info = rtt_cache. put ( key, cur_info) . unwrap ( ) ;
405- // Requests are counted (req=1) eagerly when they first enter the cache,
406- // so re-emitting a displaced Request here would double-count it.
407- // Responses were cached with None on arrival and must be counted here.
408- let mut result =
409- if !prev_info. on_blacklist && prev_info. msg_type == LogMessageType :: Response {
410- L7PerfStats :: from ( & prev_info)
411- } else {
412- L7PerfStats :: default ( )
413- } ;
414- // A new Request entering the cache via this path (replacing a previous entry)
415- // was never counted by the first-entry path, so emit req=1 now so that
416- // "request accounted before" holds when its response arrives via is_request_of.
417- if !cur_on_blacklist && cur_is_req {
418- result. inc_req ( ) ;
419- }
420- if result == L7PerfStats :: default ( ) {
421- None
422- } else {
423- Some ( result)
424- }
367+ None
425368 }
426369 } else {
427370 if !prev_info. on_blacklist
0 commit comments