Search in sources :

Example 6 with FilterConfig

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

the class ClientXdsClientDataTest method parseHttpFilter_rbacConfigForServer.

@Test
public void parseHttpFilter_rbacConfigForServer() {
    filterRegistry.register(RbacFilter.INSTANCE);
    HttpFilter httpFilter = HttpFilter.newBuilder().setIsOptional(false).setName("envoy.auth").setTypedConfig(Any.pack(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()).build())).build();
    FilterConfig config = ClientXdsClient.parseHttpFilter(httpFilter, filterRegistry, false).getStruct();
    assertThat(config).isInstanceOf(RbacConfig.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 7 with FilterConfig

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

the class ClientXdsClientDataTest method parseOverrideHttpFilter_typedStructMigration.

@Test
public void parseOverrideHttpFilter_typedStructMigration() {
    filterRegistry.register(new TestFilter());
    Struct rawStruct0 = Struct.newBuilder().putFields("name", Value.newBuilder().setStringValue("default0").build()).build();
    Struct rawStruct1 = Struct.newBuilder().putFields("name", Value.newBuilder().setStringValue("default1").build()).build();
    Map<String, Any> rawFilterMap = ImmutableMap.of("struct-0", Any.pack(com.github.udpa.udpa.type.v1.TypedStruct.newBuilder().setTypeUrl("test-url").setValue(rawStruct0).build()), "struct-1", Any.pack(TypedStruct.newBuilder().setTypeUrl("test-url").setValue(rawStruct1).build()));
    Map<String, FilterConfig> map = ClientXdsClient.parseOverrideFilterConfigs(rawFilterMap, filterRegistry).getStruct();
    assertThat(((SimpleFilterConfig) map.get("struct-0")).getConfig()).isEqualTo(rawStruct0);
    assertThat(((SimpleFilterConfig) map.get("struct-1")).getConfig()).isEqualTo(rawStruct1);
}
Also used : FilterConfig(io.grpc.xds.Filter.FilterConfig) Any(com.google.protobuf.Any) Struct(com.google.protobuf.Struct) TypedStruct(com.github.udpa.udpa.type.v1.TypedStruct) Test(org.junit.Test)

Example 8 with FilterConfig

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

the class XdsNameResolverTest method resolved_simpleCallSucceeds_routeToWeightedCluster.

@SuppressWarnings("unchecked")
@Test
public void resolved_simpleCallSucceeds_routeToWeightedCluster() {
    when(mockRandom.nextInt(anyInt())).thenReturn(90, 10);
    resolver.start(mockListener);
    FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
    xdsClient.deliverLdsUpdate(Collections.singletonList(Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forWeightedClusters(Arrays.asList(ClusterWeight.create(cluster1, 20, ImmutableMap.<String, FilterConfig>of()), ClusterWeight.create(cluster2, 80, ImmutableMap.<String, FilterConfig>of())), Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(20L), null), ImmutableMap.<String, FilterConfig>of())));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    ResolutionResult result = resolutionResultCaptor.getValue();
    assertThat(result.getAddresses()).isEmpty();
    assertServiceConfigForLoadBalancingConfig(Arrays.asList(cluster1, cluster2), (Map<String, ?>) result.getServiceConfig().getConfig());
    assertThat(result.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL)).isNotNull();
    InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
    assertCallSelectClusterResult(call1, configSelector, cluster2, 20.0);
    assertCallSelectClusterResult(call1, configSelector, cluster1, 20.0);
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) 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) Test(org.junit.Test)

Example 9 with FilterConfig

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

the class XdsServerWrapperTest method buildInterceptor_rds.

@Test
@SuppressWarnings("unchecked")
public void buildInterceptor_rds() throws Exception {
    final SettableFuture<Server> start = SettableFuture.create();
    Executors.newSingleThreadExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                start.set(xdsServerWrapper.start());
            } catch (Exception ex) {
                start.setException(ex);
            }
        }
    });
    xdsClient.ldsResource.get(5, TimeUnit.SECONDS);
    Filter filter = mock(Filter.class, withSettings().extraInterfaces(ServerInterceptorBuilder.class));
    when(filter.typeUrls()).thenReturn(new String[] { "filter-type-url" });
    filterRegistry.register(filter);
    FilterConfig f0 = mock(FilterConfig.class);
    FilterConfig f0Override = mock(FilterConfig.class);
    when(f0.typeUrl()).thenReturn("filter-type-url");
    final List<Integer> interceptorTrace = new ArrayList<>();
    ServerInterceptor interceptor0 = new ServerInterceptor() {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
            interceptorTrace.add(0);
            return next.startCall(call, headers);
        }
    };
    ServerInterceptor interceptor1 = new ServerInterceptor() {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
            interceptorTrace.add(1);
            return next.startCall(call, headers);
        }
    };
    when(((ServerInterceptorBuilder) filter).buildServerInterceptor(f0, null)).thenReturn(interceptor0);
    when(((ServerInterceptorBuilder) filter).buildServerInterceptor(f0, f0Override)).thenReturn(interceptor1);
    RouteMatch routeMatch = RouteMatch.create(PathMatcher.fromPath("/FooService/barMethod", true), Collections.<HeaderMatcher>emptyList(), null);
    HttpConnectionManager rdsHcm = HttpConnectionManager.forRdsName(0L, "r0", Arrays.asList(new NamedFilterConfig("filter-config-name-0", f0), new NamedFilterConfig("filter-config-name-1", f0)));
    EnvoyServerProtoData.FilterChain filterChain = createFilterChain("filter-chain-0", rdsHcm);
    xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain), null);
    Route route = Route.forAction(routeMatch, null, ImmutableMap.<String, FilterConfig>of());
    VirtualHost virtualHost = VirtualHost.create("v1", Collections.singletonList("foo.google.com"), Arrays.asList(route), ImmutableMap.of("filter-config-name-0", f0Override));
    xdsClient.rdsCount.await(5, TimeUnit.SECONDS);
    xdsClient.deliverRdsUpdate("r0", Collections.singletonList(virtualHost));
    start.get(5000, TimeUnit.MILLISECONDS);
    verify(mockServer).start();
    assertThat(selectorManager.getSelectorToUpdateSelector().getRoutingConfigs().size()).isEqualTo(1);
    ServerInterceptor realInterceptor = selectorManager.getSelectorToUpdateSelector().getRoutingConfigs().get(filterChain).get().interceptors().get(route);
    assertThat(realInterceptor).isNotNull();
    ServerCall<Void, Void> serverCall = mock(ServerCall.class);
    ServerCallHandler<Void, Void> mockNext = mock(ServerCallHandler.class);
    final ServerCall.Listener<Void> listener = new ServerCall.Listener<Void>() {
    };
    when(mockNext.startCall(any(ServerCall.class), any(Metadata.class))).thenReturn(listener);
    realInterceptor.interceptCall(serverCall, new Metadata(), mockNext);
    assertThat(interceptorTrace).isEqualTo(Arrays.asList(1, 0));
    verify(mockNext).startCall(eq(serverCall), any(Metadata.class));
    virtualHost = VirtualHost.create("v1", Collections.singletonList("foo.google.com"), Arrays.asList(route), ImmutableMap.<String, FilterConfig>of());
    xdsClient.deliverRdsUpdate("r0", Collections.singletonList(virtualHost));
    realInterceptor = selectorManager.getSelectorToUpdateSelector().getRoutingConfigs().get(filterChain).get().interceptors().get(route);
    assertThat(realInterceptor).isNotNull();
    interceptorTrace.clear();
    realInterceptor.interceptCall(serverCall, new Metadata(), mockNext);
    assertThat(interceptorTrace).isEqualTo(Arrays.asList(0, 0));
    verify(mockNext, times(2)).startCall(eq(serverCall), any(Metadata.class));
    xdsClient.rdsWatchers.get("r0").onResourceDoesNotExist("r0");
    assertThat(selectorManager.getSelectorToUpdateSelector().getRoutingConfigs().get(filterChain).get()).isEqualTo(noopConfig);
}
Also used : XdsServingStatusListener(io.grpc.xds.XdsServerBuilder.XdsServingStatusListener) Server(io.grpc.Server) ServerCallHandler(io.grpc.ServerCallHandler) ArrayList(java.util.ArrayList) Metadata(io.grpc.Metadata) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) ServerCall(io.grpc.ServerCall) FilterConfig(io.grpc.xds.Filter.FilterConfig) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) ServerInterceptorBuilder(io.grpc.xds.Filter.ServerInterceptorBuilder) Route(io.grpc.xds.VirtualHost.Route) TimeoutException(java.util.concurrent.TimeoutException) StatusException(io.grpc.StatusException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RouteMatch(io.grpc.xds.VirtualHost.Route.RouteMatch) ServerInterceptor(io.grpc.ServerInterceptor) FilterChain(io.grpc.xds.EnvoyServerProtoData.FilterChain) Test(org.junit.Test)

Example 10 with FilterConfig

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

the class XdsServerWrapperTest method createRoutingConfig.

private static ServerRoutingConfig createRoutingConfig(String path, String domain, String filterType, Route.RouteAction action) {
    RouteMatch routeMatch = RouteMatch.create(PathMatcher.fromPath(path, true), Collections.<HeaderMatcher>emptyList(), null);
    VirtualHost virtualHost = VirtualHost.create("v1", Collections.singletonList(domain), Arrays.asList(Route.forAction(routeMatch, action, ImmutableMap.<String, FilterConfig>of())), Collections.<String, FilterConfig>emptyMap());
    FilterConfig f0 = mock(FilterConfig.class);
    when(f0.typeUrl()).thenReturn(filterType);
    return ServerRoutingConfig.create(ImmutableList.<VirtualHost>of(virtualHost), ImmutableMap.<Route, ServerInterceptor>of());
}
Also used : FilterConfig(io.grpc.xds.Filter.FilterConfig) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) RouteMatch(io.grpc.xds.VirtualHost.Route.RouteMatch)

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