实现 type: ping checker,通过 Bun.spawn 调用系统 ping 命令,自行实现跨平台 输出解析器(Linux/macOS/Windows 含中文 locale),支持 alive、丢包率、延迟、 耗时等 expect 断言,复用现有 checker 架构零外部依赖。 包含完整的类型定义、TypeBox schema、语义校验、命令构建、解析、断言、执行、 注册、配置加载测试,以及 probe-config.schema.json 更新和文档更新。 审查修复:提取 buildPingCommand 为独立纯函数并补充跨平台单测,补充 maxDurationMs/maxAvgLatencyMs 类型非法和空字符串 host 边界测试用例。 变更已归档,delta specs 已同步至 main specs。
190 lines
4.0 KiB
YAML
190 lines
4.0 KiB
YAML
# yaml-language-server: $schema=./probe-config.schema.json
|
|
|
|
server:
|
|
host: "127.0.0.1"
|
|
port: 3000
|
|
dataDir: "/tmp/probes_data"
|
|
|
|
runtime:
|
|
maxConcurrentChecks: 20
|
|
|
|
defaults:
|
|
interval: "30s"
|
|
timeout: "10s"
|
|
http:
|
|
maxBodyBytes: "10MB"
|
|
cmd:
|
|
maxOutputBytes: "1MB"
|
|
|
|
variables:
|
|
env_name: "演示"
|
|
httpbin_base: "https://httpbin.org"
|
|
api_token: "Bearer demo-token"
|
|
sqlite_url: "sqlite://:memory:"
|
|
|
|
targets:
|
|
# ========== HTTP targets ==========
|
|
|
|
- id: "baidu-home"
|
|
name: "Baidu 首页可用"
|
|
description: "监控百度首页的可用性和响应时间"
|
|
type: http
|
|
group: "搜索引擎"
|
|
http:
|
|
url: "https://www.baidu.com"
|
|
expect:
|
|
status: [200]
|
|
maxDurationMs: 5000
|
|
|
|
- id: "httpbin-json"
|
|
name: "${env_name} JSON API — 完整流水线"
|
|
type: http
|
|
group: "后端服务"
|
|
interval: "1m"
|
|
timeout: "15s"
|
|
http:
|
|
url: "${httpbin_base}/json"
|
|
headers:
|
|
Accept: "application/json"
|
|
Authorization: "${api_token|Bearer fallback-token}"
|
|
expect:
|
|
headers:
|
|
Content-Type:
|
|
contains: "application/json"
|
|
maxDurationMs: 8000
|
|
body:
|
|
- json:
|
|
path: "$.slideshow.title"
|
|
equals: "Sample Slide Show"
|
|
- json:
|
|
path: "$.slideshow.slides[0].title"
|
|
contains: "Wake"
|
|
- regex: '"title"'
|
|
|
|
- id: "httpbin-post"
|
|
name: "POST 接口测试"
|
|
type: http
|
|
http:
|
|
url: "${httpbin_base}/post"
|
|
method: POST
|
|
headers:
|
|
Content-Type: "application/json"
|
|
body: '{"action":"check","version":1}'
|
|
expect:
|
|
status: [200]
|
|
body:
|
|
- json:
|
|
path: "$.json.action"
|
|
equals: "check"
|
|
- json:
|
|
path: "$.json.version"
|
|
gte: 1
|
|
|
|
# ========== Cmd targets ==========
|
|
|
|
- id: "bun-version"
|
|
name: "Bun 版本输出匹配"
|
|
type: cmd
|
|
group: "系统检查"
|
|
cmd:
|
|
exec: "bun"
|
|
args: ["--version"]
|
|
expect:
|
|
exitCode: [0]
|
|
stdout:
|
|
- match: "^\\d+\\.\\d+\\.\\d+"
|
|
|
|
- id: "bun-stdout-rules"
|
|
name: "多规则 stdout 顺序校验"
|
|
type: cmd
|
|
interval: "5m"
|
|
cmd:
|
|
exec: "bun"
|
|
args: ["-e", "console.log('version: 2.0.1, status: healthy')"]
|
|
expect:
|
|
stdout:
|
|
- contains: "version:"
|
|
- match: "\\d+\\.\\d+\\.\\d+"
|
|
- contains: "healthy"
|
|
|
|
- id: "bun-stderr"
|
|
name: "stderr 内容检查"
|
|
type: cmd
|
|
cmd:
|
|
exec: "bun"
|
|
args: ["-e", "process.stderr.write('simulated error\\n'); process.exit(1)"]
|
|
expect:
|
|
exitCode: [1]
|
|
stderr:
|
|
- contains: "simulated error"
|
|
|
|
# ========== DB targets ==========
|
|
|
|
- id: "sqlite-connect"
|
|
name: "SQLite 内存数据库连接测试"
|
|
type: db
|
|
group: "数据库"
|
|
db:
|
|
url: "${sqlite_url}"
|
|
expect:
|
|
maxDurationMs: 1000
|
|
|
|
- id: "sqlite-query"
|
|
name: "SQLite 内存数据库多列结果校验"
|
|
type: db
|
|
db:
|
|
url: "${sqlite_url}"
|
|
query: "SELECT 1 as id, 'Alice' as name, 'engineer' as role"
|
|
expect:
|
|
rowCount:
|
|
equals: 1
|
|
rows:
|
|
- id:
|
|
gte: 1
|
|
name:
|
|
exists: true
|
|
role:
|
|
contains: "engineer"
|
|
|
|
# ========== TCP targets ==========
|
|
|
|
- id: "redis-port"
|
|
name: "Redis 端口可达"
|
|
type: tcp
|
|
group: "基础设施"
|
|
tcp:
|
|
host: "127.0.0.1"
|
|
port: 6379
|
|
expect:
|
|
maxDurationMs: 3000
|
|
|
|
- id: "smtp-banner"
|
|
name: "SMTP Banner 探测"
|
|
type: tcp
|
|
group: "基础设施"
|
|
tcp:
|
|
host: "127.0.0.1"
|
|
port: 25
|
|
readBanner: true
|
|
bannerReadTimeout: 3000
|
|
expect:
|
|
banner:
|
|
contains: "ESMTP"
|
|
|
|
# ========== Ping targets ==========
|
|
|
|
- id: "gateway-ping"
|
|
name: "网关 ICMP 可达"
|
|
type: ping
|
|
group: "基础设施"
|
|
ping:
|
|
host: "127.0.0.1"
|
|
count: 3
|
|
packetSize: 56
|
|
expect:
|
|
alive: true
|
|
maxPacketLoss: 10
|
|
maxAvgLatencyMs: 100
|
|
maxMaxLatencyMs: 300
|
|
maxDurationMs: 5000
|