|
|
@ -17,14 +17,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
package com.tencent.cloud.rpc.enhancement.feign.plugin.reporter;
|
|
|
|
package com.tencent.cloud.rpc.enhancement.feign.plugin.reporter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URI;
|
|
|
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.tencent.cloud.common.constant.RouterConstants;
|
|
|
|
import com.tencent.cloud.common.metadata.MetadataContext;
|
|
|
|
import com.tencent.cloud.common.metadata.MetadataContext;
|
|
|
|
import com.tencent.polaris.api.pojo.RetStatus;
|
|
|
|
import com.tencent.polaris.api.pojo.RetStatus;
|
|
|
|
import com.tencent.polaris.api.pojo.ServiceKey;
|
|
|
|
import com.tencent.polaris.api.pojo.ServiceKey;
|
|
|
|
import com.tencent.polaris.api.rpc.ServiceCallResult;
|
|
|
|
import com.tencent.polaris.api.rpc.ServiceCallResult;
|
|
|
|
|
|
|
|
import com.tencent.polaris.api.utils.CollectionUtils;
|
|
|
|
import feign.Request;
|
|
|
|
import feign.Request;
|
|
|
|
|
|
|
|
import feign.RequestTemplate;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static com.tencent.cloud.common.constant.ContextConstant.UTF_8;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Util for polaris reporter.
|
|
|
|
* Util for polaris reporter.
|
|
|
@ -33,6 +43,8 @@ import org.apache.commons.lang.StringUtils;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public final class ReporterUtils {
|
|
|
|
public final class ReporterUtils {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(ReporterUtils.class);
|
|
|
|
|
|
|
|
|
|
|
|
private ReporterUtils() {
|
|
|
|
private ReporterUtils() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -40,8 +52,20 @@ public final class ReporterUtils {
|
|
|
|
ServiceCallResult resultRequest = new ServiceCallResult();
|
|
|
|
ServiceCallResult resultRequest = new ServiceCallResult();
|
|
|
|
|
|
|
|
|
|
|
|
resultRequest.setNamespace(MetadataContext.LOCAL_NAMESPACE);
|
|
|
|
resultRequest.setNamespace(MetadataContext.LOCAL_NAMESPACE);
|
|
|
|
String serviceName = request.requestTemplate().feignTarget().name();
|
|
|
|
RequestTemplate requestTemplate = request.requestTemplate();
|
|
|
|
|
|
|
|
String serviceName = requestTemplate.feignTarget().name();
|
|
|
|
resultRequest.setService(serviceName);
|
|
|
|
resultRequest.setService(serviceName);
|
|
|
|
|
|
|
|
Collection<String> labels = requestTemplate.headers().get(RouterConstants.ROUTER_LABEL_HEADER);
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(labels) && labels.iterator().hasNext()) {
|
|
|
|
|
|
|
|
String label = labels.iterator().next();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
label = URLDecoder.decode(label, UTF_8);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (UnsupportedEncodingException e) {
|
|
|
|
|
|
|
|
LOGGER.error("unsupported charset exception " + UTF_8, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
resultRequest.setLabels(convertLabel(label));
|
|
|
|
|
|
|
|
}
|
|
|
|
URI uri = URI.create(request.url());
|
|
|
|
URI uri = URI.create(request.url());
|
|
|
|
resultRequest.setMethod(uri.getPath());
|
|
|
|
resultRequest.setMethod(uri.getPath());
|
|
|
|
resultRequest.setRetStatus(retStatus);
|
|
|
|
resultRequest.setRetStatus(retStatus);
|
|
|
@ -55,4 +79,10 @@ public final class ReporterUtils {
|
|
|
|
|
|
|
|
|
|
|
|
return resultRequest;
|
|
|
|
return resultRequest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String convertLabel(String label) {
|
|
|
|
|
|
|
|
label = label.replaceAll("\"|\\{|\\}", "")
|
|
|
|
|
|
|
|
.replaceAll(",", "|");
|
|
|
|
|
|
|
|
return label;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|