|
|
@ -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,7 +52,19 @@ 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();
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
}
|
|
|
|
resultRequest.setService(serviceName);
|
|
|
|
resultRequest.setService(serviceName);
|
|
|
|
URI uri = URI.create(request.url());
|
|
|
|
URI uri = URI.create(request.url());
|
|
|
|
resultRequest.setMethod(uri.getPath());
|
|
|
|
resultRequest.setMethod(uri.getPath());
|
|
|
@ -52,7 +76,12 @@ public final class ReporterUtils {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resultRequest.setHost(uri.getHost());
|
|
|
|
resultRequest.setHost(uri.getHost());
|
|
|
|
resultRequest.setPort(uri.getPort());
|
|
|
|
resultRequest.setPort(uri.getPort());
|
|
|
|
|
|
|
|
|
|
|
|
return resultRequest;
|
|
|
|
return resultRequest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String convertLabel(String label) {
|
|
|
|
|
|
|
|
label = label.replaceAll("\"|\\{|\\}", "")
|
|
|
|
|
|
|
|
.replaceAll(",", "|");
|
|
|
|
|
|
|
|
return label;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|