← 返回题库
中级

实现服务健康检查与摘除

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    service_registry_csv = open_url(____).read()
    import pandas as pd
    from io import StringIO
    registry = pd.read_csv(StringIO(____)).copy()
    def health_check(____):
        idx = registry[registry['____']==instance_id].index
        if idx.empty: return False
        registry.loc[idx[____],'____'] = '____' if simulate_healthy else '____'
        return True
    def get_healthy(____):
        return registry[(____) & (____)]['____'].tolist()
    print(____)
    for svc in registry['____'].unique():
        print(____)
    health_check(____)
    health_check(____)
    health_check(____)
    print(____)
    for svc in registry['____'].unique():
        healthy = get_healthy(____)
        alert = '____' if not healthy else '____'
        print(____)

示例

输入
solve()
期望输出
初始健康实例:
  user-service: ['user-1', 'user-2', 'user-3']
  product-service: ['prod-1', 'prod-3']
  order-service: ['order-1', 'order-2']
  payment-service: ['pay-1', 'pay-2']
  search-service: ['search-1', 'search-2']
更新后:
  user-service: ['user-1', 'user-2', 'user-3']
  product-service: ['prod-3']
  order-service: ['order-2']
  payment-service: ['pay-1', 'pay-2']
  search-service: ['search-1', 'search-2']
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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