Commit 502c0997 authored by zhouwei's avatar zhouwei

调整告警时间

parent 95f38259
......@@ -33,8 +33,9 @@ public class FailoverGatewayFilterFactory extends AbstractGatewayFilterFactory<F
private final WebClient.Builder webClientBuilder;
private final TokenRouteMappingService tokenRouteMappingService;
// 添加错误统计
private static final int WINDOW_SIZE_SECONDS = 10*60; // 1分钟窗口
private static final int WINDOW_SIZE_SECONDS = 100; // 1分钟窗口
private static final double ERROR_THRESHOLD = 0.5; // 75%错误率阈值
private static Long lastAlarmTime = System.currentTimeMillis();
@Autowired
AlertService alertService;
private final Map<String, CircularQueue> errorStatsMap = new ConcurrentHashMap<>();
......@@ -113,7 +114,7 @@ public class FailoverGatewayFilterFactory extends AbstractGatewayFilterFactory<F
Long lastAlarmTime = alarmSentMap.get(primaryUrl);
// 如果从未发送过告警,或者距离上次告警已经超过冷却时间
if (lastAlarmTime == null || (currentTime - lastAlarmTime) > WINDOW_SIZE_SECONDS*1000) {
if (lastAlarmTime == null || (currentTime - lastAlarmTime) > 20*60*1000) {
String alarmMessage = String.format(
"Service degradation detected: %s has high error rate (%.2f%%), switching to fallback service",
primaryUrl, errorRate * 100);
......@@ -234,9 +235,8 @@ public class FailoverGatewayFilterFactory extends AbstractGatewayFilterFactory<F
ServerHttpRequest request = exchange.getRequest();
String fullUrl = baseUrl + (baseUrl.endsWith("/") ? uri.substring(1) : uri);
log.info("Trying request to: {}", fullUrl);
log.info("Using cached request body: {}", cachedBody);
log.info("Starting {} request to: {}", isSourceRequest ? "source" : "target", fullUrl);
long startTime = System.currentTimeMillis();
WebClient.RequestBodySpec requestBodySpec = webClientBuilder.build()
.method(request.getMethod())
.uri(fullUrl + (request.getQueryParams().isEmpty() ? "" :
......@@ -261,7 +261,16 @@ public class FailoverGatewayFilterFactory extends AbstractGatewayFilterFactory<F
return requestBodySpec
.exchange()
.flatMap(clientResponse -> handleResponse(exchange, clientResponse, isSourceRequest, errorStats));
.flatMap(clientResponse -> handleResponse(exchange, clientResponse, isSourceRequest, errorStats))
.doFinally(signalType -> {
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
log.info("{} request completed: {} - took {}ms, signal: {}",
isSourceRequest ? "Source" : "Target",
fullUrl,
duration,
signalType);
});
}
private Mono<Void> handleResponse(ServerWebExchange exchange,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment