Skip to content

Commit 491f845

Browse files
taloricsharang
authored andcommitted
[app] fix query when app_spans can not found _id
1 parent 3dc024e commit 491f845

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

app/app/application/l7_flow_tracing.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,21 +497,25 @@ async def trace_l7_flow(
497497
time_filter, base_filter, max_iteration, network_delay_us,
498498
app_spans_from_api)
499499

500-
if len(l7_flow_ids) == 0:
500+
if len(l7_flow_ids) == 0 and len(app_spans_from_external) == 0:
501501
return {}
502502

503503
# 查询会获取这些 _id 对应的完整 l7_flow_log 信息。
504504
# 通过 RETURN_FIELDS 确定需要返回哪些字段(精简有用的返回信息)
505505
return_fields = RETURN_FIELDS
506506
if self.has_attributes:
507507
return_fields.append("attribute")
508-
l7_flows = await self.query_all_flows(time_filter, l7_flow_ids,
509-
return_fields)
510-
if type(l7_flows) != DataFrame or l7_flows.empty:
511-
# 几乎不可能发生没有 l7_flows 但有 app_spans_from_apm 的情况
512-
# 实际上几乎不可能发生没有 l7_flows 的情况,因为至少包含初始 flow
513-
return {}
514-
l7_flows.rename(columns={'_id_str': '_id'}, inplace=True)
508+
l7_flows = pd.DataFrame()
509+
if len(l7_flow_ids) > 0:
510+
l7_flows = await self.query_all_flows(time_filter, l7_flow_ids,
511+
return_fields)
512+
if type(l7_flows) != DataFrame or l7_flows.empty:
513+
# 一般不可能发生没有 l7_flows 但有 app_spans_from_external 的情况
514+
# 实际上几乎不可能发生没有 l7_flows 的情况,因为至少包含初始 flow
515+
# 但由于 tracing_completion api 也调用此处追踪逻辑,接口可能传入不存在的 trace_id
516+
# 所以这里兼容 len(l7_flow_ids)=0 场景,仅对: 当 len(l7_flow_ids)>0 但 `query_all_flows` 为空时返回
517+
return {}
518+
l7_flows.rename(columns={'_id_str': '_id'}, inplace=True)
515519

516520
# 将外部 APM 查询到的 Span 与数据库中的 Span 结果进行合并
517521
l7_flows = self.concat_l7_flow_log_dataframe(

app/app/application/tracing_completion.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ async def query(self):
3333
"_id"] # after `complete_app_span`, _id has been filled
3434
if trace_id:
3535
_id = await self.get_id_by_trace_id(trace_id, time_filter)
36-
base_filter += f"_id = {_id}"
36+
if _id != "":
37+
base_filter += f"_id = {_id}"
38+
else:
39+
# when trace_id not found, we still need to `sort_all_flows` and `format_final_result` for app_spans
40+
# so we use `1=0` filter to avoid query error
41+
base_filter = "1=0"
3742
break
3843
self.args._id = app_span_id # set app_span_id as args, make it never been pruning
3944
# build related_map inside app_spans

0 commit comments

Comments
 (0)