Skip to content

Commit dee332a

Browse files
taloricsharang
authored andcommitted
fix: ignore time cover for OTel source
1 parent 03f2dc7 commit dee332a

1 file changed

Lines changed: 37 additions & 26 deletions

File tree

app/app/application/l7_flow_tracing.py

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,12 +1785,15 @@ def indirect_attach_client_sys_span_via_sys_span(
17851785
self.mounted_callback)
17861786
return True
17871787

1788+
17881789
def _get_auto_instance_name(span: SpanNode) -> str:
17891790
"""
17901791
get auto_instance name for span
17911792
only for Ebpf/Packet signal source
17921793
"""
1793-
return span.flow["auto_instance_0"] if span.tap_side.startswith('c') and span.tap_side != "app" else span.flow["auto_instance_1"]
1794+
return span.flow["auto_instance_0"] if span.tap_side.startswith(
1795+
'c') and span.tap_side != "app" else span.flow["auto_instance_1"]
1796+
17941797

17951798
def _get_auto_instance(span: SpanNode) -> str:
17961799
"""
@@ -2034,12 +2037,14 @@ def sort_all_flows(dataframe_flows: DataFrame, network_delay_us: int,
20342037
else:
20352038
client_sys_spans.append(span)
20362039
if span.auto_instance != "":
2037-
instance_to_agent[_get_auto_instance_name(span)] = span.agent_id
2040+
instance_to_agent[_get_auto_instance_name(
2041+
span)] = span.agent_id
20382042
elif flow['signal_source'] == L7_FLOW_SIGNAL_SOURCE_PACKET:
20392043
span = NetworkSpanNode(flow)
20402044
network_spans.append(span)
20412045
if span.auto_instance != "":
2042-
instance_to_agent[_get_auto_instance_name(span)] = span.agent_id
2046+
instance_to_agent[_get_auto_instance_name(
2047+
span)] = span.agent_id
20432048
elif flow['signal_source'] == L7_FLOW_SIGNAL_SOURCE_OTEL:
20442049
span = AppSpanNode(flow)
20452050
app_spans.append(span)
@@ -2340,16 +2345,17 @@ def _connect_process_and_networks(
23402345
if _same_span_set(ps_parent, net_child, 'network_span_set') \
23412346
or _same_span_set(ps_parent, net_child, 'process_span_set'):
23422347
continue
2343-
if net_child.agent_id == ps_parent.agent_id and not ps_parent.time_range_cover(
2344-
net_child):
2345-
# 对同一个主机采集到的数据,不存在时差
2346-
continue
2347-
if net_child.signal_source != L7_FLOW_SIGNAL_SOURCE_OTEL and ps_parent.signal_source != L7_FLOW_SIGNAL_SOURCE_OTEL and \
2348-
net_child.get_response_duration() and ps_response_duration < net_child.get_response_duration():
2349-
# 如果能取到响应时长(请求响应完整),需要判断响应时长覆盖
2350-
# 由于 app span 的时长是在 sdk 中统计,如果发生子 span 异步完成,父 span 提前完成,子 span 时间可以大于父 span
2351-
# 所以这里判断 response_duration 忽略 OTEL signal_source
2352-
continue
2348+
if net_child.signal_source != L7_FLOW_SIGNAL_SOURCE_OTEL and ps_parent.signal_source != L7_FLOW_SIGNAL_SOURCE_OTEL:
2349+
if net_child.agent_id == ps_parent.agent_id and not ps_parent.time_range_cover(
2350+
net_child):
2351+
# 对同一个主机采集到的数据,不存在时差
2352+
continue
2353+
if net_child.get_response_duration(
2354+
) and ps_response_duration < net_child.get_response_duration():
2355+
# 如果能取到响应时长(请求响应完整),需要判断响应时长覆盖
2356+
# 由于 app span 的时长是在 sdk 中统计,如果发生子 span 异步完成,父 span 提前完成,子 span 时间可以大于父 span
2357+
# 所以这里判断 response_duration 忽略 OTEL signal_source
2358+
continue
23532359
if ps_index == net_child.get_flow_index():
23542360
# 共享一个 c-p, net_child parent == ps_parent 的 parent
23552361
continue
@@ -2373,12 +2379,14 @@ def _connect_process_and_networks(
23732379
if _same_span_set(ps_child, net_parent, 'network_span_set') \
23742380
or _same_span_set(ps_child, net_parent, 'process_span_set'):
23752381
continue
2376-
if ps_child.agent_id == net_parent.agent_id and not net_parent.time_range_cover(
2377-
ps_child):
2378-
continue
2379-
if net_parent.signal_source != L7_FLOW_SIGNAL_SOURCE_OTEL and ps_child.signal_source!= L7_FLOW_SIGNAL_SOURCE_OTEL and \
2380-
net_parent.get_response_duration() and net_parent.get_response_duration() < ps_child_response_duration:
2381-
continue
2382+
if net_parent.signal_source != L7_FLOW_SIGNAL_SOURCE_OTEL and ps_child.signal_source != L7_FLOW_SIGNAL_SOURCE_OTEL:
2383+
if ps_child.agent_id == net_parent.agent_id and not net_parent.time_range_cover(
2384+
ps_child):
2385+
continue
2386+
if net_parent.get_response_duration(
2387+
) and net_parent.get_response_duration(
2388+
) < ps_child_response_duration:
2389+
continue
23822390
if ps_index == net_parent.get_flow_index():
23832391
# 共享一个 s-p,则 ps_child 的 parent == net_parent 的 parent
23842392
continue
@@ -2415,12 +2423,14 @@ def _connect_process_and_networks(
24152423
if _same_span_set(ps_child, ps_parent, 'network_span_set') \
24162424
or _same_span_set(ps_child, ps_parent, 'process_span_set'):
24172425
continue
2418-
if ps_child.agent_id == ps_parent.agent_id and not ps_parent.time_range_cover(
2419-
ps_child):
2420-
continue
2421-
if ps_parent.signal_source != L7_FLOW_SIGNAL_SOURCE_OTEL and ps_child.signal_source!= L7_FLOW_SIGNAL_SOURCE_OTEL and \
2422-
ps_parent.get_response_duration() and ps_parent.get_response_duration() < ps_child_response_duration:
2423-
continue
2426+
if ps_parent.signal_source != L7_FLOW_SIGNAL_SOURCE_OTEL and ps_child.signal_source != L7_FLOW_SIGNAL_SOURCE_OTEL:
2427+
if ps_parent.agent_id == ps_child.agent_id and not ps_parent.time_range_cover(
2428+
ps_child):
2429+
continue
2430+
if ps_parent.get_response_duration(
2431+
) and ps_parent.get_response_duration(
2432+
) < ps_child_response_duration:
2433+
continue
24242434
if ps_child_index == ps_parent.get_flow_index():
24252435
# 共享一个 c-p,则 ps_child 的 parent == ps_parent 的 parent
24262436
continue
@@ -2818,7 +2828,8 @@ def correct_span_time(flows: dict, host_clock_correction: dict,
28182828
else:
28192829
# OTel data maybe sent to different host and tag by different agent
28202830
# should verify `agent` by instance_to_agent record by Ebpf/Packet signal source
2821-
agent_id = instance_to_agent.get(flow['auto_instance'], flow['vtap_id'])
2831+
agent_id = instance_to_agent.get(flow['auto_instance'],
2832+
flow['vtap_id'])
28222833
if host_clock_correction.get(agent_id, 0) != 0:
28232834
flow['start_time_us'] += host_clock_correction[agent_id]
28242835
flow['end_time_us'] += host_clock_correction[agent_id]

0 commit comments

Comments
 (0)