Skip to content

Commit

Permalink
Add ipAddress to RequestAttempt & include port in serialization (#1692)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinbunney authored Nov 2, 2023
1 parent e46ab42 commit ffce212
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ private void proxyRequestToOrigin() {
zuulRequest, channelCtx.channel().eventLoop(), attemptNum, passport, chosenServer, chosenHostAddr);

storeAndLogOriginRequestInfo();
currentRequestAttempt = origin.newRequestAttempt(chosenServer.get(), context, attemptNum);
currentRequestAttempt =
origin.newRequestAttempt(chosenServer.get(), chosenHostAddr.get(), context, attemptNum);
requestAttempts.add(currentRequestAttempt);
passport.add(PassportState.ORIGIN_CONN_ACQUIRE_START);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.netty.handler.timeout.ReadTimeoutException;

import javax.net.ssl.SSLHandshakeException;
import java.net.InetAddress;

/**
* User: [email protected]
Expand All @@ -51,6 +52,7 @@ public class RequestAttempt {
private String instanceId;
private String host;
private int port;
private String ipAddress;
private String vip;
private String region;
private String availabilityZone;
Expand All @@ -61,6 +63,7 @@ public class RequestAttempt {
public RequestAttempt(
int attemptNumber,
InstanceInfo server,
InetAddress serverAddr,
String targetVip,
String chosenWarmupLB,
int status,
Expand Down Expand Up @@ -99,6 +102,10 @@ public RequestAttempt(
}
}

if (serverAddr != null) {
ipAddress = serverAddr.getHostAddress();
}

this.status = status;
this.error = error;
this.exceptionType = exceptionType;
Expand All @@ -108,7 +115,11 @@ public RequestAttempt(
}

public RequestAttempt(
final DiscoveryResult server, final IClientConfig clientConfig, int attemptNumber, int readTimeout) {
final DiscoveryResult server,
InetAddress serverAddr,
final IClientConfig clientConfig,
int attemptNumber,
int readTimeout) {
this.status = -1;
this.attempt = attemptNumber;
this.readTimeout = readTimeout;
Expand Down Expand Up @@ -141,6 +152,10 @@ public RequestAttempt(
}
}

if (serverAddr != null) {
ipAddress = serverAddr.getHostAddress();
}

if (clientConfig != null) {
this.connectTimeout = clientConfig.get(IClientConfigKey.Keys.ConnectTimeout);
}
Expand Down Expand Up @@ -200,6 +215,10 @@ public int getPort() {
return port;
}

public String getIpAddress() {
return ipAddress;
}

public String getRegion() {
return region;
}
Expand Down Expand Up @@ -256,6 +275,10 @@ public void setPort(int port) {
this.port = port;
}

public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}

public void setVip(String vip) {
this.vip = vip;
}
Expand Down Expand Up @@ -338,6 +361,11 @@ public ObjectNode toJsonNode() {
putNullableAttribute(root, "asg", asg);
putNullableAttribute(root, "instanceId", instanceId);
putNullableAttribute(root, "vip", vip);
putNullableAttribute(root, "ipAddress", ipAddress);

if (port > 0) {
root.put("port", port);
}

if (status < 1) {
root.put("readTimeout", readTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ public int getMaxRetriesForRequest(SessionContext context) {
}

@Override
public RequestAttempt newRequestAttempt(DiscoveryResult server, SessionContext zuulCtx, int attemptNum) {
return new RequestAttempt(server, config, attemptNum, config.get(CommonClientConfigKey.ReadTimeout));
public RequestAttempt newRequestAttempt(
DiscoveryResult server, InetAddress serverAddr, SessionContext zuulCtx, int attemptNum) {
return new RequestAttempt(
server, serverAddr, config, attemptNum, config.get(CommonClientConfigKey.ReadTimeout));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ void onRequestExecutionFailed(

void recordFinalResponse(final HttpResponseMessage resp);

RequestAttempt newRequestAttempt(final DiscoveryResult server, final SessionContext zuulCtx, int attemptNum);
RequestAttempt newRequestAttempt(
final DiscoveryResult server, final InetAddress serverAddr, final SessionContext zuulCtx, int attemptNum);

String getIpAddrFromServer(DiscoveryResult server);

Expand Down

0 comments on commit ffce212

Please sign in to comment.