Skip to content

Commit 3c45062

Browse files
author
developerworks
committed
Migrate SupervisorConfig from confique derive to manual serde impl
- Replace confique-derived SupervisorConfig with manual serde Deserialize - Add src/config/policy.rs with full restart policy, budget, and severity config - Add src/config/audit.rs for audit channel configuration - Rewrite src/config/state.rs with dynamic child and topology state management - Migrate generate_supervisor binary to src/main.rs - Update example YAML configs (local, template, supervisor) with new fields - Sync architecture docs, manuals, and README with new config structure - Extend test coverage for configurable schema, template, and YAML loading
1 parent d8c3c63 commit 3c45062

51 files changed

Lines changed: 2456 additions & 329 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
[package]
22
name = "rust-tokio-supervisor"
3-
version = "0.1.2"
3+
version = "0.1.3"
44
edition = "2024"
55
rust-version = "1.88"
6+
autobins = false
67
description = "A Rust tokio supervisor with declarative task supervision, restart policy, shutdown coordination, and observability."
78
license = "MIT"
89
repository = "https://github.com/developerworks/rust-supervisor"
@@ -32,6 +33,10 @@ include = [
3233
name = "rust_supervisor"
3334
path = "src/lib.rs"
3435

36+
[[bin]]
37+
name = "rust-tokio-supervisor"
38+
path = "src/main.rs"
39+
3540
[dependencies]
3641
clap = { version = "4.6.1", features = ["derive"] }
3742
confique = { version = "0.4.0", features = ["yaml"] }

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Package name: `rust-tokio-supervisor`. Library crate name: `rust_supervisor`.
3838
- Load the primary YAML configuration from `examples/config/supervisor.yaml`.
3939
- Reuse `rust_supervisor::config::configurable::SupervisorConfig` for YAML loading, template generation, and JSON Schema generation.
4040
- Emit structured logs, tracing spans, metrics, audit events, event journal entries, and `RunSummary` diagnostics.
41-
- Enable target-side dashboard IPC through the optional `ipc` configuration section. The target process owns only local Unix domain socket IPC, snapshot generation, event conversion, command mapping, and shared JSON contracts.
41+
- Enable target-side dashboard IPC through the optional `dashboard` configuration section. The target process owns only local Unix domain socket IPC, snapshot generation, event conversion, command mapping, and shared JSON contracts.
4242

4343
## Platform Support
4444

@@ -117,7 +117,7 @@ The supervisor dashboard feature uses three directories.
117117
- [rust-supervisor-relay](https://github.com/developerworks/rust-supervisor-relay) at `~/rust-supervisor-relay`: relay server, dynamic registration, `wss://`, mTLS, session gating, and command audit.
118118
- [rust-supervisor-ui](https://github.com/developerworks/rust-supervisor-ui) at `~/rust-supervisor-ui`: Vue, shadcn-vue, Tailwind dashboard client.
119119

120-
The target process does not expose IPC to the network. It opens a local Unix domain socket only when `ipc.enabled=true`. A relay can read snapshots, but event and log subscriptions must be triggered by an established remote dashboard session.
120+
The target process does not expose IPC to the network. It opens a local Unix domain socket only when `dashboard.enabled=true`. A relay can read snapshots, but event and log subscriptions must be triggered by an established remote dashboard session.
121121

122122
![rust-supervisor dashboard screenshot](docs/screenshot.png)
123123

@@ -130,12 +130,23 @@ The official YAML files stay single-file by default:
130130
- `examples/config/supervisor.yaml`: complete runnable configuration.
131131
- `examples/config/supervisor.template.yaml`: complete single-file template.
132132

133+
The root configuration includes `backpressure` for observability subscriber queues:
134+
135+
```yaml
136+
backpressure:
137+
strategy: alert_and_block
138+
warn_threshold_pct: 80
139+
critical_threshold_pct: 95
140+
window_secs: 30
141+
audit_channel_capacity: 1024
142+
```
143+
133144
This crate does not bake in `x-tree-split`. Projects that want split configuration files can wrap or reuse `SupervisorConfig` in their own crate and decide their own tree split layout.
134145

135146
The optional dashboard IPC section has this shape:
136147

137148
```yaml
138-
ipc:
149+
dashboard:
139150
enabled: true
140151
target_id: payments-worker-a
141152
path: /run/rust-supervisor/payments-worker-a.sock
@@ -149,7 +160,7 @@ ipc:
149160
registration_heartbeat_interval_seconds: 15
150161
```
151162

152-
When `ipc.enabled=true`, `ipc.path` and `ipc.registration.relay_registration_path` must be absolute local paths. Registration uses dynamic registration. The relay configuration must not hard-code target lists.
163+
When `dashboard.enabled=true`, `dashboard.path` and `dashboard.registration.relay_registration_path` must be absolute local paths. Registration uses dynamic registration. The relay configuration must not hard-code target lists.
153164

154165
## Quick Start
155166

README.zh.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
-`examples/config/supervisor.yaml` 加载主 YAML(数据序列化格式) 配置.
3737
- 复用 `rust_supervisor::config::configurable::SupervisorConfig` 完成 YAML(数据序列化格式) 加载, template generation(模板生成) 和 JSON Schema(JSON 结构模式) 生成.
3838
- 发出 structured log(结构化日志), tracing span(追踪跨度), metrics(指标), audit event(审计事件), event journal entry(事件日志条目) 和 `RunSummary`(运行摘要) diagnostics(诊断信息).
39-
- 通过可选 `ipc` 配置启用 target-side dashboard IPC(目标侧看板进程间通信). target process(目标进程) 只拥有本机 Unix domain socket IPC(Unix 域套接字进程间通信), snapshot(快照) 生成, event conversion(事件转换), command mapping(命令映射) 和 shared JSON contract(共享 JSON 契约).
39+
- 通过可选 `dashboard` 配置启用 target-side dashboard IPC(目标侧看板进程间通信). target process(目标进程) 只拥有本机 Unix domain socket IPC(Unix 域套接字进程间通信), snapshot(快照) 生成, event conversion(事件转换), command mapping(命令映射) 和 shared JSON contract(共享 JSON 契约).
4040

4141
## 看板
4242

@@ -46,7 +46,7 @@ dashboard(看板) 功能固定拆成三个目录.
4646
- [rust-supervisor-relay](https://github.com/developerworks/rust-supervisor-relay) 位于 `~/rust-supervisor-relay`: relay server(中继服务), dynamic registration(动态注册), `wss://`, mTLS(双向传输层安全协议认证), session gating(会话门控) 和 command audit(命令审计).
4747
- [rust-supervisor-ui](https://github.com/developerworks/rust-supervisor-ui) 位于 `~/rust-supervisor-ui`: Vue(网页界面框架), shadcn-vue(组件库), Tailwind(样式框架) dashboard client(看板客户端).
4848

49-
target process(目标进程) 不把 IPC(进程间通信) 暴露到外网. 它只在 `ipc.enabled=true` 时打开本机 Unix domain socket(Unix 域套接字). relay(中继) 可以读取 snapshot(快照), 但是 event(事件) 和 log(日志) subscription(订阅) 必须由已认证 dashboard session(看板会话) 触发.
49+
target process(目标进程) 不把 IPC(进程间通信) 暴露到外网. 它只在 `dashboard.enabled=true` 时打开本机 Unix domain socket(Unix 域套接字). relay(中继) 可以读取 snapshot(快照), 但是 event(事件) 和 log(日志) subscription(订阅) 必须由已认证 dashboard session(看板会话) 触发.
5050

5151
![rust-supervisor dashboard(看板) screenshot(截图)](docs/screenshot.png)
5252

@@ -59,12 +59,23 @@ target process(目标进程) 不把 IPC(进程间通信) 暴露到外网. 它只
5959
- `examples/config/supervisor.yaml`: 完整可运行配置.
6060
- `examples/config/supervisor.template.yaml`: 完整单文件模板.
6161

62+
root configuration(根配置) 包含 `backpressure`(背压) 配置, 用来控制 observability subscriber(可观测性订阅者) 队列:
63+
64+
```yaml
65+
backpressure:
66+
strategy: alert_and_block
67+
warn_threshold_pct: 80
68+
critical_threshold_pct: 95
69+
window_secs: 30
70+
audit_channel_capacity: 1024
71+
```
72+
6273
本 crate(包) 不默认写入 `x-tree-split`(树形拆分扩展). 如果使用者项目需要拆分配置文件, 可以在自己的项目中包装或复用 `SupervisorConfig`(监督器配置), 并自行决定 tree split layout(树形拆分布局).
6374

6475
dashboard IPC(看板进程间通信) 的可选配置如下.
6576

6677
```yaml
67-
ipc:
78+
dashboard:
6879
enabled: true
6980
target_id: payments-worker-a
7081
path: /run/rust-supervisor/payments-worker-a.sock
@@ -78,7 +89,7 @@ ipc:
7889
registration_heartbeat_interval_seconds: 15
7990
```
8091

81-
`ipc.enabled=true` 时, `ipc.path` 和 `ipc.registration.relay_registration_path` 必须是 absolute path(绝对路径). registration(注册) 使用 dynamic registration(动态注册). relay config(中继配置) 不允许写死 target list(目标列表).
92+
当 `dashboard.enabled=true` 时, `dashboard.path` 和 `dashboard.registration.relay_registration_path` 必须是 absolute path(绝对路径). registration(注册) 使用 dynamic registration(动态注册). relay config(中继配置) 不允许写死 target list(目标列表).
8293

8394
## Quick Start(快速开始)
8495

docs/architecture.md

Lines changed: 84 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
│ │
1515
│ ┌─────────────────────┐ ┌─────────────────────┐ │
1616
│ │ Core Library │ │ Relay │ │
17-
│ │ (目标进程) │ (中继进程) │ │
17+
│ │ (目标进程) | │ (中继进程) │ │
1818
│ │ │ │ │ │
1919
│ │ Unix Domain Socket │◄─►│ Unix Domain Socket │ │
2020
│ │ /run/.../*.sock │ │ /run/.../relay.sock │ │
@@ -75,7 +75,7 @@
7575
YAML 配置
7676
7777
78-
rust-config-tree v0.1.9 加载
78+
rust-config-tree 加载
7979
8080
8181
ConfigState (不可变配置状态)
@@ -368,7 +368,7 @@ scripts/
368368

369369
- 所有可调配置通过 `rust-config-tree` v0.1.9 从 YAML 加载
370370
- `SupervisorConfig` 同时支持 `confique::Config`, `schemars::JsonSchema`, `serde::Serialize/Deserialize`
371-
- `ConfigState` 加载后不可变,派生 `SupervisorSpec`默认策略、关闭预算和可观测性配置
371+
- `ConfigState` 加载后不可变,派生 `SupervisorSpec`,默认策略,关闭预算,可观测性配置,背压配置,底层 policy(策略)配置,分组策略和子任务策略覆盖
372372
- 模块内部不得保存可调配置默认值
373373

374374
### 4.5 平台编译隔离
@@ -388,6 +388,10 @@ pub mod ipc;
388388
```yaml
389389
supervisor:
390390
strategy: OneForAll # 监督策略
391+
escalation_policy: escalate_to_parent # 默认升级策略
392+
dynamic_supervisor:
393+
enabled: true # 是否允许运行时增加子任务
394+
child_limit: 16 # 子任务总数上限
391395

392396
policy:
393397
child_restart_limit: 10 # 子任务窗口内最大重启次数
@@ -399,6 +403,27 @@ policy:
399403
jitter_ratio: 0.10 # 抖动比率
400404
heartbeat_interval_ms: 1000 # 心跳间隔
401405
stale_after_ms: 3000 # 心跳过期阈值
406+
restart_budget:
407+
window_secs: 60 # 重启预算窗口
408+
max_burst: 10 # 突发重启次数上限
409+
recovery_rate_per_sec: 0.50 # 令牌恢复速率
410+
failure_window:
411+
mode: time_sliding # 失败窗口模式
412+
window_secs: 60 # 时间滑动窗口
413+
max_count: 5 # 数量滑动窗口保留条数
414+
threshold: 5 # 失败阈值
415+
meltdown:
416+
child_max_restarts: 3 # 子任务熔断阈值
417+
child_window_secs: 10 # 子任务熔断窗口
418+
group_max_failures: 5 # 分组熔断阈值
419+
group_window_secs: 30 # 分组熔断窗口
420+
supervisor_max_failures: 10 # 监督器熔断阈值
421+
supervisor_window_secs: 60 # 监督器熔断窗口
422+
reset_after_secs: 120 # 稳定后重置窗口
423+
supervision_pipeline:
424+
journal_capacity: 100 # 策略流水线事件容量
425+
subscriber_capacity: 10 # 策略流水线订阅队列容量
426+
concurrent_restart_limit: 5 # 并发重启上限
402427

403428
shutdown:
404429
graceful_timeout_ms: 5000 # 优雅关闭超时
@@ -409,7 +434,61 @@ observability:
409434
metrics_enabled: true
410435
audit_enabled: true
411436

412-
ipc: # 可选,仅 Unix
437+
backpressure:
438+
strategy: alert_and_block # 背压策略
439+
warn_threshold_pct: 80 # 告警阈值
440+
critical_threshold_pct: 95 # 降级阈值
441+
window_secs: 30 # 评估窗口
442+
audit_channel_capacity: 1024 # 审计通道容量
443+
444+
groups:
445+
- name: core # 分组名称
446+
children:
447+
- api
448+
budget:
449+
window_secs: 60
450+
max_burst: 10
451+
recovery_rate_per_sec: 0.50
452+
- name: upstream
453+
children: []
454+
455+
group_strategies:
456+
- group: core
457+
strategy: OneForOne
458+
restart_limit:
459+
max_restarts: 5
460+
window_ms: 60000
461+
escalation_policy: quarantine_scope
462+
463+
group_dependencies:
464+
- from_group: core
465+
to_group: upstream
466+
propagation: Full
467+
468+
child_strategy_overrides:
469+
- child_id: api
470+
strategy: RestForOne
471+
restart_limit:
472+
max_restarts: 3
473+
window_ms: 30000
474+
escalation_policy: shutdown_tree
475+
476+
severity_defaults:
477+
- task_role: service
478+
severity: Critical
479+
480+
children:
481+
- name: api
482+
kind: supervisor
483+
criticality: critical
484+
tags:
485+
- core
486+
task_role: supervisor
487+
severity: Critical
488+
group: core
489+
restart_policy: transient
490+
491+
dashboard: # 可选,仅 Unix
413492
enabled: true
414493
target_id: payments-worker-a
415494
path: /run/rust-supervisor/payments-worker-a.sock
@@ -466,7 +545,7 @@ ipc: # 可选,仅 Unix
466545

467546
## 八、IPC 安全控制点
468547

469-
看板 IPC 配置了 9 项安全控制点 (C1-C9):
548+
看板 IPC 配置了 9 项安全控制点 (C1-C9). C7 审计持久化使用顶层 `audit` 配置, 不在 `dashboard.security_config` 中重复声明:
470549

471550
| 编号 | 控制点 | 说明 |
472551
| ---- | -------------------------- | ------------------------------- |

docs/security.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
## 三、IPC 安全控制点 (C1-C9)
1818

19-
看板 IPC 配置了 9 项安全控制点, 经 `IpcSecurityPipeline` 统一编排.
19+
看板 IPC 配置了 9 项安全控制点, 经 `IpcSecurityPipeline` 统一编排. C7 审计持久化不在 `dashboard.security_config` 中重复配置, 它使用顶层 `audit` 配置.
2020

2121
### 3.1 执行顺序
2222

@@ -130,7 +130,7 @@ SBOM 包含所有直接依赖和传递依赖, 每条依赖记录版本、许可
130130
### 6.1 IPC 配置 (Unix only)
131131

132132
```yaml
133-
ipc:
133+
dashboard:
134134
enabled: true
135135
path: /run/rust-supervisor/target.sock
136136
permissions: "0600" # 仅所有者可读写
@@ -153,7 +153,7 @@ ipc:
153153
| 限制 | 说明 | 缓解措施 |
154154
| ------------------ | --------------------------------------------- | ----------------------------------------------------- |
155155
| IPC 仅 Unix | Windows 等非 Unix 平台无法使用 dashboard | 通过 Unix relay 间接访问 |
156-
| 审计持久化默认内存 | `AuditBackend` 默认使用 ring buffer, 重启丢失 | 配置 `audit_persistence=file` 落盘 |
156+
| 审计持久化默认内存 | `AuditBackend` 默认使用 ring buffer, 重启丢失 | 配置 `audit.backend: file` 和 `audit.file_path` 落盘 |
157157
| 配置不支持热更新 | 修改安全配置需重启 supervisor | 使用配置管理工具自动化重启 |
158158
| 无内置 mTLS | target 侧不处理 mTLS | mTLS 由 relay 侧管理, 参考 rust-supervisor-relay 文档 |
159159

0 commit comments

Comments
 (0)