mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 17:30:23 +08:00
feat(stats,rules): api_key 用量统计(total_tokens 字段 + 回填)与 body rules 新增 append/insert/regex_replace/name_style 操作
- 新增迁移 20260422120000_add_api_key_usage_stats.sql,为 api_keys 表添加 total_tokens 列 - 新增回填 20260422120000_backfill_api_key_usage_stats.sql,按历史 usage 重建 api_key 维度汇总 - 在 UsageWriteRepository trait 中添加 rebuild_api_key_usage_stats,补齐 SQL/内存实现及上层调用链 - 内存实现中新增 apply_usage_stats_delta,支持增量更新 api_key 统计快照 - dev.sh:改进临时日志目录管理,并在网关异常退出时输出错误提示 - frontend EndpointFormDialog:将 append 操作从 insert 分支拆分,提供独立 path/value 输入 UI - rules.rs:扩展 body rules 支持,新增 append/insert/regex_replace/name_style 操作及 WildcardSlice 路径段
This commit is contained in:
@@ -722,6 +722,14 @@ impl GatewayDataState {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn rebuild_api_key_usage_stats(&self) -> Result<u64, DataLayerError> {
|
||||
match &self.usage_writer {
|
||||
Some(repository) => repository.rebuild_api_key_usage_stats().await,
|
||||
None => Ok(0),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn rebuild_provider_api_key_usage_stats(&self) -> Result<u64, DataLayerError> {
|
||||
match &self.usage_writer {
|
||||
|
||||
@@ -3,6 +3,14 @@ use aether_data_contracts::repository::{candidates, usage};
|
||||
use usage::{StoredUsageDailySummary, UsageDailyHeatmapQuery};
|
||||
|
||||
impl AppState {
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn rebuild_api_key_usage_stats(&self) -> Result<u64, GatewayError> {
|
||||
self.data
|
||||
.rebuild_api_key_usage_stats()
|
||||
.await
|
||||
.map_err(|err| GatewayError::Internal(err.to_string()))
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn rebuild_provider_api_key_usage_stats(&self) -> Result<u64, GatewayError> {
|
||||
self.data
|
||||
|
||||
Reference in New Issue
Block a user