Skip to content

Commit

Permalink
Set Eureka InstanceInfo to endpoint attribute
Browse files Browse the repository at this point in the history
Related: #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 #6056
- Now users can retrieve it.
  • Loading branch information
Ivan-Montes committed Jan 13, 2025
1 parent d7a4d29 commit 29d007a
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import com.linecorp.armeria.server.eureka.EurekaUpdatingListener;

import io.netty.channel.EventLoop;
import io.netty.util.AttributeKey;
import io.netty.util.concurrent.ScheduledFuture;

/**
Expand Down Expand Up @@ -399,6 +400,24 @@ public List<Endpoint> apply(byte[] content) {
}
}

private static final class EurekaInstanceInfoUtil {

private static final AttributeKey<InstanceInfo> INSTANCE_INFO = AttributeKey.valueOf(
EurekaInstanceInfoUtil.class, "INSTANCE_INFO");

@Nullable
static InstanceInfo get(Endpoint endpoint) {
requireNonNull(endpoint, "endpoint");
return endpoint.attr(INSTANCE_INFO);
}

static Endpoint with(Endpoint endpoint, InstanceInfo instanceInfo) {
requireNonNull(endpoint, "endpoint");
requireNonNull(instanceInfo, "instanceInfo");
return endpoint.withAttr(INSTANCE_INFO, instanceInfo);
}
}

private static Endpoint endpoint(InstanceInfo instanceInfo, boolean secureVip) {
final String hostname = instanceInfo.getHostName();
final PortWrapper portWrapper = instanceInfo.getPort();
Expand All @@ -415,7 +434,7 @@ private static Endpoint endpoint(InstanceInfo instanceInfo, boolean secureVip) {
if (ipAddr != null && hostname != ipAddr) {
endpoint = endpoint.withIpAddr(ipAddr);
}
return endpoint;
return EurekaInstanceInfoUtil.with(endpoint, instanceInfo);
}

@Override
Expand Down

0 comments on commit 29d007a

Please sign in to comment.