← 返回题库
中级

构建服务依赖调用图

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    trace_logs_csv = open_url(____).read()
    routing_rules_csv = open_url(____).read()
    import pandas as pd
    from io import StringIO
    traces = pd.read_csv(StringIO(____))
    rules = pd.read_csv(StringIO(____))
    dep_graph = {}
    for tid, grp in traces.groupby(____):
        span_svc = dict(zip(____))
        for _, row in grp.iterrows():
            if pd.notna(____) and row['____'] != '____':
                parent_svc = span_svc.get(____)
                child_svc = row['____']
                if parent_svc and parent_svc != child_svc:
                    dep_graph.setdefault(parent_svc, set()).add(____)
    print(____)
    for caller, callees in sorted(dep_graph.items()):
        print(____)
    print(____)
    for _, r in rules.iterrows():
        print(____)

示例

输入
solve()
期望输出
服务依赖图 (caller -> callees):
  api-gateway -> ['order-service', 'payment-service', 'user-service']
路由规则中的依赖:
  gateway --[/api/v1/users]--> user-service
  gateway --[/api/v1/products]--> product-service
  gateway --[/api/v1/orders]--> order-service
  gateway --[/api/v1/payments]--> payment-service
  gateway --[/api/v1/search]--> search-service
  gateway --[/api/v2/users]--> user-service
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码