feat(cost-guard): 代理/LLM 损耗监控与账号级任务暂停

- 每分钟扫描用量增量/日累计,异常置暂停闸并推站内通知
- 品牌补测、跟价派发、外观激活、品牌检测与两个 LLM 客户端统一接闸
- 同一代理/LLM 密钥被 3 个以上账号共用时给出用户提示
- 品牌检测出口拒绝批级熔断;LLM 同 key 共享并发/间隔/429 惩罚
- V170 新增 biz_user_task_guard
This commit is contained in:
2026-10-24 10:50:20 +08:00
parent 052f2bd4a5
commit 9c4905c94e
32 changed files with 1625 additions and 5 deletions
@@ -0,0 +1,38 @@
package com.nanri.aiimage.common.retry;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.springframework.web.client.HttpClientErrorException;
import static org.assertj.core.api.Assertions.assertThat;
class LlmKeyGateTest {
@AfterEach
void tearDown() {
LlmKeyGate.resetForTests();
}
@Test
void recognizesRateLimitThroughExceptionChain() {
assertThat(LlmKeyGate.isRateLimited(
new HttpClientErrorException(HttpStatus.TOO_MANY_REQUESTS))).isTrue();
assertThat(LlmKeyGate.isRateLimited(
new IllegalStateException("wrapped",
new HttpClientErrorException(HttpStatus.TOO_MANY_REQUESTS)))).isTrue();
assertThat(LlmKeyGate.isRateLimited(
new IllegalStateException("read timeout"))).isFalse();
}
@Test
void permitIsReleasedAfterUse() {
try (LlmKeyGate.Permit ignored = LlmKeyGate.acquire("shared-key")) {
assertThat(ignored).isNotNull();
}
// 能再次拿到同一个 key 的许可,说明 close 归还了信号量
try (LlmKeyGate.Permit ignored = LlmKeyGate.acquire("shared-key")) {
assertThat(ignored).isNotNull();
}
}
}