Skip to content

Commit 51482a5

Browse files
committed
Set Eureka InstanceInfo to endpoint attribute
Related: line#6056 Motivation: Users might want to use the metadata from the Eureka `InstanceInfo` but currently, there's no way to retrieve it. Modifications: - Add a helper class to hide the implementation detail. - Set the `InstanceInfo` to the `Endpoint` as an attribute. Result: - Closes line#6056 - Now users can retrieve it.
1 parent df2c0e9 commit 51482a5

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Diff for: eureka/src/main/java/com/linecorp/armeria/client/eureka/EurekaEndpointGroup.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import com.linecorp.armeria.server.eureka.EurekaUpdatingListener;
6767

6868
import io.netty.channel.EventLoop;
69+
import io.netty.util.AttributeKey;
6970
import io.netty.util.concurrent.ScheduledFuture;
7071

7172
/**
@@ -399,6 +400,24 @@ public List<Endpoint> apply(byte[] content) {
399400
}
400401
}
401402

403+
private static final class EurekaInstanceInfoUtil {
404+
405+
private static final AttributeKey<InstanceInfo> INSTANCE_INFO = AttributeKey.valueOf(
406+
EurekaInstanceInfoUtil.class, "INSTANCE_INFO");
407+
408+
@Nullable
409+
static InstanceInfo get(Endpoint endpoint) {
410+
requireNonNull(endpoint, "endpoint");
411+
return endpoint.attr(INSTANCE_INFO);
412+
}
413+
414+
static Endpoint with(Endpoint endpoint, InstanceInfo instanceInfo) {
415+
requireNonNull(endpoint, "endpoint");
416+
requireNonNull(instanceInfo, "instanceInfo");
417+
return endpoint.withAttr(INSTANCE_INFO, instanceInfo);
418+
}
419+
}
420+
402421
private static Endpoint endpoint(InstanceInfo instanceInfo, boolean secureVip) {
403422
final String hostname = instanceInfo.getHostName();
404423
final PortWrapper portWrapper = instanceInfo.getPort();
@@ -415,7 +434,7 @@ private static Endpoint endpoint(InstanceInfo instanceInfo, boolean secureVip) {
415434
if (ipAddr != null && hostname != ipAddr) {
416435
endpoint = endpoint.withIpAddr(ipAddr);
417436
}
418-
return endpoint;
437+
return EurekaInstanceInfoUtil.with(endpoint, instanceInfo);
419438
}
420439

421440
@Override

0 commit comments

Comments
 (0)