소스 검색

optimize log

supeng 4 달 전
부모
커밋
6be70948e8
2개의 변경된 파일9개의 추가작업 그리고 9개의 파일을 삭제
  1. 3 1
      longvideoapi/longvideoapi_update_k.py
  2. 6 8
      longvideoapi/utils.py

+ 3 - 1
longvideoapi/longvideoapi_update_k.py

@@ -66,6 +66,7 @@ async def ess_instance(ecs_client, alb_client, ess_count, max_workers, version,
     server_start_sh = os.path.join(longvideoapi_config.start_sh['target_dir'], longvideoapi_config.start_sh['name'])
     server_start_commend = f"sh {server_start_sh} {version}"
     utils.run_command(ecs_client=ecs_client, instance_ids=ess_instance_ids, command=server_start_commend)
+    logging.info(f"start server finish, instances: {ess_instance_ids}")
     # 4. 异步探活
     global health_instances
     health_instances = []
@@ -76,7 +77,7 @@ async def ess_instance(ecs_client, alb_client, ess_count, max_workers, version,
         [(ecs_client, instance_id) for instance_id in ess_instance_ids]
     ]
     await asyncio.wait(tasks)
-    logging.info(f"health instances count: {len(health_instances)}, {health_instances}")
+    logging.info(f"health instances count: {len(health_instances)}, instances: {health_instances}")
     # 5. 挂载流量
     if len(health_instances) == len(ess_instance_ids):
         # 所有机器探活成功
@@ -88,6 +89,7 @@ async def ess_instance(ecs_client, alb_client, ess_count, max_workers, version,
         logging.info(f"Successfully added health_instance_ids {health_instance_ids} to server groups {longvideoapi_config.server_group_id_list}.")
 
         time.sleep(20)
+        logging.info(f"start update weight instances: {health_instance_ids} server groups: {longvideoapi_config.server_group_id_list}.")
         # add_weight_list = [(10, 5), (20, 5), (40, 5), (60, 5), (80, 5), (100, 5)]
         add_weight_list = [(10, 10), (20, 10), (40, 10), (60, 10), (80, 10), (100, 10)]
         utils.update_server_group_servers_attribute(alb_client,

+ 6 - 8
longvideoapi/utils.py

@@ -384,9 +384,9 @@ def add_servers_to_server_group(alb_client, server_group_ids, instance_ids, weig
         runtime = util_models.RuntimeOptions()
         try:
             alb_client.add_servers_to_server_group_with_options(request, runtime)
-            logging.info(f"Successfully added servers {instance_ids} to server group {server_group_id} with weight {weight}.")
+            logging.info(f"Successfully added instance_ids {instance_ids} to server group {server_group_id} with weight {weight}.")
         except Exception as e:
-            logging.error(f"Failed to add servers {instance_ids} to server group {server_group_id}: {str(e)}")
+            logging.error(f"Failed to add instance_ids {instance_ids} to server group {server_group_id}: {str(e)}")
             sys.exit()
 
 
@@ -415,9 +415,9 @@ def remove_servers_from_server_group(alb_client, server_group_id_list, instance_
         runtime = util_models.RuntimeOptions()
         try:
             alb_client.remove_servers_from_server_group_with_options(request, runtime)
-            logging.info(f"Successfully removed servers {servers} from server group {server_group_id}.")
+            logging.info(f"Successfully removed instance_ids {instance_ids} from server group {server_group_id}.")
         except Exception as e:
-            logging.error(f"Failed to remove servers {servers} from server group {server_group_id}: {str(e)}")
+            logging.error(f"Failed to remove instance_ids {instance_ids} from server group {server_group_id}: {str(e)}")
             sys.exit()
 
 
@@ -472,7 +472,7 @@ def update_server_group_server_weight(alb_client, server_group_id_list, instance
         # logging.info(f"servers = {servers}")
         runtime = util_models.RuntimeOptions()
         try:
-            logging.info(f"instance_id_list = {instance_id_list} request = {request}")
+            # logging.info(f"instance_id_list = {instance_id_list} request = {request}")
             alb_client.update_server_group_servers_attribute_with_options(request, runtime)
             logging.info(f"Successfully updated servers {instance_id_list} in group {server_group_id} to weight {weight}.")
         except Exception as e:
@@ -508,9 +508,7 @@ def check_server_group_status(alb_client, server_group_id_list):
             response = alb_client.list_server_groups_with_options(list_server_groups_request, runtime)
             count = 0
             if response.body:
-                map = UtilClient.to_map(response.body)
-                logging.info(f"response.body.servers {map}.")
-                server_groups = map.get("ServerGroups")
+                server_groups = UtilClient.to_map(response.body).get("ServerGroups")
                 if server_groups:
                     for server_group in server_groups:
                         if server_group.get("ServerGroupStatus") == "Available":