Skip to content

Commit

Permalink
empty dumpLdsConfig()
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiitk committed Feb 25, 2021
1 parent 7b68d94 commit 9ac4279
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 61 deletions.
1 change: 1 addition & 0 deletions xds/src/main/java/io/grpc/xds/AbstractXdsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
* the xDS RPC stream.
*/
abstract class AbstractXdsClient extends XdsClient {

private static final String ADS_TYPE_URL_LDS_V2 = "type.googleapis.com/envoy.api.v2.Listener";
private static final String ADS_TYPE_URL_LDS =
"type.googleapis.com/envoy.config.listener.v3.Listener";
Expand Down
9 changes: 9 additions & 0 deletions xds/src/main/java/io/grpc/xds/ClientXdsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.protobuf.util.Durations;
import com.google.re2j.Pattern;
import com.google.re2j.PatternSyntaxException;
import io.envoyproxy.envoy.admin.v3.ListenersConfigDump;
import io.envoyproxy.envoy.config.cluster.v3.CircuitBreakers.Thresholds;
import io.envoyproxy.envoy.config.cluster.v3.Cluster;
import io.envoyproxy.envoy.config.cluster.v3.Cluster.CustomClusterType;
Expand Down Expand Up @@ -262,6 +263,14 @@ protected void handleLdsResponse(String versionInfo, List<Any> resources, String
}
}

@Override
ListenersConfigDump dumpLdsConfig() {
ListenersConfigDump.Builder ldsConfig = ListenersConfigDump.newBuilder()
.setVersionInfo(getCurrentVersion(ResourceType.LDS));

return ldsConfig.build();
}

private static StructOrError<VirtualHost> parseVirtualHost(
io.envoyproxy.envoy.config.route.v3.VirtualHost proto) {
String name = proto.getName();
Expand Down
60 changes: 5 additions & 55 deletions xds/src/main/java/io/grpc/xds/CsdsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.envoyproxy.envoy.service.status.v3.ClientStatusDiscoveryServiceGrpc;
import io.envoyproxy.envoy.service.status.v3.ClientStatusRequest;
import io.envoyproxy.envoy.service.status.v3.ClientStatusResponse;
import io.envoyproxy.envoy.service.status.v3.PerXdsConfig;
import io.grpc.ExperimentalApi;
import io.grpc.Status;
import io.grpc.StatusException;
Expand All @@ -38,14 +39,6 @@
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/TODO")
public final class CsdsService extends
ClientStatusDiscoveryServiceGrpc.ClientStatusDiscoveryServiceImplBase {
// private static final ImmutableMap<ResourceType, Class<?>> RESOURCE_TO_CONFIG_DUMP_CLASS =
// new ImmutableMap.Builder<ResourceType, Class<?>>()
// .put(ResourceType.LDS, ListenersConfigDump.class)
// .put(ResourceType.RDS, RoutesConfigDump.class)
// .put(ResourceType.CDS, ClustersConfigDump.class)
// .put(ResourceType.EDS, EndpointsConfigDump.class)
// .build();

private final SharedXdsClientPoolProvider xdsClientPoolProvider;

private CsdsService() {
Expand Down Expand Up @@ -125,52 +118,9 @@ private ClientStatusResponse getConfigDumpForRequest(ClientStatusRequest request
}

private ClientConfig getClientConfigForXdsClient(XdsClient xdsClient) {
ClientConfig.Builder clientConfig = ClientConfig.newBuilder();

// Add node info loaded from bootstrap.
clientConfig.setNode(xdsClient.getNode().toEnvoyProtoNode());

// String ldsVersion = xdsClient.getCurrentVersion(ResourceType.LDS);
// ListenersConfigDump.Builder ldsConfigDump = ListenersConfigDump.newBuilder()
// .setVersionInfo(ldsVersion);
// if (!ldsVersion.equals("")) {
// // ...
// }

return clientConfig.build();
return ClientConfig.newBuilder()
.setNode(xdsClient.getNode().toEnvoyProtoNode())
.addXdsConfig(PerXdsConfig.newBuilder().setListenerConfig(xdsClient.dumpLdsConfig()))
.build();
}

// private ClientStatusResponse getConfigDumpForRequest(
// ClientStatusRequest request, AbstractXdsClient xdsClient) {
//
//
// ClientConfig.Builder clientConfig = ClientConfig.newBuilder();
// return ClientStatusResponse.newBuilder().addConfig(clientConfig).build();
//
// // Return single clientConfig describing xdsClient.
// // Add node info loaded from bootstrap.
// clientConfig.setNode(xdsClient.node.toEnvoyProtoNode());
//
// // for (ResourceType type : RESOURCE_TO_CONFIG_DUMP_CLASS.keySet()) {
// // addConfigDump(type, clientConfig, xdsClient);
// // }
// // LDS
// String ldsVersion = xdsClient.getCurrentVersion(ResourceType.LDS);
// if (!ldsVersion.equals("")) {
// ListenersConfigDump.Builder ldsConfigDump =
// ListenersConfigDump.newBuilder().setVersionInfo(ldsVersion);
// clientConfig.addXdsConfig(
// PerXdsConfig.newBuilder().setListenerConfig(ldsConfigDump.build()).build());
// }
//
// return resp.build();
// }
//
// // private void addConfigDump(
// // ResourceType type, ClientConfig.Builder configDump, AbstractXdsClient xdsClient) {
// // if (type == ResourceType.UNKNOWN) {
// // return;
// // }
// //
// // }
}
6 changes: 6 additions & 0 deletions xds/src/main/java/io/grpc/xds/XdsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableList;
import io.envoyproxy.envoy.admin.v3.ListenersConfigDump;
import io.grpc.Status;
import io.grpc.xds.Endpoints.DropOverload;
import io.grpc.xds.Endpoints.LocalityLbEndpoints;
Expand Down Expand Up @@ -484,6 +485,11 @@ void cancelLdsResourceWatch(String resourceName, LdsResourceWatcher watcher) {
throw new UnsupportedOperationException();
}

ListenersConfigDump dumpLdsConfig() {
// TODO(sergiitk): docs.
throw new UnsupportedOperationException();
}

/**
* Registers a data watcher for the given RDS resource.
*/
Expand Down
58 changes: 52 additions & 6 deletions xds/src/test/java/io/grpc/xds/CsdsServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,25 @@

package io.grpc.xds;

import static org.junit.Assert.assertEquals;
import static com.google.common.truth.Truth.assertThat;

import com.google.common.collect.ImmutableList;
import io.envoyproxy.envoy.admin.v3.ListenersConfigDump;
import io.envoyproxy.envoy.config.core.v3.Node;
import io.envoyproxy.envoy.service.status.v3.ClientConfig;
import io.envoyproxy.envoy.service.status.v3.ClientStatusDiscoveryServiceGrpc;
import io.envoyproxy.envoy.service.status.v3.ClientStatusRequest;
import io.envoyproxy.envoy.service.status.v3.ClientStatusResponse;
import io.envoyproxy.envoy.service.status.v3.PerXdsConfig;
import io.grpc.InsecureChannelCredentials;
import io.grpc.ManagedChannel;
import io.grpc.inprocess.InProcessChannelBuilder;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.internal.ObjectPool;
import io.grpc.testing.GrpcCleanupRule;
import io.grpc.xds.AbstractXdsClient.ResourceType;
import io.grpc.xds.Bootstrapper.ServerInfo;
import java.util.EnumMap;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -97,11 +102,52 @@ public void tearDown() {

@Test
public void nodeInfo() {
ClientStatusResponse response = blockingStub.fetchClientStatus(request);
assertEquals(1, response.getConfigCount());
Node node = fetchClientConfig().getNode();
assertThat(node.getId()).isEqualTo(NODE_ID);
assertThat(node).isEqualTo(bootstrapNode.toEnvoyProtoNode());
}

@Test
public void ldsConfig_empty() {
ClientConfig config = fetchClientConfig();
EnumMap<ResourceType, PerXdsConfig> configDumpMap = mapConfigDumps(config);
assertThat(configDumpMap).containsKey(ResourceType.LDS);
PerXdsConfig perXdsConfig = configDumpMap.get(ResourceType.LDS);
ListenersConfigDump ldsConfig = perXdsConfig.getListenerConfig();
assertThat(ldsConfig.getVersionInfo()).isEmpty();
assertThat(ldsConfig.getStaticListenersCount()).isEqualTo(0);
assertThat(ldsConfig.getDynamicListenersCount()).isEqualTo(0);
}

private EnumMap<ResourceType, PerXdsConfig> mapConfigDumps(ClientConfig config) {
EnumMap<ResourceType, PerXdsConfig> xdsConfigMap = new EnumMap<>(ResourceType.class);
for (PerXdsConfig perXdsConfig : config.getXdsConfigList()) {
ResourceType type = perXdsConfigToResourceType(perXdsConfig);
assertThat(type).isNotEqualTo(ResourceType.UNKNOWN);
assertThat(xdsConfigMap).doesNotContainKey(type);
xdsConfigMap.put(type, perXdsConfig);
}
return xdsConfigMap;
}

private ResourceType perXdsConfigToResourceType(PerXdsConfig perXdsConfig) {
switch (perXdsConfig.getPerXdsConfigCase()) {
case LISTENER_CONFIG:
return ResourceType.LDS;
case CLUSTER_CONFIG:
return ResourceType.CDS;
case ROUTE_CONFIG:
return ResourceType.RDS;
case ENDPOINT_CONFIG:
return ResourceType.EDS;
default:
return ResourceType.UNKNOWN;
}
}

Node responseNode = response.getConfig(0).getNode();
assertEquals(NODE_ID, responseNode.getId());
assertEquals(bootstrapNode.toEnvoyProtoNode(), responseNode);
private ClientConfig fetchClientConfig() {
ClientStatusResponse response = blockingStub.fetchClientStatus(request);
assertThat(response.getConfigCount()).isEqualTo(1);
return response.getConfig(0);
}
}

0 comments on commit 9ac4279

Please sign in to comment.