mirror of https://github.com/grpc/grpc-java.git
xds: add fields for EDS server and LRS server in XdsConfig (#6287)
This commit is contained in:
parent
eef47b26b8
commit
9dce879742
|
|
@ -48,9 +48,12 @@ public final class ServiceConfigUtil {
|
||||||
private static final String SERVICE_CONFIG_METHOD_CONFIG_KEY = "methodConfig";
|
private static final String SERVICE_CONFIG_METHOD_CONFIG_KEY = "methodConfig";
|
||||||
private static final String SERVICE_CONFIG_LOAD_BALANCING_POLICY_KEY = "loadBalancingPolicy";
|
private static final String SERVICE_CONFIG_LOAD_BALANCING_POLICY_KEY = "loadBalancingPolicy";
|
||||||
private static final String SERVICE_CONFIG_LOAD_BALANCING_CONFIG_KEY = "loadBalancingConfig";
|
private static final String SERVICE_CONFIG_LOAD_BALANCING_CONFIG_KEY = "loadBalancingConfig";
|
||||||
|
// TODO(chengyuanzhang): delete this key after shifting to use bootstrap.
|
||||||
private static final String XDS_CONFIG_BALANCER_NAME_KEY = "balancerName";
|
private static final String XDS_CONFIG_BALANCER_NAME_KEY = "balancerName";
|
||||||
private static final String XDS_CONFIG_CHILD_POLICY_KEY = "childPolicy";
|
private static final String XDS_CONFIG_CHILD_POLICY_KEY = "childPolicy";
|
||||||
private static final String XDS_CONFIG_FALLBACK_POLICY_KEY = "fallbackPolicy";
|
private static final String XDS_CONFIG_FALLBACK_POLICY_KEY = "fallbackPolicy";
|
||||||
|
private static final String XDS_CONFIG_EDS_SERVICE_NAME = "edsServiceName";
|
||||||
|
private static final String XDS_CONFIG_LRS_SERVER_NAME = "lrsLoadReportingServerName";
|
||||||
private static final String SERVICE_CONFIG_STICKINESS_METADATA_KEY = "stickinessMetadataKey";
|
private static final String SERVICE_CONFIG_STICKINESS_METADATA_KEY = "stickinessMetadataKey";
|
||||||
private static final String METHOD_CONFIG_NAME_KEY = "name";
|
private static final String METHOD_CONFIG_NAME_KEY = "name";
|
||||||
private static final String METHOD_CONFIG_TIMEOUT_KEY = "timeout";
|
private static final String METHOD_CONFIG_TIMEOUT_KEY = "timeout";
|
||||||
|
|
@ -423,10 +426,27 @@ public final class ServiceConfigUtil {
|
||||||
/**
|
/**
|
||||||
* Extracts the loadbalancer name from xds loadbalancer config.
|
* Extracts the loadbalancer name from xds loadbalancer config.
|
||||||
*/
|
*/
|
||||||
|
// TODO(chengyuanzhang): delete after shifting to use bootstrap.
|
||||||
public static String getBalancerNameFromXdsConfig(Map<String, ?> rawXdsConfig) {
|
public static String getBalancerNameFromXdsConfig(Map<String, ?> rawXdsConfig) {
|
||||||
return JsonUtil.getString(rawXdsConfig, XDS_CONFIG_BALANCER_NAME_KEY);
|
return JsonUtil.getString(rawXdsConfig, XDS_CONFIG_BALANCER_NAME_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the server name to use in EDS query.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static String getEdsServiceNameFromXdsConfig(Map<String, ?> rawXdsConfig) {
|
||||||
|
return JsonUtil.getString(rawXdsConfig, XDS_CONFIG_EDS_SERVICE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the LRS server name to send load reports to.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static String getLrsServerNameFromXdsConfig(Map<String, ?> rawXdsConfig) {
|
||||||
|
return JsonUtil.getString(rawXdsConfig, XDS_CONFIG_LRS_SERVER_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts list of child policies from xds loadbalancer config.
|
* Extracts list of child policies from xds loadbalancer config.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,60 @@ public class ServiceConfigUtilTest {
|
||||||
assertThat(fallbackPolicies).isNull();
|
assertThat(fallbackPolicies).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getEdsServiceNameFromXdsConfig() throws Exception {
|
||||||
|
String rawLbConfig = "{"
|
||||||
|
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||||
|
+ "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}],"
|
||||||
|
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}],"
|
||||||
|
+ "\"edsServiceName\" : \"dns:///eds.service.com:8080\""
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
String edsServiceName = ServiceConfigUtil.getEdsServiceNameFromXdsConfig(
|
||||||
|
checkObject(JsonParser.parse(rawLbConfig)));
|
||||||
|
assertThat(edsServiceName).isEqualTo("dns:///eds.service.com:8080");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getEdsServiceNameFromXdsConfig_null() throws Exception {
|
||||||
|
String rawLbConfig = "{"
|
||||||
|
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||||
|
+ "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}],"
|
||||||
|
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
String edsServiceName = ServiceConfigUtil.getEdsServiceNameFromXdsConfig(
|
||||||
|
checkObject(JsonParser.parse(rawLbConfig)));
|
||||||
|
assertThat(edsServiceName).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLrsServerNameFromXdsConfig() throws Exception {
|
||||||
|
String rawLbConfig = "{"
|
||||||
|
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||||
|
+ "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}],"
|
||||||
|
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}],"
|
||||||
|
+ "\"lrsLoadReportingServerName\" : \"dns:///lrs.service.com:8080\""
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
String lrsServerName = ServiceConfigUtil.getLrsServerNameFromXdsConfig(
|
||||||
|
checkObject(JsonParser.parse(rawLbConfig)));
|
||||||
|
assertThat(lrsServerName).isEqualTo("dns:///lrs.service.com:8080");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLrsServerNameFromXdsConfig_null() throws Exception {
|
||||||
|
String rawLbConfig = "{"
|
||||||
|
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||||
|
+ "\"childPolicy\" : [{\"round_robin\" : {}}, {\"lbPolicy2\" : {\"key\" : \"val\"}}],"
|
||||||
|
+ "\"fallbackPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"lbPolicy4\" : {}}]"
|
||||||
|
+ "}";
|
||||||
|
|
||||||
|
String lrsServerName = ServiceConfigUtil.getLrsServerNameFromXdsConfig(
|
||||||
|
checkObject(JsonParser.parse(rawLbConfig)));
|
||||||
|
assertThat(lrsServerName).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unwrapLoadBalancingConfig() throws Exception {
|
public void unwrapLoadBalancingConfig() throws Exception {
|
||||||
String lbConfig = "{\"xds_experimental\" : { "
|
String lbConfig = "{\"xds_experimental\" : { "
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,13 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider {
|
||||||
ServiceConfigUtil.getBalancerNameFromXdsConfig(rawLoadBalancingPolicyConfig);
|
ServiceConfigUtil.getBalancerNameFromXdsConfig(rawLoadBalancingPolicyConfig);
|
||||||
LbConfig childPolicy = selectChildPolicy(rawLoadBalancingPolicyConfig, registry);
|
LbConfig childPolicy = selectChildPolicy(rawLoadBalancingPolicyConfig, registry);
|
||||||
LbConfig fallbackPolicy = selectFallbackPolicy(rawLoadBalancingPolicyConfig, registry);
|
LbConfig fallbackPolicy = selectFallbackPolicy(rawLoadBalancingPolicyConfig, registry);
|
||||||
return ConfigOrError.fromConfig(new XdsConfig(newBalancerName, childPolicy, fallbackPolicy));
|
String edsServiceName =
|
||||||
|
ServiceConfigUtil.getEdsServiceNameFromXdsConfig(rawLoadBalancingPolicyConfig);
|
||||||
|
String lrsServerName =
|
||||||
|
ServiceConfigUtil.getLrsServerNameFromXdsConfig(rawLoadBalancingPolicyConfig);
|
||||||
|
return ConfigOrError.fromConfig(
|
||||||
|
new XdsConfig(
|
||||||
|
newBalancerName, childPolicy, fallbackPolicy, edsServiceName, lrsServerName));
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
return ConfigOrError.fromError(
|
return ConfigOrError.fromError(
|
||||||
Status.UNKNOWN.withDescription("Failed to parse config " + e.getMessage()).withCause(e));
|
Status.UNKNOWN.withDescription("Failed to parse config " + e.getMessage()).withCause(e));
|
||||||
|
|
@ -126,18 +132,31 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider {
|
||||||
* Represents a successfully parsed and validated LoadBalancingConfig for XDS.
|
* Represents a successfully parsed and validated LoadBalancingConfig for XDS.
|
||||||
*/
|
*/
|
||||||
static final class XdsConfig {
|
static final class XdsConfig {
|
||||||
|
// TODO(chengyuanzhang): delete after shifting to use bootstrap.
|
||||||
final String balancerName;
|
final String balancerName;
|
||||||
// TODO(carl-mastrangelo): make these Object's containing the fully parsed child configs.
|
// TODO(carl-mastrangelo): make these Object's containing the fully parsed child configs.
|
||||||
@Nullable
|
@Nullable
|
||||||
final LbConfig childPolicy;
|
final LbConfig childPolicy;
|
||||||
@Nullable
|
@Nullable
|
||||||
final LbConfig fallbackPolicy;
|
final LbConfig fallbackPolicy;
|
||||||
|
// Optional. Name to use in EDS query. If not present, defaults to the server name from the
|
||||||
|
// target URI.
|
||||||
|
@Nullable
|
||||||
|
final String edsServiceName;
|
||||||
|
// Optional. LRS server to send load reports to. If not present, load reporting will be
|
||||||
|
// disabled. If set to the empty string, load reporting will be sent to the same server that
|
||||||
|
// we obtained CDS data from.
|
||||||
|
@Nullable
|
||||||
|
final String lrsServerName;
|
||||||
|
|
||||||
XdsConfig(
|
XdsConfig(
|
||||||
String balancerName, @Nullable LbConfig childPolicy, @Nullable LbConfig fallbackPolicy) {
|
String balancerName, @Nullable LbConfig childPolicy, @Nullable LbConfig fallbackPolicy,
|
||||||
|
@Nullable String edsServiceName, @Nullable String lrsServerName) {
|
||||||
this.balancerName = checkNotNull(balancerName, "balancerName");
|
this.balancerName = checkNotNull(balancerName, "balancerName");
|
||||||
this.childPolicy = childPolicy;
|
this.childPolicy = childPolicy;
|
||||||
this.fallbackPolicy = fallbackPolicy;
|
this.fallbackPolicy = fallbackPolicy;
|
||||||
|
this.edsServiceName = edsServiceName;
|
||||||
|
this.lrsServerName = lrsServerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -146,6 +165,8 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider {
|
||||||
.add("balancerName", balancerName)
|
.add("balancerName", balancerName)
|
||||||
.add("childPolicy", childPolicy)
|
.add("childPolicy", childPolicy)
|
||||||
.add("fallbackPolicy", fallbackPolicy)
|
.add("fallbackPolicy", fallbackPolicy)
|
||||||
|
.add("edsServiceName", edsServiceName)
|
||||||
|
.add("lrsServerName", lrsServerName)
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,12 +178,15 @@ public final class XdsLoadBalancerProvider extends LoadBalancerProvider {
|
||||||
XdsConfig that = (XdsConfig) obj;
|
XdsConfig that = (XdsConfig) obj;
|
||||||
return Objects.equal(this.balancerName, that.balancerName)
|
return Objects.equal(this.balancerName, that.balancerName)
|
||||||
&& Objects.equal(this.childPolicy, that.childPolicy)
|
&& Objects.equal(this.childPolicy, that.childPolicy)
|
||||||
&& Objects.equal(this.fallbackPolicy, that.fallbackPolicy);
|
&& Objects.equal(this.fallbackPolicy, that.fallbackPolicy)
|
||||||
|
&& Objects.equal(this.edsServiceName, that.edsServiceName)
|
||||||
|
&& Objects.equal(this.lrsServerName, that.lrsServerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(balancerName, childPolicy, fallbackPolicy);
|
return Objects.hashCode(
|
||||||
|
balancerName, childPolicy, fallbackPolicy, edsServiceName, lrsServerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,9 @@ public class XdsLoadBalancerProviderTest {
|
||||||
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
+ "\"balancerName\" : \"dns:///balancer.example.com:8080\","
|
||||||
+ "\"childPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"supported_1\" : {}}],"
|
+ "\"childPolicy\" : [{\"lbPolicy3\" : {\"key\" : \"val\"}}, {\"supported_1\" : {}}],"
|
||||||
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"round_robin\" : {\"key\" : \"val\"}},"
|
+ "\"fallbackPolicy\" : [{\"unsupported\" : {}}, {\"round_robin\" : {\"key\" : \"val\"}},"
|
||||||
+ "{\"supported_2\" : {\"key\" : \"val\"}}]"
|
+ "{\"supported_2\" : {\"key\" : \"val\"}}],"
|
||||||
|
+ "\"edsServiceName\" : \"dns:///eds.service.com:8080\","
|
||||||
|
+ "\"lrsLoadReportingServerName\" : \"dns:///lrs.service.com:8080\""
|
||||||
+ "}";
|
+ "}";
|
||||||
Map<String, ?> rawlbConfigMap = checkObject(JsonParser.parse(rawLbConfig));
|
Map<String, ?> rawlbConfigMap = checkObject(JsonParser.parse(rawLbConfig));
|
||||||
ConfigOrError configOrError =
|
ConfigOrError configOrError =
|
||||||
|
|
@ -175,7 +177,9 @@ public class XdsLoadBalancerProviderTest {
|
||||||
ServiceConfigUtil.unwrapLoadBalancingConfig(
|
ServiceConfigUtil.unwrapLoadBalancingConfig(
|
||||||
checkObject(JsonParser.parse("{\"supported_1\" : {}}"))),
|
checkObject(JsonParser.parse("{\"supported_1\" : {}}"))),
|
||||||
ServiceConfigUtil.unwrapLoadBalancingConfig(
|
ServiceConfigUtil.unwrapLoadBalancingConfig(
|
||||||
checkObject(JsonParser.parse("{\"round_robin\" : {\"key\" : \"val\"}}"))))
|
checkObject(JsonParser.parse("{\"round_robin\" : {\"key\" : \"val\"}}"))),
|
||||||
|
"dns:///eds.service.com:8080",
|
||||||
|
"dns:///lrs.service.com:8080")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue