Skip to content

Commit

Permalink
optimization: Agent 安装日志展示优化 (closed #1198)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuoZhuoCrayon committed Oct 31, 2022
1 parent f79be55 commit a00c0e1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 11 additions & 3 deletions apps/backend/components/collections/agent_new/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from pipeline.core.flow import Service, StaticIntervalGenerator

from .. import core
from ..base import LogLevel
from ..common import remote
from . import base

Expand Down Expand Up @@ -537,10 +538,10 @@ def handle_report_data(self, sub_inst_id: int, success_callback_step: str) -> Di
for data in report_data:
# redis取出为bytes类型,进行解码
data = json.loads(data.decode())
step = data["step"]
tag = data.get("prefix") or "[script]"
log = f"{tag} {data['log']}"
log = f"{tag} [{step}] {data['log']}"
status = data["status"]
step = data["step"]
if status == "FAILED":
error_log = log
is_finished = True
Expand All @@ -553,12 +554,19 @@ def handle_report_data(self, sub_inst_id: int, success_callback_step: str) -> Di
elif step == "report_os_version":
os_version = data["log"]
elif step in ["report_healthz"]:
logs.append(data.get("log"))
# 考虑解析 healthz 输出,进行友好提示
pass
# 只要匹配到成功返回步骤完成,则认为是执行完成了
if step == success_callback_step and status == "DONE":
is_finished = True
# 并非每次调度都能取到日志,所以仅在非空情况下打印日志
if logs:
# 多行日志批量打印时,非起始日志需要补充时间等前缀,提升美观度
logs = [logs[0]] + [
self.log_maker_class.get_log_content(level=LogLevel.INFO, content=log)
for log in logs[1:]
if len(log.strip())
]
self.log_info(sub_inst_ids=sub_inst_id, log_content="\n".join(logs))
if error_log:
self.move_insts_to_failed([sub_inst_id], log_content=error_log)
Expand Down
3 changes: 3 additions & 0 deletions dev_log/2.2.31/crayon_202210311003.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
optimization:
- "Agent 安装日志展示优化 (closed #1198)"

0 comments on commit a00c0e1

Please sign in to comment.