feat: 引入 aether-runtime/cache/data/http/testkit 基础 crate,完善并发门控与审计系统

新增 crate:
- aether-runtime: 服务运行时基础设施(并发门控、分布式并发、指标、队列、优雅关闭、tracing)
- aether-cache: 通用 TTL 缓存与命名空间抽象
- aether-data: 数据访问层(PostgreSQL/Redis 后端、repository 模式)
- aether-http: HTTP 客户端封装(重试、配置)
- aether-testkit: 集成测试工具集(gateway/executor/hub/proxy fixture、等待、负载测试)

gateway 扩展:
- 引入 audit 模块(shadow 执行审计、决策链路追踪、请求审计 bundle)
- 引入 cache 模块(AuthContext 缓存、direct-plan bypass 缓存)
- 引入 data 模块(auth/candidates/config/usage/video_tasks 数据访问)
- 集成 ConcurrencyGate/DistributedConcurrencyGate 请求门控
- 新增本地 auth 拒绝、过载响应构建器
- 补充 control/auth_cache/video/concurrency 集成测试

aether-proxy 扩展:
- AppState 集成 stream_gate / distributed_stream_gate 并发门控
- 新增 ProxyAdmissionError 及准入拒绝流程
- stream_handler 补充门控饱和/不可用场景测试
- 配置与注册客户端逻辑完善

aether-hub 扩展:
- main.rs 引入运行时初始化、指标端点、健康检查
- local_relay 重构为 lib.rs 暴露公共接口
This commit is contained in:
fawney19
2026-03-24 15:12:56 +08:00
parent eaf8475f9e
commit b5a0070023
157 changed files with 22097 additions and 448 deletions
+76
View File
@@ -0,0 +1,76 @@
use aether_gateway::{build_router_with_state, AppState};
use aether_runtime::DistributedConcurrencyGate;
use crate::server::SpawnedServer;
#[derive(Debug, Clone)]
pub struct GatewayHarnessConfig {
pub upstream_base_url: String,
pub control_base_url: Option<String>,
pub executor_base_url: Option<String>,
pub max_in_flight_requests: Option<usize>,
pub distributed_request_gate: Option<DistributedConcurrencyGate>,
}
impl GatewayHarnessConfig {
pub fn new(upstream_base_url: impl Into<String>) -> Self {
Self {
upstream_base_url: upstream_base_url.into(),
control_base_url: None,
executor_base_url: None,
max_in_flight_requests: None,
distributed_request_gate: None,
}
}
}
#[derive(Debug)]
pub struct GatewayHarness {
server: SpawnedServer,
}
impl GatewayHarness {
pub async fn start(config: GatewayHarnessConfig) -> Result<Self, String> {
Self::start_with_server(config, None).await
}
pub async fn start_on_port(config: GatewayHarnessConfig, port: u16) -> Result<Self, String> {
Self::start_with_server(config, Some(port)).await
}
async fn start_with_server(
config: GatewayHarnessConfig,
port: Option<u16>,
) -> Result<Self, String> {
let mut state = AppState::new_with_executor(
config.upstream_base_url,
config.control_base_url,
config.executor_base_url,
)
.map_err(|err| format!("failed to build gateway harness state: {err}"))?;
if let Some(limit) = config.max_in_flight_requests {
state = state.with_request_concurrency_limit(limit);
}
if let Some(gate) = config.distributed_request_gate {
state = state.with_distributed_request_concurrency_gate(gate);
}
let router = build_router_with_state(state);
let server = match port {
Some(port) => SpawnedServer::start_on_port(port, router)
.await
.map_err(|err| format!("failed to start gateway harness: {err}"))?,
None => SpawnedServer::start(router)
.await
.map_err(|err| format!("failed to start gateway harness: {err}"))?,
};
Ok(Self { server })
}
pub fn base_url(&self) -> &str {
self.server.base_url()
}
pub fn port(&self) -> u16 {
self.server.port()
}
}