18960 探活改打 /healthz:恒 404 的那一格只能读成"未验证",服务真死了也不响
`service_down` 探活在 java 进程内跑,根路径没有路由 ⇒ 现网每轮一条
`WARN 服务探测未验证业务可用性 detail=HTTP 404`,跟价 API 挂了通知面上是 0 行
(10-07 那次 41 分钟整站宕机在通知表上就是 0 行的同族形状)。
不能选 `/batch/status`:它 `beat("vc")` 会让服务用自己的健康检查刷新采集机心跳,
正是 10-04 变体采集停摆 12 小时没被发现的那条路。`/healthz` 是 18960 专为探针加的,
不写心跳、不碰 Redis/MySQL——两台实测 `/`→404、`/healthz`→200 {"ok":true}。
两条新用例分别钉"拼出来的地址"与"`probeServices()` 真请求的路径":只钉前者的话
调用点改回去照样绿(第一版就是这么漏的,变异注入才暴露)。全类 10→12 例。
This commit is contained in:
+69
@@ -263,6 +263,75 @@ class NotificationScanSchedulerTest {
|
||||
verify(dispatch, never()).pushToAdmins(anyString(), anyString(), anyString(), anyString(), anyString(), any());
|
||||
}
|
||||
|
||||
/**
|
||||
* 跟价 API 的探针必须打在 /healthz 上。反例一就是本笔之前的 "/":18960 根路径没有路由,
|
||||
* 恒 404 ⇒ 那一格结构上永远只能读成「未验证」,服务真死了也不响。
|
||||
* 反例二是 /batch/status?task_id=watchdog:它会 beat("vc"),等于让服务用自己的健康检查
|
||||
* 刷新采集机心跳(2026-10-04 变体采集停摆 12 小时未被发现就是这个形状)。
|
||||
*/
|
||||
@Test
|
||||
void priceTrackProbeTargetsHealthzAndNeverTheHeartbeatEndpoint() {
|
||||
properties.setPriceTrackApiUrl("http://192.168.0.170:18960");
|
||||
assertThat(newScheduler().priceTrackProbeUrl())
|
||||
.isEqualTo("http://192.168.0.170:18960/healthz");
|
||||
|
||||
properties.setPriceTrackApiUrl("http://127.0.0.1:18960/");
|
||||
assertThat(newScheduler().priceTrackProbeUrl())
|
||||
.as("登记好的地址带尾斜杠,也不能拼出 //healthz")
|
||||
.isEqualTo("http://127.0.0.1:18960/healthz");
|
||||
|
||||
properties.setPriceTrackApiUrl("http://127.0.0.1:18960");
|
||||
assertThat(newScheduler().priceTrackProbeUrl())
|
||||
.doesNotEndWith(":18960")
|
||||
.doesNotContain("batch/status");
|
||||
}
|
||||
|
||||
/** 端到端一格:真打出去的请求路径必须就是 /healthz,只看拼好的字符串不算验过。 */
|
||||
@Test
|
||||
void healthzAnswersAliveAndProbeServicesActuallyRequestsThatPath() throws Exception {
|
||||
java.util.List<String> requested =
|
||||
java.util.Collections.synchronizedList(new java.util.ArrayList<>());
|
||||
com.sun.net.httpserver.HttpServer server = com.sun.net.httpserver.HttpServer.create(
|
||||
new java.net.InetSocketAddress("127.0.0.1", 0), 0);
|
||||
server.createContext("/healthz", exchange -> {
|
||||
requested.add(exchange.getRequestURI().getPath());
|
||||
byte[] body = "{\"ok\":true}".getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
exchange.close();
|
||||
});
|
||||
server.createContext("/", exchange -> {
|
||||
requested.add(exchange.getRequestURI().getPath());
|
||||
byte[] body = "no route".getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(404, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
exchange.close();
|
||||
});
|
||||
server.setExecutor(null);
|
||||
server.start();
|
||||
try {
|
||||
String base = "http://127.0.0.1:" + server.getAddress().getPort();
|
||||
properties.setPriceTrackApiUrl(base);
|
||||
properties.setBrandServiceUrl("");
|
||||
properties.setJikipProbeEnabled(false);
|
||||
NotificationScanScheduler scheduler = newScheduler();
|
||||
|
||||
assertThat(scheduler.probeHttpWithRetry(scheduler.priceTrackProbeUrl()).verdict())
|
||||
.isEqualTo(NotificationScanScheduler.ProbeVerdict.ALIVE);
|
||||
assertThat(scheduler.probeHttpWithRetry(base + "/").verdict())
|
||||
.as("本笔之前打的就是根路径,它只能判「未验证」")
|
||||
.isEqualTo(NotificationScanScheduler.ProbeVerdict.UNVERIFIED);
|
||||
|
||||
requested.clear();
|
||||
scheduler.probeServices();
|
||||
assertThat(requested)
|
||||
.as("探针实际请求的那一条路径——调用点被改回根路径时这一格必须红")
|
||||
.containsExactly("/healthz");
|
||||
} finally {
|
||||
server.stop(0);
|
||||
}
|
||||
}
|
||||
|
||||
private com.sun.net.httpserver.HttpServer startFixedStatusServer(
|
||||
int status, java.util.concurrent.atomic.AtomicInteger hits) throws java.io.IOException {
|
||||
com.sun.net.httpserver.HttpServer server =
|
||||
|
||||
Reference in New Issue
Block a user