#!/usr/bin/env bash
set -euo pipefail

# 获取fluent-bit-host02容器名称
container_name="logging-mvp-fluent-bit-host02-1"

# 检查容器是否存在并运行
if ! docker ps | grep -q "$container_name"; then
    echo "[ERROR] Fluent Bit容器 $container_name 未运行"
    exit 1
fi

# 创建日志目录
docker exec "$container_name" mkdir -p /logs/train /logs/infer

# 写入训练日志 (host02)
docker exec "$container_name" sh -c "printf '%s INFO [host02] training step=1 loss=1.45 model=gpt\n' \"\$(date '+%F %T')\" >> /logs/train/train-demo.log"
docker exec "$container_name" sh -c "printf '%s INFO [host02] training step=2 loss=1.38 model=gpt\n' \"\$(date '+%F %T')\" >> /logs/train/train-demo.log"
docker exec "$container_name" sh -c "printf '%s INFO [host02] training step=3 loss=1.32 model=gpt\n' \"\$(date '+%F %T')\" >> /logs/train/train-demo.log"

# 写入推理日志 (host02)  
docker exec "$container_name" sh -c "printf '%s WARN [host02] inference slow on batch=5 latency=2.3s\n' \"\$(date '+%F %T')\" >> /logs/infer/infer-demo.log"
docker exec "$container_name" sh -c "printf '%s INFO [host02] inference completed batch=6 latency=0.8s\n' \"\$(date '+%F %T')\" >> /logs/infer/infer-demo.log"

echo "[OK] 已通过docker exec写入测试日志到 host02 容器内："
echo " - /logs/train/train-demo.log"
echo " - /logs/infer/infer-demo.log"