Search in sources :

Example 11 with FilterConfig

use of io.grpc.xds.Filter.FilterConfig in project grpc-java by grpc.

the class XdsNameResolverTest method resolving_ldsResourceUpdateRdsName.

@SuppressWarnings("unchecked")
@Test
public void resolving_ldsResourceUpdateRdsName() {
    Route route1 = Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forCluster(cluster1, Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(15L), null), ImmutableMap.<String, FilterConfig>of());
    Route route2 = Route.forAction(RouteMatch.withPathExactOnly(call2.getFullMethodNameForPath()), RouteAction.forCluster(cluster2, Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(20L), null), ImmutableMap.<String, FilterConfig>of());
    resolver.start(mockListener);
    FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
    xdsClient.deliverLdsUpdateForRdsName(RDS_RESOURCE_NAME);
    assertThat(xdsClient.rdsResource).isEqualTo(RDS_RESOURCE_NAME);
    VirtualHost virtualHost = VirtualHost.create("virtualhost", Collections.singletonList(AUTHORITY), Collections.singletonList(route1), ImmutableMap.<String, FilterConfig>of());
    xdsClient.deliverRdsUpdate(RDS_RESOURCE_NAME, Collections.singletonList(virtualHost));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    assertServiceConfigForLoadBalancingConfig(Collections.singletonList(cluster1), (Map<String, ?>) resolutionResultCaptor.getValue().getServiceConfig().getConfig());
    reset(mockListener);
    ArgumentCaptor<ResolutionResult> resultCaptor = ArgumentCaptor.forClass(ResolutionResult.class);
    String alternativeRdsResource = "route-configuration-alter.googleapis.com";
    xdsClient.deliverLdsUpdateForRdsName(alternativeRdsResource);
    assertThat(xdsClient.rdsResource).isEqualTo(alternativeRdsResource);
    virtualHost = VirtualHost.create("virtualhost-alter", Collections.singletonList(AUTHORITY), Collections.singletonList(route2), ImmutableMap.<String, FilterConfig>of());
    xdsClient.deliverRdsUpdate(alternativeRdsResource, Collections.singletonList(virtualHost));
    // Two new service config updates triggered:
    // - with load balancing config being able to select cluster1 and cluster2
    // - with load balancing config being able to select cluster2 only
    verify(mockListener, times(2)).onResult(resultCaptor.capture());
    assertServiceConfigForLoadBalancingConfig(Arrays.asList(cluster1, cluster2), (Map<String, ?>) resultCaptor.getAllValues().get(0).getServiceConfig().getConfig());
    assertServiceConfigForLoadBalancingConfig(Collections.singletonList(cluster2), (Map<String, ?>) resultCaptor.getValue().getServiceConfig().getConfig());
}
Also used : HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) ResolutionResult(io.grpc.NameResolver.ResolutionResult) FilterConfig(io.grpc.xds.Filter.FilterConfig) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) Route(io.grpc.xds.VirtualHost.Route) Test(org.junit.Test)

Example 12 with FilterConfig

use of io.grpc.xds.Filter.FilterConfig in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseHttpFilter_routerFilterForServer.

@Test
public void parseHttpFilter_routerFilterForServer() {
    filterRegistry.register(RouterFilter.INSTANCE);
    HttpFilter httpFilter = HttpFilter.newBuilder().setIsOptional(false).setName("envoy.router").setTypedConfig(Any.pack(Router.getDefaultInstance())).build();
    FilterConfig config = ClientXdsClient.parseHttpFilter(httpFilter, filterRegistry, false).getStruct();
    assertThat(config.typeUrl()).isEqualTo(RouterFilter.TYPE_URL);
}
Also used : HttpFilter(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter) FilterConfig(io.grpc.xds.Filter.FilterConfig) Test(org.junit.Test)

Example 13 with FilterConfig

use of io.grpc.xds.Filter.FilterConfig in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseHttpFilter_faultConfigForClient.

@Test
public void parseHttpFilter_faultConfigForClient() {
    filterRegistry.register(FaultFilter.INSTANCE);
    HttpFilter httpFilter = HttpFilter.newBuilder().setIsOptional(false).setName("envoy.fault").setTypedConfig(Any.pack(HTTPFault.newBuilder().setDelay(FaultDelay.newBuilder().setFixedDelay(Durations.fromNanos(1234L))).setAbort(FaultAbort.newBuilder().setHttpStatus(300).setPercentage(FractionalPercent.newBuilder().setNumerator(10).setDenominator(DenominatorType.HUNDRED))).build())).build();
    FilterConfig config = ClientXdsClient.parseHttpFilter(httpFilter, filterRegistry, true).getStruct();
    assertThat(config).isInstanceOf(FaultConfig.class);
}
Also used : HttpFilter(io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter) FilterConfig(io.grpc.xds.Filter.FilterConfig) Test(org.junit.Test)

Example 14 with FilterConfig

use of io.grpc.xds.Filter.FilterConfig in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseOverrideRbacFilterConfig.

@Test
public void parseOverrideRbacFilterConfig() {
    filterRegistry.register(RbacFilter.INSTANCE);
    RBACPerRoute rbacPerRoute = RBACPerRoute.newBuilder().setRbac(io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBAC.newBuilder().setRules(RBAC.newBuilder().setAction(Action.ALLOW).putPolicies("allow-all", Policy.newBuilder().addPrincipals(Principal.newBuilder().setAny(true)).addPermissions(Permission.newBuilder().setAny(true)).build()))).build();
    Map<String, Any> configOverrides = ImmutableMap.of("envoy.auth", Any.pack(rbacPerRoute));
    Map<String, FilterConfig> parsedConfigs = ClientXdsClient.parseOverrideFilterConfigs(configOverrides, filterRegistry).getStruct();
    assertThat(parsedConfigs).hasSize(1);
    assertThat(parsedConfigs).containsKey("envoy.auth");
    assertThat(parsedConfigs.get("envoy.auth")).isInstanceOf(RbacConfig.class);
}
Also used : RBACPerRoute(io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBACPerRoute) FilterConfig(io.grpc.xds.Filter.FilterConfig) Any(com.google.protobuf.Any) Test(org.junit.Test)

Example 15 with FilterConfig

use of io.grpc.xds.Filter.FilterConfig in project grpc-java by grpc.

the class ClientXdsClientDataTest method parseOverrideFilterConfigs_unsupportedButOptional.

@Test
public void parseOverrideFilterConfigs_unsupportedButOptional() {
    filterRegistry.register(FaultFilter.INSTANCE);
    HTTPFault httpFault = HTTPFault.newBuilder().setDelay(FaultDelay.newBuilder().setFixedDelay(Durations.fromNanos(3000))).build();
    Map<String, Any> configOverrides = ImmutableMap.of("envoy.fault", Any.pack(httpFault), "unsupported.filter", Any.pack(io.envoyproxy.envoy.config.route.v3.FilterConfig.newBuilder().setIsOptional(true).setConfig(Any.pack(StringValue.of("string value"))).build()));
    Map<String, FilterConfig> parsedConfigs = ClientXdsClient.parseOverrideFilterConfigs(configOverrides, filterRegistry).getStruct();
    assertThat(parsedConfigs).hasSize(1);
    assertThat(parsedConfigs).containsKey("envoy.fault");
}
Also used : HTTPFault(io.envoyproxy.envoy.extensions.filters.http.fault.v3.HTTPFault) FilterConfig(io.grpc.xds.Filter.FilterConfig) Any(com.google.protobuf.Any) Test(org.junit.Test)

Aggregations

FilterConfig (io.grpc.xds.Filter.FilterConfig)18 Test (org.junit.Test)14 NamedFilterConfig (io.grpc.xds.Filter.NamedFilterConfig)8 HttpFilter (io.envoyproxy.envoy.extensions.filters.network.http_connection_manager.v3.HttpFilter)7 Any (com.google.protobuf.Any)4 Route (io.grpc.xds.VirtualHost.Route)4 TypedStruct (com.github.udpa.udpa.type.v1.TypedStruct)3 HashPolicy (io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy)3 RouteMatch (io.grpc.xds.VirtualHost.Route.RouteMatch)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Struct (com.google.protobuf.Struct)2 Metadata (io.grpc.Metadata)2 ResolutionResult (io.grpc.NameResolver.ResolutionResult)2 Server (io.grpc.Server)2 ServerCall (io.grpc.ServerCall)2 ServerCallHandler (io.grpc.ServerCallHandler)2 ServerInterceptor (io.grpc.ServerInterceptor)2 StatusException (io.grpc.StatusException)2 FilterChain (io.grpc.xds.EnvoyServerProtoData.FilterChain)2 ServerInterceptorBuilder (io.grpc.xds.Filter.ServerInterceptorBuilder)2