|
41 | 41 | import org.springframework.cloud.client.discovery.event.HeartbeatEvent; |
42 | 42 | import org.springframework.context.ApplicationEventPublisher; |
43 | 43 | import org.springframework.context.ApplicationEventPublisherAware; |
| 44 | +import org.springframework.util.CollectionUtils; |
44 | 45 |
|
45 | 46 | import com.google.common.eventbus.Subscribe; |
| 47 | +import com.huaweicloud.common.context.InvocationContext; |
| 48 | +import com.huaweicloud.common.context.InvocationContextHolder; |
46 | 49 | import com.huaweicloud.service.engine.common.configration.bootstrap.BootstrapProperties; |
47 | 50 | import com.huaweicloud.service.engine.common.configration.bootstrap.DiscoveryBootstrapProperties; |
48 | 51 | import com.huaweicloud.service.engine.common.configration.bootstrap.MicroserviceProperties; |
@@ -132,8 +135,30 @@ public List<ServiceInstance> getInstances(String serviceId) { |
132 | 135 | if (instances == null) { |
133 | 136 | return Collections.emptyList(); |
134 | 137 | } |
135 | | - return instances.stream().filter(instance -> MicroserviceInstanceStatus.UP.equals(instance.getStatus())) |
| 138 | + List<ServiceInstance> availableInstances = instances.stream() |
| 139 | + .filter(instance -> MicroserviceInstanceStatus.UP.equals(instance.getStatus())) |
136 | 140 | .map(ServiceCombServiceInstance::new).collect(Collectors.toList()); |
| 141 | + if (LOGGER.isDebugEnabled()) { |
| 142 | + LOGGER.debug("|{}| service [{}] current available instances [{}]", getTraceId(), serviceId, |
| 143 | + buildInstancesInfo(availableInstances)); |
| 144 | + } |
| 145 | + return availableInstances; |
| 146 | + } |
| 147 | + |
| 148 | + private String getTraceId() { |
| 149 | + return InvocationContextHolder.getOrCreateInvocationContext().getContext(InvocationContext.CONTEXT_TRACE_ID); |
| 150 | + } |
| 151 | + |
| 152 | + private String buildInstancesInfo(List<ServiceInstance> availableInstances) { |
| 153 | + if (CollectionUtils.isEmpty(availableInstances)) { |
| 154 | + return ""; |
| 155 | + } |
| 156 | + StringBuilder sb = new StringBuilder(); |
| 157 | + for (ServiceInstance instance : availableInstances) { |
| 158 | + sb.append(instance.getHost()); |
| 159 | + sb.append("|"); |
| 160 | + } |
| 161 | + return sb.toString(); |
137 | 162 | } |
138 | 163 |
|
139 | 164 | @Override |
|
0 commit comments