|
|
@ -119,12 +119,14 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void reportResult(URI url, ClientHttpResponse response) {
|
|
|
|
private void reportResult(URI url, ClientHttpResponse response) {
|
|
|
|
ServiceCallResult resultRequest = createServiceCallResult(url);
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
ServiceCallResult resultRequest = createServiceCallResult(url, response);
|
|
|
|
Map<String, String> loadBalancerContext = MetadataContextHolder.get().getLoadbalancerMetadata();
|
|
|
|
Map<String, String> loadBalancerContext = MetadataContextHolder.get().getLoadbalancerMetadata();
|
|
|
|
|
|
|
|
|
|
|
|
String targetHost = loadBalancerContext.get("host");
|
|
|
|
String targetHost = loadBalancerContext.get("host");
|
|
|
|
String targetPort = loadBalancerContext.get("port");
|
|
|
|
String targetPort = loadBalancerContext.get("port");
|
|
|
|
|
|
|
|
String startMillis = loadBalancerContext.get("startMillis");
|
|
|
|
|
|
|
|
long delay = System.currentTimeMillis() - Long.parseLong(startMillis);
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(targetHost) || StringUtils.isBlank(targetPort)) {
|
|
|
|
if (StringUtils.isBlank(targetHost) || StringUtils.isBlank(targetPort)) {
|
|
|
|
LOGGER.warn("Can not get target host or port from metadata context. host = {}, port = {}", targetHost, targetPort);
|
|
|
|
LOGGER.warn("Can not get target host or port from metadata context. host = {}, port = {}", targetHost, targetPort);
|
|
|
@ -133,6 +135,7 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter
|
|
|
|
|
|
|
|
|
|
|
|
resultRequest.setHost(targetHost);
|
|
|
|
resultRequest.setHost(targetHost);
|
|
|
|
resultRequest.setPort(Integer.parseInt(targetPort));
|
|
|
|
resultRequest.setPort(Integer.parseInt(targetPort));
|
|
|
|
|
|
|
|
resultRequest.setDelay(delay);
|
|
|
|
|
|
|
|
|
|
|
|
// checking response http status code
|
|
|
|
// checking response http status code
|
|
|
|
HttpStatusCode httpStatusCode = response.getStatusCode();
|
|
|
|
HttpStatusCode httpStatusCode = response.getStatusCode();
|
|
|
@ -154,8 +157,8 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// processing report with consumerAPI .
|
|
|
|
// processing report with consumerAPI .
|
|
|
|
LOGGER.debug("Will report result of {}. URL=[{}]. Response=[{}].", resultRequest.getRetStatus().name(),
|
|
|
|
LOGGER.debug("Will report result of {}. Request=[{}]. Response=[{}]. Delay=[{}]ms.", resultRequest.getRetStatus()
|
|
|
|
url, response);
|
|
|
|
.name(), url, httpStatusCode.value(), delay);
|
|
|
|
consumerAPI.updateServiceCallResult(resultRequest);
|
|
|
|
consumerAPI.updateServiceCallResult(resultRequest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
catch (Exception e) {
|
|
|
@ -197,12 +200,13 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter
|
|
|
|
response.getHeaders().remove(HEADER_HAS_ERROR);
|
|
|
|
response.getHeaders().remove(HEADER_HAS_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private ServiceCallResult createServiceCallResult(URI uri) {
|
|
|
|
private ServiceCallResult createServiceCallResult(URI uri, ClientHttpResponse response) throws IOException {
|
|
|
|
ServiceCallResult resultRequest = new ServiceCallResult();
|
|
|
|
ServiceCallResult resultRequest = new ServiceCallResult();
|
|
|
|
String serviceName = uri.getHost();
|
|
|
|
String serviceName = uri.getHost();
|
|
|
|
resultRequest.setService(serviceName);
|
|
|
|
resultRequest.setService(serviceName);
|
|
|
|
resultRequest.setNamespace(MetadataContext.LOCAL_NAMESPACE);
|
|
|
|
resultRequest.setNamespace(MetadataContext.LOCAL_NAMESPACE);
|
|
|
|
resultRequest.setMethod(uri.getPath());
|
|
|
|
resultRequest.setMethod(uri.getPath());
|
|
|
|
|
|
|
|
resultRequest.setRetCode(response.getStatusCode().value());
|
|
|
|
resultRequest.setRetStatus(RetStatus.RetSuccess);
|
|
|
|
resultRequest.setRetStatus(RetStatus.RetSuccess);
|
|
|
|
String sourceNamespace = MetadataContext.LOCAL_NAMESPACE;
|
|
|
|
String sourceNamespace = MetadataContext.LOCAL_NAMESPACE;
|
|
|
|
String sourceService = MetadataContext.LOCAL_SERVICE;
|
|
|
|
String sourceService = MetadataContext.LOCAL_SERVICE;
|
|
|
|