|
|
|
@ -17,6 +17,14 @@
|
|
|
|
|
|
|
|
|
|
package com.tencent.cloud.rpc.enhancement.webclient;
|
|
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.net.SocketTimeoutException;
|
|
|
|
|
import java.net.URI;
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
import com.tencent.cloud.common.constant.HeaderConstant;
|
|
|
|
|
import com.tencent.cloud.common.constant.RouterConstant;
|
|
|
|
|
import com.tencent.cloud.common.metadata.MetadataContext;
|
|
|
|
@ -32,22 +40,15 @@ import com.tencent.polaris.discovery.client.api.DefaultConsumerAPI;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
import reactor.util.context.Context;
|
|
|
|
|
import reactor.util.context.ContextView;
|
|
|
|
|
|
|
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.web.reactive.function.client.ClientRequest;
|
|
|
|
|
import org.springframework.web.reactive.function.client.ClientResponse;
|
|
|
|
|
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
|
|
|
|
|
import org.springframework.web.reactive.function.client.ExchangeFunction;
|
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
import reactor.util.context.Context;
|
|
|
|
|
import reactor.util.context.ContextView;
|
|
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
import java.net.SocketTimeoutException;
|
|
|
|
|
import java.net.URI;
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
import static com.tencent.cloud.common.constant.ContextConstant.UTF_8;
|
|
|
|
|
|
|
|
|
@ -68,6 +69,35 @@ public class EnhancedWebClientReporter extends AbstractPolarisReporterAdapter im
|
|
|
|
|
this.consumerAPI = consumerAPI;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static RetStatus getRetStatusFromRequest(ClientResponse response, RetStatus defaultVal) {
|
|
|
|
|
HttpHeaders headers = response.headers().asHttpHeaders();
|
|
|
|
|
if (headers.containsKey(HeaderConstant.INTERNAL_CALLEE_RET_STATUS)) {
|
|
|
|
|
List<String> values = headers.get(HeaderConstant.INTERNAL_CALLEE_RET_STATUS);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(values)) {
|
|
|
|
|
String retStatusVal = com.tencent.polaris.api.utils.StringUtils.defaultString(values.get(0));
|
|
|
|
|
if (Objects.equals(retStatusVal, RetStatus.RetFlowControl.getDesc())) {
|
|
|
|
|
return RetStatus.RetFlowControl;
|
|
|
|
|
}
|
|
|
|
|
if (Objects.equals(retStatusVal, RetStatus.RetReject.getDesc())) {
|
|
|
|
|
return RetStatus.RetReject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return defaultVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String getActiveRuleNameFromRequest(ClientResponse response) {
|
|
|
|
|
HttpHeaders headers = response.headers().asHttpHeaders();
|
|
|
|
|
if (headers.containsKey(HeaderConstant.INTERNAL_ACTIVE_RULE_NAME)) {
|
|
|
|
|
List<String> values = headers.get(HeaderConstant.INTERNAL_ACTIVE_RULE_NAME);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(values)) {
|
|
|
|
|
String val = com.tencent.polaris.api.utils.StringUtils.defaultString(values.get(0));
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Mono<ClientResponse> filter(ClientRequest request, ExchangeFunction next) {
|
|
|
|
|
return next.exchange(request).as((responseMono) -> instrumentResponse(request, responseMono))
|
|
|
|
@ -97,7 +127,8 @@ public class EnhancedWebClientReporter extends AbstractPolarisReporterAdapter im
|
|
|
|
|
String label = labels.iterator().next();
|
|
|
|
|
try {
|
|
|
|
|
label = URLDecoder.decode(label, UTF_8);
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
}
|
|
|
|
|
catch (UnsupportedEncodingException e) {
|
|
|
|
|
LOGGER.error("unsupported charset exception " + UTF_8, e);
|
|
|
|
|
}
|
|
|
|
|
callResult.setLabels(convertLabel(label));
|
|
|
|
@ -131,35 +162,6 @@ public class EnhancedWebClientReporter extends AbstractPolarisReporterAdapter im
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static RetStatus getRetStatusFromRequest(ClientResponse response, RetStatus defaultVal) {
|
|
|
|
|
HttpHeaders headers = response.headers().asHttpHeaders();
|
|
|
|
|
if (headers.containsKey(HeaderConstant.INTERNAL_CALLEE_RET_STATUS)) {
|
|
|
|
|
List<String> values = headers.get(HeaderConstant.INTERNAL_CALLEE_RET_STATUS);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(values)) {
|
|
|
|
|
String retStatusVal = com.tencent.polaris.api.utils.StringUtils.defaultString(values.get(0));
|
|
|
|
|
if (Objects.equals(retStatusVal, RetStatus.RetFlowControl.getDesc())) {
|
|
|
|
|
return RetStatus.RetFlowControl;
|
|
|
|
|
}
|
|
|
|
|
if (Objects.equals(retStatusVal, RetStatus.RetReject.getDesc())) {
|
|
|
|
|
return RetStatus.RetReject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return defaultVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String getActiveRuleNameFromRequest(ClientResponse response) {
|
|
|
|
|
HttpHeaders headers = response.headers().asHttpHeaders();
|
|
|
|
|
if (headers.containsKey(HeaderConstant.INTERNAL_ACTIVE_RULE_NAME)) {
|
|
|
|
|
List<String> values = headers.get(HeaderConstant.INTERNAL_ACTIVE_RULE_NAME);
|
|
|
|
|
if (CollectionUtils.isNotEmpty(values)) {
|
|
|
|
|
String val = com.tencent.polaris.api.utils.StringUtils.defaultString(values.get(0));
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Long getStartTime(ContextView context) {
|
|
|
|
|
return context.get(METRICS_WEBCLIENT_START_TIME);
|
|
|
|
|
}
|
|
|
|
|