feat(unreachable-cooldown): 连接层不可达客户端级冷却,四家判定下沉共用

BACKLOG B24(窗长 300s 已拍板):连续 2 次连接未建立即对该 host 进
冷却窗,窗内调用零探针快速失败(归因文案与调用内短路逐字一致);到期
后下一条真实调用兼作探针,失败重进、成功恢复。isConnectFailure 四处
副本(BrandCheckClient/AppearancePatentLlmClient/SimilarAsinLlmClient/
TaskOwnerForwardService)下沉 common/retry 共用。三家客户端接入同一
冷却表(两个 LLM 客户端共用 ai.t8star.org 一格,16890 独立一格),
窗长可配(0=关闭退回调用内短路)。另修 CollectDataBrandBatchFilter
首批预算竞态(1ms 预算下 GC 停顿误切首批,照 BrandCheckClient 首轮
不掐契约补 start>0 守卫)。变异验证:冷却禁用 6 例判红;定向 47/47 绿。
This commit is contained in:
2026-10-23 20:58:32 +08:00
parent 6af19b51ba
commit 09dfb01f9c
22 changed files with 426 additions and 99 deletions
@@ -1,6 +1,7 @@
package com.nanri.aiimage.metrics;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nanri.aiimage.common.retry.UnreachableCooldown;
import com.nanri.aiimage.config.BrandCheckProperties;
import com.nanri.aiimage.config.SimilarAsinProperties;
import com.nanri.aiimage.config.ZiniaoProperties;
@@ -162,7 +163,7 @@ class ExternalCallMetricsRecorderTest {
SimilarAsinProperties props = llmProps();
SimilarAsinLlmClient client =
new SimilarAsinLlmClient(props, objectMapper, new ExternalCallMetricsRecorder(registry),
mock(UserSecretUsageService.class));
mock(UserSecretUsageService.class), new UnreachableCooldown());
String content = client.invokeChat("test-model", "system", "hello", "test-key");
@@ -181,7 +182,7 @@ class ExternalCallMetricsRecorderTest {
SimilarAsinProperties props = llmProps();
SimilarAsinLlmClient client =
new SimilarAsinLlmClient(props, objectMapper, new ExternalCallMetricsRecorder(registry),
mock(UserSecretUsageService.class));
mock(UserSecretUsageService.class), new UnreachableCooldown());
for (int i = 0; i < 3; i++) {
client.invokeChat("test-model", "system", "prompt-" + i, "test-key");
@@ -192,7 +193,7 @@ class ExternalCallMetricsRecorderTest {
"client", "llm", "result", "success"), "三次成功全部记录");
// 全部外部客户端(LLM / 品牌检查 / 紫鸟)在同一次批量中各自记录指标
BrandCheckClient brand = new BrandCheckClient(brandProps(), new ExternalCallMetricsRecorder(registry), stubbedUserSecrets());
BrandCheckClient brand = new BrandCheckClient(brandProps(), new ExternalCallMetricsRecorder(registry), stubbedUserSecrets(), new UnreachableCooldown());
brand.checkAll(List.of("Nintendo", "LEGO", "Sony"), "Terms", 7L);
ZiniaoClientImpl ziniao = new ZiniaoClientImpl(ziniaoProps(), objectMapper, new ExternalCallMetricsRecorder(registry));
assertEquals(1001L, ziniao.getCompanyIdByApiKey("test-api-key"));
@@ -210,7 +211,7 @@ class ExternalCallMetricsRecorderTest {
@Test
void test_task_078_payload_metrics_normal_repeated_operation_is_idempotent() throws Exception {
BrandCheckProperties props = brandProps();
BrandCheckClient client = new BrandCheckClient(props, new ExternalCallMetricsRecorder(registry), stubbedUserSecrets());
BrandCheckClient client = new BrandCheckClient(props, new ExternalCallMetricsRecorder(registry), stubbedUserSecrets(), new UnreachableCooldown());
client.check("Nintendo", "Terms", 7L);
client.check("Nintendo", "Terms", 7L);
@@ -227,7 +228,7 @@ class ExternalCallMetricsRecorderTest {
@Test
void test_task_078_payload_metrics_boundary_empty_input() throws Exception {
BrandCheckProperties props = brandProps();
BrandCheckClient client = new BrandCheckClient(props, new ExternalCallMetricsRecorder(registry), stubbedUserSecrets());
BrandCheckClient client = new BrandCheckClient(props, new ExternalCallMetricsRecorder(registry), stubbedUserSecrets(), new UnreachableCooldown());
BrandCheckClient.BrandCheckBatchResult result = client.checkAll(List.of(), "Terms", 7L);
@@ -242,7 +243,7 @@ class ExternalCallMetricsRecorderTest {
@Test
void test_task_078_payload_metrics_boundary_single_item() throws Exception {
BrandCheckProperties props = brandProps();
BrandCheckClient client = new BrandCheckClient(props, new ExternalCallMetricsRecorder(registry), stubbedUserSecrets());
BrandCheckClient client = new BrandCheckClient(props, new ExternalCallMetricsRecorder(registry), stubbedUserSecrets(), new UnreachableCooldown());
BrandCheckClient.BrandCheckResponse response = client.check("LEGO", "Terms", 7L);
@@ -264,7 +265,7 @@ class ExternalCallMetricsRecorderTest {
int index = i;
pool.submit(() -> {
SimilarAsinLlmClient client = new SimilarAsinLlmClient(props, objectMapper, recorder,
mock(UserSecretUsageService.class));
mock(UserSecretUsageService.class), new UnreachableCooldown());
try {
client.invokeChat("test-model", "system", "prompt-" + index, "test-key");
} catch (Exception ignored) {
@@ -297,7 +298,7 @@ class ExternalCallMetricsRecorderTest {
@Test
void test_task_078_payload_metrics_invalid_input_rejected() throws Exception {
BrandCheckProperties props = brandProps();
BrandCheckClient client = new BrandCheckClient(props, new ExternalCallMetricsRecorder(registry), stubbedUserSecrets());
BrandCheckClient client = new BrandCheckClient(props, new ExternalCallMetricsRecorder(registry), stubbedUserSecrets(), new UnreachableCooldown());
BrandCheckClient.BrandCheckBatchResult result = client.checkAll(null, "Terms", 7L);
@@ -315,7 +316,7 @@ class ExternalCallMetricsRecorderTest {
SimilarAsinProperties props = llmProps();
SimilarAsinLlmClient client =
new SimilarAsinLlmClient(props, objectMapper, recorder,
mock(UserSecretUsageService.class));
mock(UserSecretUsageService.class), new UnreachableCooldown());
// 第一次调用走 500 失败路径,第二次调用恢复成功:错误可恢复
llmFailNext.set(true);