Skip to content

Commit ff636f3

Browse files
committed
[app] build related_ids after pruning
1 parent 491f845 commit ff636f3

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

app/app/application/l7_flow_tracing.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,13 +2511,16 @@ def pruning_trace(response, _id, network_delay_us):
25112511

25122512

25132513
def calculate_related_ids(
2514-
response, flow_index_to_id0: list,
2514+
response, flow_index_to_id0: list, pruning_uid_index_map: dict,
25152515
related_flow_index_map: defaultdict(inner_defaultdict_set)):
25162516
"""
25172517
计算 flow 的 related_ids 字段。
25182518
当 related_ids 很多时,构造这些字符串非常耗时,因此这一步放在 pruning_trace 之后进行。
25192519
25202520
response: {'tracing': [flow]}
2521+
flow_index_to_id0: flow_index => _id
2522+
pruning_uid_index_map: flow_index => index of reponse.tracing
2523+
related_flow_index_map: flow_index => [{flow_index => related_type}]
25212524
"""
25222525
_FLOW_INDEX_KEY = 'id' # after _get_flow_dict(), _index change to id
25232526

@@ -2526,6 +2529,8 @@ def calculate_related_ids(
25262529
flow['related_ids'] = []
25272530
for _index, related_types in related_flow_index_map[
25282531
flow[_FLOW_INDEX_KEY]].items():
2532+
if pruning_uid_index_map.get(_index, -1) < 0:
2533+
continue
25292534
_id = flow_index_to_id0[_index]
25302535
flow['related_ids'].append(
25312536
f"{_index}-{','.join(related_types)}-{_id}")
@@ -2611,10 +2616,10 @@ def format_final_result(
26112616
response = format_trace(services, networks)
26122617
# after `format_trace`, _get_flow_dict convert flow to flow_dict
26132618
pruning_trace(response, _id, network_delay_us) # XXX: slow function
2614-
calculate_related_ids(response, flow_index_to_id0,
2615-
related_flow_index_map) # XXX: slow function
26162619
traces = response.get('tracing', [])
26172620
uid_index_map = {trace["id"]: i for i, trace in enumerate(traces)}
2621+
calculate_related_ids(response, flow_index_to_id0, uid_index_map,
2622+
related_flow_index_map) # XXX: slow function
26182623
for trace in traces:
26192624
format_selftime(traces, trace, trace.get("childs", []), uid_index_map)
26202625
response['services'] = merge_service(services, traces, uid_index_map)

0 commit comments

Comments
 (0)