feat(密钥管理): 代理配置后台明文展示 + 按次统计各密钥调用损耗

- 后台密钥管理「代理设置」列改为完整明文展示(含账号密码),便于运维核对;
  新增 full 字段仅对代理模块下发,密钥两列保持脱敏
- 新增 biz_user_secret_usage_daily(V117):用户 × 模块 × 天累计真实对外请求次数
- 计次口径:LLM 每次真实 HTTP 请求(含重试)计 1 次;代理每次成功提取计 1 次
- LLM 埋点走 SecretUsageContext 上下文(批次外设置、线程池内快照恢复)
- 新增内部上报接口 /api/internal/user-secret-usage(X-Internal-Token)
- 新增后台页「密钥用量统计」:日期范围 + 用户名 + 分组筛选,含范围内汇总
This commit is contained in:
2026-09-13 21:56:46 +08:00
parent 178901b03e
commit 41674d1adb
35 changed files with 1545 additions and 76 deletions
@@ -34,6 +34,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.nanri.aiimage.modules.usersecret.service.UserSecretUsageService;
import static org.mockito.Mockito.mock;
/**
* Task 78:为所有外部调用(LLM / 品牌检查 / 紫鸟)统一增加耗时、重试、
@@ -159,7 +161,8 @@ class ExternalCallMetricsRecorderTest {
void test_task_078_payload_metrics_normal_default_path() throws Exception {
SimilarAsinProperties props = llmProps();
SimilarAsinLlmClient client =
new SimilarAsinLlmClient(props, objectMapper, new ExternalCallMetricsRecorder(registry));
new SimilarAsinLlmClient(props, objectMapper, new ExternalCallMetricsRecorder(registry),
mock(UserSecretUsageService.class));
String content = client.invokeChat("test-model", "system", "hello", "test-key");
@@ -177,7 +180,8 @@ class ExternalCallMetricsRecorderTest {
void test_task_078_payload_metrics_normal_multiple_items() throws Exception {
SimilarAsinProperties props = llmProps();
SimilarAsinLlmClient client =
new SimilarAsinLlmClient(props, objectMapper, new ExternalCallMetricsRecorder(registry));
new SimilarAsinLlmClient(props, objectMapper, new ExternalCallMetricsRecorder(registry),
mock(UserSecretUsageService.class));
for (int i = 0; i < 3; i++) {
client.invokeChat("test-model", "system", "prompt-" + i, "test-key");
@@ -259,7 +263,8 @@ class ExternalCallMetricsRecorderTest {
for (int i = 0; i < 20; i++) {
int index = i;
pool.submit(() -> {
SimilarAsinLlmClient client = new SimilarAsinLlmClient(props, objectMapper, recorder);
SimilarAsinLlmClient client = new SimilarAsinLlmClient(props, objectMapper, recorder,
mock(UserSecretUsageService.class));
try {
client.invokeChat("test-model", "system", "prompt-" + index, "test-key");
} catch (Exception ignored) {
@@ -309,7 +314,8 @@ class ExternalCallMetricsRecorderTest {
ExternalCallMetricsRecorder recorder = new ExternalCallMetricsRecorder(registry);
SimilarAsinProperties props = llmProps();
SimilarAsinLlmClient client =
new SimilarAsinLlmClient(props, objectMapper, recorder);
new SimilarAsinLlmClient(props, objectMapper, recorder,
mock(UserSecretUsageService.class));
// 第一次调用走 500 失败路径,第二次调用恢复成功:错误可恢复
llmFailNext.set(true);