109 lines
3.5 KiB
PowerShell
109 lines
3.5 KiB
PowerShell
# 日志管理全链路测试一键脚本:
|
||
# 1) 准备测试数据
|
||
# 2) 运行 E2E 主测试
|
||
# 3) 输出报告路径
|
||
param(
|
||
# 一键模式:本地全量测试
|
||
[switch]$Local,
|
||
# 一键模式:线上接口可控测试(自动跳过易受环境影响项)
|
||
[switch]$Online,
|
||
# 可选:指定本次测试唯一标识;不传则自动按时间生成
|
||
[string]$RunId = "",
|
||
# 可选:接口鉴权 token(本服务要求 Authorization 头直接传 token)
|
||
[string]$Token = "",
|
||
# 可选:logs 配置文件路径
|
||
[string]$Config = "d:/work/ops/logs/etc/logs_dev.yaml",
|
||
# 可选:logs 服务主机名(例如 127.0.0.1)
|
||
[string]$ApiHost = "127.0.0.1",
|
||
# 可选:syslog/trap 发送目标主机(默认跟随 ApiHost)
|
||
[string]$IngestHost = "",
|
||
# 可选:logs 完整 API 前缀(例如 https://ops-api.apinb.com/Logs/v1),优先级高于 ApiHost
|
||
[string]$BaseUrl = "",
|
||
# 可选:前端入口地址(用于入口联调检测)
|
||
[string]$FrontUrl = "http://127.0.0.1:5173/log-mgmt/entries"
|
||
,
|
||
# 可选:跳过前端入口检测(仅测后端链路)
|
||
[switch]$NoFront,
|
||
# 可选:跳过 resource-events 用例(线上未配置 hmac_secret 时可用)
|
||
[switch]$SkipResourceEvent,
|
||
# 可选:跳过 trap 接收用例(线上 trap 端口不可达时可用)
|
||
[switch]$SkipTrap
|
||
)
|
||
|
||
$ErrorActionPreference = "Stop"
|
||
|
||
# 便捷模式参数展开:
|
||
# -Online: 默认走线上 API,可控跳过前端/resource-events/trap
|
||
# -Local : 默认走本地全量
|
||
if ($Online -and $Local) {
|
||
throw "不能同时指定 -Online 和 -Local"
|
||
}
|
||
if ($Online) {
|
||
if ([string]::IsNullOrWhiteSpace($BaseUrl)) {
|
||
$BaseUrl = "https://ops-api.apinb.com/Logs/v1"
|
||
}
|
||
$NoFront = $true
|
||
$SkipResourceEvent = $true
|
||
$SkipTrap = $true
|
||
}
|
||
|
||
# 未传 RunId 时,按当前时间生成,便于报告文件唯一化
|
||
if ([string]::IsNullOrWhiteSpace($RunId)) {
|
||
$RunId = Get-Date -Format "yyyyMMddHHmmss"
|
||
}
|
||
|
||
# 先准备测试数据(清理+初始化)
|
||
python "d:/work/ops/logs/scripts/prepare_logs_e2e_data.py" --run-id $RunId --config $Config
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "prepare_logs_e2e_data.py 执行失败,退出码: $LASTEXITCODE"
|
||
}
|
||
|
||
# 组装主测试命令参数;按需跳过前端入口检查
|
||
$args = @(
|
||
"d:/work/ops/logs/scripts/run_logs_e2e.py",
|
||
"--run-id", $RunId,
|
||
"--config", $Config,
|
||
"--front-url", $FrontUrl
|
||
)
|
||
if (-not [string]::IsNullOrWhiteSpace($BaseUrl)) {
|
||
$args += @("--base-url", $BaseUrl)
|
||
} elseif ($ApiHost -match "^https?://") {
|
||
$normalized = $ApiHost.TrimEnd("/")
|
||
if ($normalized.EndsWith("/Logs/v1")) {
|
||
$args += @("--base-url", $normalized)
|
||
} else {
|
||
$args += @("--base-url", "$normalized/Logs/v1")
|
||
}
|
||
} else {
|
||
$args += @("--host", $ApiHost)
|
||
}
|
||
if (-not [string]::IsNullOrWhiteSpace($Token)) {
|
||
$args += @("--token", $Token)
|
||
}
|
||
if ($NoFront) {
|
||
$args += @("--skip-front")
|
||
}
|
||
if (-not [string]::IsNullOrWhiteSpace($IngestHost)) {
|
||
$ingestTarget = $IngestHost
|
||
if ($ingestTarget -match "^https?://") {
|
||
try {
|
||
$ingestTarget = ([System.Uri]$ingestTarget).Host
|
||
} catch {
|
||
throw "IngestHost 格式无效: $IngestHost"
|
||
}
|
||
}
|
||
$args += @("--ingest-host", $ingestTarget)
|
||
}
|
||
if ($SkipResourceEvent) {
|
||
$args += @("--skip-resource-event")
|
||
}
|
||
if ($SkipTrap) {
|
||
$args += @("--skip-trap")
|
||
}
|
||
python @args
|
||
if ($LASTEXITCODE -ne 0) {
|
||
throw "run_logs_e2e.py 执行失败,退出码: $LASTEXITCODE"
|
||
}
|
||
|
||
Write-Host "E2E报告: d:/work/ops/artifacts/logs_e2e_report_$RunId.md"
|