From c3ef7a5d945ba4fdb620b8c62cd74e1404a59478 Mon Sep 17 00:00:00 2001 From: Jonathan Knight Date: Wed, 13 Dec 2023 10:51:23 +0300 Subject: [PATCH] Update gRPC version to 1.60.0 (#8113) Fixes issue #8106 --- config/etcd/pom.xml | 8 ++- config/etcd/src/main/java/module-info.java | 6 +- dependencies/pom.xml | 2 +- .../grpc/client/GrpcChannelDescriptor.java | 12 +++- .../grpc/client/GrpcChannelsProvider.java | 3 +- grpc/client/src/main/java/module-info.java | 5 +- .../grpc/client/GrpcChannelsProviderIT.java | 42 +++++++++++-- .../grpc/client/GrpcChannelsProviderTest.java | 3 +- grpc/core/pom.xml | 46 ++++---------- grpc/core/src/main/java/module-info.java | 10 +-- grpc/io.grpc/pom.xml | 5 ++ grpc/io.grpc/src/main/java/module-info.java | 21 +++++++ .../grpc/server/GrpcServerBasicConfig.java | 20 +++++- .../grpc/server/GrpcServerConfiguration.java | 63 ++++++++++++++++++- .../helidon/grpc/server/GrpcServerImpl.java | 7 ++- grpc/server/src/main/java/module-info.java | 11 +++- .../server/GrpcServerConfigurationTest.java | 37 ++++++++++- .../client/src/main/java/module-info.java | 3 +- .../server/src/main/java/module-info.java | 2 +- 19 files changed, 244 insertions(+), 62 deletions(-) create mode 100644 grpc/io.grpc/src/main/java/module-info.java diff --git a/config/etcd/pom.xml b/config/etcd/pom.xml index 5661376ac64..b96d715d7cb 100644 --- a/config/etcd/pom.xml +++ b/config/etcd/pom.xml @@ -57,8 +57,12 @@ - io.helidon.grpc - io.grpc + io.grpc + grpc-api + + + io.grpc + grpc-core io.grpc diff --git a/config/etcd/src/main/java/module-info.java b/config/etcd/src/main/java/module-info.java index b64d496119b..e1bb259277b 100644 --- a/config/etcd/src/main/java/module-info.java +++ b/config/etcd/src/main/java/module-info.java @@ -24,9 +24,9 @@ requires java.logging; requires transitive io.helidon.config; requires etcd4j; - requires grpc.protobuf; - requires grpc.stub; - requires grpc.api; + requires io.grpc.protobuf; + requires io.grpc.stub; + requires io.grpc; requires com.google.protobuf; requires com.google.common; requires io.helidon.common; diff --git a/dependencies/pom.xml b/dependencies/pom.xml index bd34c159328..68ae9b0c4c8 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -61,7 +61,7 @@ 18.6 18.3 2.9.0 - 1.57.1 + 1.60.0 32.0.1-jre 2.1.212 1.3 diff --git a/grpc/client/src/main/java/io/helidon/grpc/client/GrpcChannelDescriptor.java b/grpc/client/src/main/java/io/helidon/grpc/client/GrpcChannelDescriptor.java index 25e5324e91e..451ef1c5226 100644 --- a/grpc/client/src/main/java/io/helidon/grpc/client/GrpcChannelDescriptor.java +++ b/grpc/client/src/main/java/io/helidon/grpc/client/GrpcChannelDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -102,9 +102,14 @@ public Optional loadBalancerPolicy() { /** * Get the {@link NameResolver.Factory} to use. + *

+ * This method is deprecated due to the deprecation of the + * {@link io.grpc.ManagedChannelBuilder#nameResolverFactory(io.grpc.NameResolver.Factory)} + * method in the gRPC Java API. * * @return the optional {@link NameResolver.Factory} to use */ + @Deprecated public Optional nameResolverFactory() { return Optional.ofNullable(nameResolver); } @@ -223,11 +228,16 @@ public Builder loadBalancerPolicy(String policy) { /** * Set the {@link io.grpc.NameResolver.Factory} to use. * @param factory the {@link io.grpc.NameResolver.Factory} to use + *

+ * This method is deprecated due to the deprecation of the + * {@link io.grpc.ManagedChannelBuilder#nameResolverFactory(io.grpc.NameResolver.Factory)} + * method in the gRPC Java API. * * @return this instance for fluent API * * @see io.grpc.ManagedChannelBuilder#nameResolverFactory(io.grpc.NameResolver.Factory) */ + @Deprecated public Builder nameResolverFactory(NameResolver.Factory factory) { this.nameResolver = factory; return this; diff --git a/grpc/client/src/main/java/io/helidon/grpc/client/GrpcChannelsProvider.java b/grpc/client/src/main/java/io/helidon/grpc/client/GrpcChannelsProvider.java index bc00b92fcae..7a19015b6f8 100644 --- a/grpc/client/src/main/java/io/helidon/grpc/client/GrpcChannelsProvider.java +++ b/grpc/client/src/main/java/io/helidon/grpc/client/GrpcChannelsProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -155,6 +155,7 @@ Map channels() { return channelConfigs; } + @SuppressWarnings("deprecation") private ManagedChannel createChannel(GrpcChannelDescriptor descriptor) { ManagedChannelBuilder builder = descriptor.tlsDescriptor() .map(tlsDescriptor -> createNettyChannelBuilder(descriptor, tlsDescriptor)) diff --git a/grpc/client/src/main/java/module-info.java b/grpc/client/src/main/java/module-info.java index 892ea0dbaf4..51c41975be9 100644 --- a/grpc/client/src/main/java/module-info.java +++ b/grpc/client/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,9 @@ module io.helidon.grpc.client { exports io.helidon.grpc.client; + requires io.grpc.netty; + requires io.netty.handler; + requires transitive io.helidon.grpc.core; requires io.helidon.tracing; diff --git a/grpc/client/src/test/java/io/helidon/grpc/client/GrpcChannelsProviderIT.java b/grpc/client/src/test/java/io/helidon/grpc/client/GrpcChannelsProviderIT.java index f12cca78b13..d03e11ce3ed 100644 --- a/grpc/client/src/test/java/io/helidon/grpc/client/GrpcChannelsProviderIT.java +++ b/grpc/client/src/test/java/io/helidon/grpc/client/GrpcChannelsProviderIT.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,8 @@ import io.helidon.grpc.server.GrpcServerConfiguration; import io.grpc.EquivalentAddressGroup; import io.grpc.NameResolver; +import io.grpc.NameResolverProvider; +import io.grpc.NameResolverRegistry; import io.grpc.StatusRuntimeException; import io.netty.handler.codec.DecoderException; @@ -209,12 +211,11 @@ public void shouldConnectWithCaCertAndClientCertAndClientKeyTo2WaySslServer() th @Test public void shouldUseTarget() throws Exception { - FakeNameResolverFactory factory = new FakeNameResolverFactory(portNoSsl); + NameResolverRegistry.getDefaultRegistry().register(new FakeNameResolverProvider("foo", portNoSsl)); String channelKey = "ChannelKey"; GrpcChannelDescriptor.Builder builder = GrpcChannelDescriptor .builder() - .target("foo://bar.com") - .nameResolverFactory(factory); + .target("foo://bar.com"); GrpcChannelsProvider provider = GrpcChannelsProvider.builder() .channel(channelKey, builder.build()) @@ -304,6 +305,39 @@ public NameResolver.Args getArgs() { } } + private static class FakeNameResolverProvider extends NameResolverProvider { + private final String scheme; + private final int port; + private URI targetUri; + private NameResolver.Args args; + + public FakeNameResolverProvider(String scheme, int port) { + this.scheme = scheme; + this.port = port; + } + + @Override + protected boolean isAvailable() { + return true; + } + + @Override + protected int priority() { + return 0; + } + + @Override + public NameResolver newNameResolver(URI targetUri, NameResolver.Args args) { + this.targetUri = targetUri; + this.args = args; + return new FakeNameResolver(port); + } + + @Override + public String getDefaultScheme() { + return scheme; + } + } private static class FakeNameResolver extends NameResolver { private final int port; diff --git a/grpc/client/src/test/java/io/helidon/grpc/client/GrpcChannelsProviderTest.java b/grpc/client/src/test/java/io/helidon/grpc/client/GrpcChannelsProviderTest.java index c8f06bab816..2d5c099567e 100644 --- a/grpc/client/src/test/java/io/helidon/grpc/client/GrpcChannelsProviderTest.java +++ b/grpc/client/src/test/java/io/helidon/grpc/client/GrpcChannelsProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,6 +36,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; +@SuppressWarnings("deprecation") public class GrpcChannelsProviderTest { private static final String CLIENT_CERT = "ssl/clientCert.pem"; diff --git a/grpc/core/pom.xml b/grpc/core/pom.xml index 58c140e66b1..6408419d935 100644 --- a/grpc/core/pom.xml +++ b/grpc/core/pom.xml @@ -44,33 +44,27 @@ io.helidon.tracing helidon-tracing + - io.helidon.grpc - io.grpc + io.grpc + grpc-api + + + io.grpc + grpc-core + + + io.grpc + grpc-inprocess - io.grpc grpc-netty - - - io.grpc - grpc-core - - io.grpc grpc-services - - io.grpc - grpc-stub - - - io.grpc - grpc-core - com.google.j2objc j2objc-annotations @@ -80,29 +74,11 @@ io.grpc grpc-protobuf - - - io.grpc - grpc-core - - - io.grpc - grpc-api - - io.grpc grpc-stub - - io.grpc - grpc-core - - - io.grpc - grpc-api - com.google.j2objc j2objc-annotations diff --git a/grpc/core/src/main/java/module-info.java b/grpc/core/src/main/java/module-info.java index 97ccaffc9cb..93ee54203bd 100644 --- a/grpc/core/src/main/java/module-info.java +++ b/grpc/core/src/main/java/module-info.java @@ -31,11 +31,11 @@ requires io.helidon.common.context; requires io.helidon.common.http; - requires grpc.netty; - requires transitive grpc.protobuf; - requires grpc.protobuf.lite; - requires transitive grpc.stub; - requires transitive grpc.api; + requires io.grpc.netty; + requires transitive io.grpc.protobuf; + requires io.grpc.protobuf.lite; + requires transitive io.grpc.stub; + requires transitive io.grpc; requires io.netty.handler; requires io.netty.transport; requires transitive com.google.protobuf; diff --git a/grpc/io.grpc/pom.xml b/grpc/io.grpc/pom.xml index 29bed40781f..b3b962ef85c 100644 --- a/grpc/io.grpc/pom.xml +++ b/grpc/io.grpc/pom.xml @@ -32,6 +32,11 @@ Helidon grpc-java Bundle Bundle of grpc dependencies provided for backwards compatibility + + true + true + + io.grpc diff --git a/grpc/io.grpc/src/main/java/module-info.java b/grpc/io.grpc/src/main/java/module-info.java new file mode 100644 index 00000000000..4286e896ca2 --- /dev/null +++ b/grpc/io.grpc/src/main/java/module-info.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * The deprecated repackaged gRPC Module. + */ +module io.helidon.grpc.deprecated { +} diff --git a/grpc/server/src/main/java/io/helidon/grpc/server/GrpcServerBasicConfig.java b/grpc/server/src/main/java/io/helidon/grpc/server/GrpcServerBasicConfig.java index 244f64f35e5..45d0ae1cf3c 100644 --- a/grpc/server/src/main/java/io/helidon/grpc/server/GrpcServerBasicConfig.java +++ b/grpc/server/src/main/java/io/helidon/grpc/server/GrpcServerBasicConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package io.helidon.grpc.server; +import java.time.Duration; + import io.helidon.common.context.Context; import io.helidon.grpc.core.GrpcTlsDescriptor; import io.helidon.tracing.Tracer; @@ -42,6 +44,10 @@ public class GrpcServerBasicConfig private final Context context; + private final int maxRapidResets; + + private final Duration rapidResetCheckPeriod; + /** * Construct {@link GrpcServerBasicConfig} instance. * @@ -57,6 +63,8 @@ private GrpcServerBasicConfig(GrpcServerConfiguration.Builder builder) { this.tracingConfig = builder.tracingConfig(); this.workers = builder.workers(); this.tlsConfig = builder.tlsConfig(); + this.maxRapidResets = builder.maxRapidResets(); + this.rapidResetCheckPeriod = builder.rapidResetCheckPeriod(); } /** @@ -132,4 +140,14 @@ public int workers() { public GrpcTlsDescriptor tlsConfig() { return tlsConfig; } + + @Override + public Duration rapidResetCheckPeriod() { + return rapidResetCheckPeriod; + } + + @Override + public int maxRapidResets() { + return maxRapidResets; + } } diff --git a/grpc/server/src/main/java/io/helidon/grpc/server/GrpcServerConfiguration.java b/grpc/server/src/main/java/io/helidon/grpc/server/GrpcServerConfiguration.java index ac13a4ae89e..c692c947206 100644 --- a/grpc/server/src/main/java/io/helidon/grpc/server/GrpcServerConfiguration.java +++ b/grpc/server/src/main/java/io/helidon/grpc/server/GrpcServerConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package io.helidon.grpc.server; +import java.time.Duration; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; @@ -107,6 +108,21 @@ public interface GrpcServerConfiguration { */ GrpcTlsDescriptor tlsConfig(); + /** + * Returns the period for counting rapid resets (stream RST sent by client before any data have been sent by server). + * + * @return the period for counting rapid resets + */ + Duration rapidResetCheckPeriod(); + + /** + * Returns the maximum allowed number of rapid resets (stream RST sent by client before any data have been sent by server). + * When reached within {@link #rapidResetCheckPeriod()}, GOAWAY is sent to client and connection is closed. + * + * @return the maximum allowed number of rapid resets + */ + int maxRapidResets(); + /** * Creates new instance with default values for all configuration properties. * @@ -168,6 +184,10 @@ final class Builder implements io.helidon.common.BuilderISO_8601 Durations + * @see #maxRapidResets() + */ + @ConfiguredOption("PT30S") + public Builder rapidResetCheckPeriod(Duration rapidResetCheckPeriod) { + Objects.requireNonNull(rapidResetCheckPeriod); + this.rapidResetCheckPeriod = rapidResetCheckPeriod; + return this; + } + + /** + * Maximum number of rapid resets(stream RST sent by client before any data have been sent by server). + * When reached within {@link #rapidResetCheckPeriod()}, GOAWAY is sent to client and connection is closed. + * Default value is {@code 200}. + * + * @param maxRapidResets maximum number of rapid resets + * @return updated builder + * @see #rapidResetCheckPeriod() + */ + @ConfiguredOption("200") + public Builder maxRapidResets(int maxRapidResets) { + this.maxRapidResets = maxRapidResets; + return this; + } + /** * Configure the application scoped context to be used as a parent for webserver request contexts. * @param context top level context @@ -332,6 +385,14 @@ int workers() { return workers; } + int maxRapidResets() { + return maxRapidResets; + } + + Duration rapidResetCheckPeriod() { + return rapidResetCheckPeriod; + } + @Override public GrpcServerConfiguration build() { if (name == null || name.isEmpty()) { diff --git a/grpc/server/src/main/java/io/helidon/grpc/server/GrpcServerImpl.java b/grpc/server/src/main/java/io/helidon/grpc/server/GrpcServerImpl.java index 5b4debf3737..91a7d636625 100644 --- a/grpc/server/src/main/java/io/helidon/grpc/server/GrpcServerImpl.java +++ b/grpc/server/src/main/java/io/helidon/grpc/server/GrpcServerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; +import java.time.Duration; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -178,11 +179,15 @@ public CompletionStage start() { HandlerRegistry handlerRegistry = this.handlerRegistry; + int maxRapidResets = config.maxRapidResets(); + Duration rapidResetCheckPeriod = config.rapidResetCheckPeriod(); + server = configureNetty(builder) .directExecutor() .addService(healthService) .addService(ProtoReflectionService.newInstance()) .fallbackHandlerRegistry(handlerRegistry) + .maxRstFramesPerWindow(maxRapidResets, (int) rapidResetCheckPeriod.toSeconds()) .build() .start(); diff --git a/grpc/server/src/main/java/module-info.java b/grpc/server/src/main/java/module-info.java index 4e180ae8803..9ea7ea3968d 100644 --- a/grpc/server/src/main/java/module-info.java +++ b/grpc/server/src/main/java/module-info.java @@ -28,8 +28,15 @@ requires transitive io.helidon.health; requires io.helidon.tracing; - requires transitive grpc.services; - requires transitive grpc.core; + requires transitive io.grpc; + requires transitive io.grpc.inprocess; + requires transitive io.grpc.internal; + requires transitive io.grpc.services; + requires io.grpc.netty; + requires io.grpc.util; + requires io.netty.transport; + requires io.netty.handler; + requires io.netty.common; requires transitive microprofile.health.api; requires jakarta.annotation; diff --git a/grpc/server/src/test/java/io/helidon/grpc/server/GrpcServerConfigurationTest.java b/grpc/server/src/test/java/io/helidon/grpc/server/GrpcServerConfigurationTest.java index f5f95941aaa..791b1a2fa0e 100644 --- a/grpc/server/src/test/java/io/helidon/grpc/server/GrpcServerConfigurationTest.java +++ b/grpc/server/src/test/java/io/helidon/grpc/server/GrpcServerConfigurationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package io.helidon.grpc.server; +import java.time.Duration; import java.util.function.Supplier; import io.helidon.config.Config; @@ -220,4 +221,38 @@ public void shouldBuildFromConfig() { assertThat(serverConfig.useNativeTransport(), is(true)); assertThat(serverConfig.workers(), is(51)); } + + @Test + public void shouldHaveDefaultMaxRapidResets() { + GrpcServerConfiguration configuration = GrpcServerConfiguration.builder() + .build(); + + assertThat(configuration.maxRapidResets(), is(200)); + } + + @Test + public void shouldSetMaxRapidResets() { + GrpcServerConfiguration configuration = GrpcServerConfiguration.builder() + .maxRapidResets(19) + .build(); + + assertThat(configuration.maxRapidResets(), is(19)); + } + + @Test + public void shouldHaveDefaultRapidResetCheckPeriod() { + GrpcServerConfiguration configuration = GrpcServerConfiguration.builder() + .build(); + + assertThat(configuration.rapidResetCheckPeriod(), is(Duration.ofSeconds(30))); + } + + @Test + public void shouldSetRapidResetCheckPeriod() { + GrpcServerConfiguration configuration = GrpcServerConfiguration.builder() + .rapidResetCheckPeriod(Duration.ofSeconds(19)) + .build(); + + assertThat(configuration.rapidResetCheckPeriod(), is(Duration.ofSeconds(19))); + } } diff --git a/microprofile/grpc/client/src/main/java/module-info.java b/microprofile/grpc/client/src/main/java/module-info.java index 5a09aba5eeb..b23225d51c9 100644 --- a/microprofile/grpc/client/src/main/java/module-info.java +++ b/microprofile/grpc/client/src/main/java/module-info.java @@ -23,7 +23,8 @@ requires jakarta.cdi; requires jakarta.inject; - requires transitive grpc.core; + requires transitive io.grpc.inprocess; + requires transitive io.grpc.internal; requires transitive io.helidon.microprofile.grpc.core; exports io.helidon.microprofile.grpc.client; diff --git a/microprofile/grpc/server/src/main/java/module-info.java b/microprofile/grpc/server/src/main/java/module-info.java index cdc29dd2b16..9b28f9214b1 100644 --- a/microprofile/grpc/server/src/main/java/module-info.java +++ b/microprofile/grpc/server/src/main/java/module-info.java @@ -27,7 +27,7 @@ requires io.helidon.microprofile.server; requires io.helidon.config.mp; - requires grpc.protobuf.lite; + requires io.grpc.protobuf.lite; requires com.google.protobuf; requires java.logging;