tools: spark_submit 记录拼装命令到 per-tool log

之前 d.Logger.Debug("spark_submit.built", "argv", cmd) 在 spark-submit
执行前 log 一次, 但 LOG_LEVEL=info 默认看不到, 拼装结果只活在
运行时 stack. 现在把 binary + argv 合并进 callLog.WithResult 写入
per-tool 文件 (data/logs/tools/<ts>_spark_submit_<id>.log), 每次
执行都在 tail -f 的现场能 grep 出来.

   tail -f data/logs/tools/*.log | grep -A1 '"argv"'
   -> 看每次实际传给 spark-submit 的 argv, 含 script_path 在最后

保留 Debug 调用: verbose 模式下用 base.Logger 直接看到完整 argv 跟
cluster_id, 不依赖 file tail.

两份记录 (Debug + WithResult) 字段一致, 都是 binary + argv, 排查
spark-submit 行为时可以交叉对照.

测试:
  - 已有 TestSparkSubmit_StructuredCommand 跑通, argv 字段被
    JSON marshal 进 resultRaw, 不需要新增测试
  - go test ./... 全绿

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-07-14 10:51:03 +08:00
co-authored by Claude
parent 157848d87a
commit 4af166ea48
+4
View File
@@ -176,6 +176,8 @@ func (d *Deps) SparkSubmitHandler(ctx context.Context, req mcp.CallToolRequest)
// Even on error, result carries ExitCode/Stderr for the LLM. // Even on error, result carries ExitCode/Stderr for the LLM.
if result != nil { if result != nil {
callLog.WithResult(map[string]any{ callLog.WithResult(map[string]any{
"binary": binary,
"argv": cmd,
"app_id": result.AppID, "app_id": result.AppID,
"exit_code": result.ExitCode, "exit_code": result.ExitCode,
"duration_ms": result.DurationMS, "duration_ms": result.DurationMS,
@@ -193,6 +195,8 @@ func (d *Deps) SparkSubmitHandler(ctx context.Context, req mcp.CallToolRequest)
} }
callLog.WithResult(map[string]any{ callLog.WithResult(map[string]any{
"binary": binary,
"argv": cmd,
"app_id": result.AppID, "app_id": result.AppID,
"exit_code": result.ExitCode, "exit_code": result.ExitCode,
"duration_ms": result.DurationMS, "duration_ms": result.DurationMS,