add limit rate filter debug log. (#437)

Co-authored-by: 许路路 <499319126@qq.com>
pull/444/head
Haotian Zhang 2 years ago committed by GitHub
parent 74f4433e75
commit fbd88840ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,3 +2,4 @@
--- ---
- [Bugfix: optimize ratelimit actuator](https://github.com/Tencent/spring-cloud-tencent/pull/420) - [Bugfix: optimize ratelimit actuator](https://github.com/Tencent/spring-cloud-tencent/pull/420)
- [Feature: add rate limit filter debug log](https://github.com/Tencent/spring-cloud-tencent/pull/437)

@ -114,6 +114,7 @@ public class QuotaCheckReactiveFilter implements WebFilter, Ordered {
} }
// Unirate // Unirate
if (quotaResponse.getCode() == QuotaResultCode.QuotaResultOk && quotaResponse.getWaitMs() > 0) { if (quotaResponse.getCode() == QuotaResultCode.QuotaResultOk && quotaResponse.getWaitMs() > 0) {
LOG.debug("The request of [{}] will waiting for {}ms.", path, quotaResponse.getWaitMs());
return Mono.delay(Duration.ofMillis(quotaResponse.getWaitMs())).flatMap(e -> chain.filter(exchange)); return Mono.delay(Duration.ofMillis(quotaResponse.getWaitMs())).flatMap(e -> chain.filter(exchange));
} }
} }

@ -58,11 +58,13 @@ import static com.tencent.cloud.polaris.ratelimit.constant.RateLimitConstant.LAB
@Order(RateLimitConstant.FILTER_ORDER) @Order(RateLimitConstant.FILTER_ORDER)
public class QuotaCheckServletFilter extends OncePerRequestFilter { public class QuotaCheckServletFilter extends OncePerRequestFilter {
private static final Logger LOG = LoggerFactory.getLogger(QuotaCheckServletFilter.class);
/** /**
* Default Filter Registration Bean Name Defined . * Default Filter Registration Bean Name Defined .
*/ */
public static final String QUOTA_FILTER_BEAN_NAME = "quotaFilterRegistrationBean"; public static final String QUOTA_FILTER_BEAN_NAME = "quotaFilterRegistrationBean";
private static final Logger LOG = LoggerFactory.getLogger(QuotaCheckServletFilter.class);
private final LimitAPI limitAPI; private final LimitAPI limitAPI;
private final PolarisRateLimiterLabelServletResolver labelResolver; private final PolarisRateLimiterLabelServletResolver labelResolver;
@ -97,8 +99,8 @@ public class QuotaCheckServletFilter extends OncePerRequestFilter {
Map<String, String> labels = getRequestLabels(request, localNamespace, localService); Map<String, String> labels = getRequestLabels(request, localNamespace, localService);
try { try {
QuotaResponse quotaResponse = QuotaCheckUtils.getQuota( QuotaResponse quotaResponse = QuotaCheckUtils.getQuota(limitAPI,
limitAPI, localNamespace, localService, 1, labels, request.getRequestURI()); localNamespace, localService, 1, labels, request.getRequestURI());
if (quotaResponse.getCode() == QuotaResultCode.QuotaResultLimited) { if (quotaResponse.getCode() == QuotaResultCode.QuotaResultLimited) {
response.setStatus(polarisRateLimitProperties.getRejectHttpCode()); response.setStatus(polarisRateLimitProperties.getRejectHttpCode());
@ -108,6 +110,7 @@ public class QuotaCheckServletFilter extends OncePerRequestFilter {
} }
// Unirate // Unirate
if (quotaResponse.getCode() == QuotaResultCode.QuotaResultOk && quotaResponse.getWaitMs() > 0) { if (quotaResponse.getCode() == QuotaResultCode.QuotaResultOk && quotaResponse.getWaitMs() > 0) {
LOG.debug("The request of [{}] will waiting for {}ms.", request.getRequestURI(), quotaResponse.getWaitMs());
Thread.sleep(quotaResponse.getWaitMs()); Thread.sleep(quotaResponse.getWaitMs());
} }
@ -147,8 +150,7 @@ public class QuotaCheckServletFilter extends OncePerRequestFilter {
return labelResolver.resolve(request); return labelResolver.resolve(request);
} }
catch (Throwable e) { catch (Throwable e) {
LOG.error("resolve custom label failed. resolver = {}", LOG.error("resolve custom label failed. resolver = {}", labelResolver.getClass().getName(), e);
labelResolver.getClass().getName(), e);
} }
} }
return Collections.emptyMap(); return Collections.emptyMap();

Loading…
Cancel
Save