Commit Graph

298 Commits

Author SHA1 Message Date
Terry Wilson 7665d3850b
Revert "Add LoadBalancer.acceptResolvedAddresses() (#8742)" (#9414)
This reverts commit 70a29fbfe3.
2022-07-28 12:15:26 -07:00
Terry Wilson 70a29fbfe3
Add LoadBalancer.acceptResolvedAddresses() (#8742)
Introduces a new acceptResolvedAddresses() to the LoadBalancer.

This will now be the preferred way to handle addresses from the NameResolver. The existing handleResolvedAddresses() will eventually be deprecated.

The new method returns a boolean based on the LoadBalancers ability to use the provided addresses. If it does not accept them, false is returned. LoadBalancer implementations using the new method should no longer implement the canHandleEmptyAddressListFromNameResolution(), which will eventually be removed, along with handleResolvedAddresses().

Backward compatibility will be maintained so existing load balancers using handleResolvedAddresses() will continue to work.

Additionally the previously deprecated handleResolvedAddressGroups() method is removed.
2022-07-26 09:23:37 -07:00
yifeizhuang 027d36eee7
xds: xdsNameResolver match channel overrideAuthority in virtualHost matching (#9405) 2022-07-22 12:41:16 -07:00
Benjamin Peterson 50ebb5f864
api: Link to Status#asRuntimeException method in StatusRuntimeException javadocs. (#9373) 2022-07-14 21:04:25 +05:30
DNVindhya ef89bd3ac9
gcp-observability: Populate global interceptors from observability (#9309)
* Populate global interceptors from observability and added stackdriver exporters
2022-07-14 19:38:00 +05:30
Eric Anderson 0ff9f37b9e Use Gradle's task configuration avoidance APIs
This can avoid creating an additional 736 tasks (previously 502 out of
1591 were not created). That's not all that important as the build time
is essentially the same, but this lets us see the poor behavior of the
protobuf plugin in our own project and increase our understanding of how
to avoid task creation when developing the plugin. Of the tasks still
being created, protobuf is the highest contributor with 165 tasks,
followed by maven-publish with 76 and appengine with 53. The remaining
59 are from our own build, but indirectly caused by maven-publish.
2022-07-08 12:16:40 -07:00
Eric Anderson e96d04774b okhttp: Add server implementation 2022-07-01 12:38:01 -07:00
sanjaypujare c9a52eb83f
api,core: change ManagedChannel and Server Builders to use GlobalInterceptors (#9312)
* api,core: change ManagedChannel and Server Builders to use GlobalInterceptors
also added a getter in GlobalInterceptors to expose the set flag
2022-06-30 10:11:58 -07:00
Eric Anderson 69abec5a28
api: Explain security constraints of ATTR_AUTHORITY_OVERRIDE
Half of the text was copied from NameResolver.getServiceAuthority().
However, that method can't perform I/O (which would block) so more text
was appropriate here to mention the implications of having a remote
service provide the authority.

I noticed the text was lacking while discussing #9266.
2022-06-22 13:16:42 -07:00
Eric Anderson b06942d63b Use Gradle's version catalog
This moves our depedencies into a plain file that can be read and
updated by tooling. While the current tooling is not particularly better
than just using gradle-versions-plugin, it should put us on better
footing. gradle-versions-plugin is actually pretty nice, but will be
incompatible with Gradle 8, so we need to wait a bit to see what the
future holds.

Left libraries as an alias for libs to reduce the commit size and make
it easier to revert if we don't end up liking this approach.

We're using Gradle 7.3.3 where it was an incubating fetaure. But in
Gradle 7.4 is became stable.
2022-06-14 14:04:10 -07:00
Sergii Tkachenko 9cebe0aa2b
api: Add missing RunWith annotation to GlobalInterceptorsTest (#9258)
Internal build failed with 

```
grpc/api/src/test/java/io/grpc/GlobalInterceptorsTest.java:28: error: 
[JUnit4RunWithMissing] Test class may not be run because it is missing a @RunWith annotation
public class GlobalInterceptorsTest {
       ^
  Did you mean '@RunWith(JUnit4.class)' or 'public abstract class GlobalInterceptorsTest {'?
```
2022-06-10 10:30:42 -07:00
DNVindhya 395fae59f0
api: Add GlobalInterceptors API (#9235)
* added GlobalInterceptors API
2022-06-09 16:27:25 -07:00
Eric Anderson 01faeee877 api: Document illegal arguments for server connection management APIs
Most are not allowed to be zero. Grace period can be zero to immediately
close the connection when the age is hit. A zero permitKeepAliveTime()
simply doesn't enforce any limits on the client.

The choices here precisely matches the pre-existing Netty behavior, but
also seems to make sense in general.
2022-06-06 11:09:14 -07:00
Eric Anderson a2c0ae3295 api: Document Attributes.Key uses reference equality
The text here should be expanded once `keys()` is removed. But for now
this at least can make it clearer that the current behavior is on
purpose. The text here is the same as that in CallOptions.Key.

See https://github.com/grpc/grpc-java/issues/1764#issuecomment-1144935608
2022-06-06 11:08:51 -07:00
Eric Anderson a206cda1a8 Change Attributes.Key debug strings to reference the API of the key
Users appear to be doing `attributes.toString()` to find keys they are
interested in and then unable to find the name of the Key in our API.
They workaround the problem by scanning through `attributes.keys()`
looking for the key of interest. This is an abuse of the keys() API and
unnecessary user friction. They'd happily use the API if they just knew
where to find it.

I added internal to some strings to make it clear that you shouldn't go
looking to use it. There were many strings I didn't change. I focused on
keys most likely to be seen by users, which meant keys in grpc-api and
keys that are available via transport attributes.

See https://github.com/grpc/grpc-java/issues/1764#issuecomment-1139250061
2022-06-02 16:11:02 -07:00
Ovidiu Tirla a88f19fb4b
Expose SecurityLevel on server-side (#8943) 2022-05-16 17:26:10 -07:00
Eric Anderson b5e78d548d api: Ignore ClassCastExceptions for hard-coded providers
This was observed in the Bazel/Blaze build where io.grpc.util is a
separate target from the rest of core. During the build of a library
SecretRoundRobinLoadBalancerProvider was not on the classpath, and the
library was later included into a binary using grpc-core from Maven
Central which includes SecretRoundRobinLoadBalancerProvider.

```
java.util.ServiceConfigurationError: Provider io.grpc.util.SecretRoundRobinLoadBalancerProvider$Provider could not be instantiated java.lang.ClassCastException: class io.grpc.util.SecretRoundRobinLoadBalancerProvider$Provider cannot be cast to some.app.aaa.aab
```
2022-05-16 13:19:46 -07:00
Eric Anderson ba57a1d893 api: Add connection management APIs to ServerBuilder
These APIs were added to NettyServerBuilder for gRFC A8 and A9. They are
important enough that they shouldn't require using the perma-unstable
transport API to access. This change also allows using these methods
with grpc-netty-shaded.

Fixes #8991
2022-05-16 13:02:09 -07:00
sanjaypujare 41c027c11b
netty: implement UdsNameResolver and UdsNettyChannelProvider (#9113)
* netty: implement UdsNameResolver and UdsNettyChannelProvider
When the scheme is "unix:" we get the UdsNettyChannelProvider to
create a NettyChannelBuilder with DomainSocketAddress type and
other related params needed for UDS sockets
2022-05-02 16:41:50 -07:00
Sergii Tkachenko 7dc4fc929c
xds, api: minor cleanup to address linter suggestions (#9116) 2022-04-27 13:02:46 -07:00
sanjaypujare 538db03d56
api: add support for SocketAddress types in ManagedChannelProvider (#9076)
* api: add support for SocketAddress types in ManagedChannelProvider
also add support for SocketAddress types in NameResolverProvider
Use scheme in target URI to select a NameRseolverProvider and get
that provider's supported SocketAddress types.
implement selection in ManagedChannelRegistry of appropriate
ManagedChannelProvider based on NameResolver's SocketAddress types
2022-04-22 09:10:55 -07:00
Eric Anderson 40c929e39f android: Use InternalManagedChannelProvider instead of reflection
This fixes up cda0e9d to be compatible with Proguard without
configuration. Since the methods are now accessed directly there is no
need for manual -keep configuration.
2022-03-31 11:52:57 -07:00
yifeizhuang 7eeb411b1f
doc: add comment about callOptions executor behavior (#8913) 2022-02-11 15:07:09 -08:00
sanjaypujare a661515421
observability: revert previous visibility changes made in the provider APIs (#8889)
change visibility back to protected for certain methods of Providers
2022-02-04 08:38:46 -08:00
sanjaypujare bd156f98d6
observability: implement and integrate LoggingServerProvider into Observability (#8879) 2022-02-01 10:05:59 -08:00
sanjaypujare 881f747b7e
observability: implement Observability.grpcInit() and LoggingChannelProvider (#8872) 2022-01-31 10:37:54 -08:00
Penn (Dapeng) Zhang cf4cd65707 Revert "all: clean up code related to android api level less than 19"
This reverts commit 3ad4d9bfb7.
2022-01-18 10:14:50 -08:00
Penn (Dapeng) Zhang 3179bc3be0 Revert "use charset from StandardCharsets instead of 'Charset.forName' (#8779)"
This reverts commit a74a3ad834.
2022-01-18 10:14:50 -08:00
Eric Anderson 58a7ace6ac
Bump ErrorProne to 2.10.0
Previous versions of error prone were incompatible with Java 17 javac.

In grpc-api, errorprone is now api dependency because it is on a public
API.  I was happy to see that Gradle failed the build without the dep
change, although the error message wasn't super clear as to the cause.

It seems that previously -PerrorProne=false did nothing. I'm guessing
this is due to a behavior change of Gradle at some point. Swapping to
using the project does build without errorProne, although the build
fails with Javac complaining certain classes are unavailable. It's
unclear why. It doesn't seem to be caused by the error-prone plugin.
I've left it failing as a pre-existing issue.

ClientCalls/ServerCalls had Deprecated removed from some methods because
they were only deprecated in the internal class, not the API. And with
Deprecated, InlineMeSuggester complained.

I'm finding InlineMeSuggester to be overzealous, complaining about
package-private methods. In time we may figure out how to use it better,
or we may request changes to the checker in error-prone.
2022-01-12 12:06:27 -08:00
Jintao a74a3ad834
use charset from StandardCharsets instead of 'Charset.forName' (#8779)
Co-authored-by: Penn (Dapeng) Zhang <zdapeng@google.com>
2022-01-07 15:03:14 -08:00
Eric Anderson d44de5069d
Bump to Gradle 6.9 and update plugins
These changes make the build compatible with Gradle 7, except for
Android which requires plugin updates.

I removed animalsniffer from binder because it did nothing (as there
were no signatures) and it was failing after setting toolVersion. It
failed because animalsniffer is only compatible with java plugin. After
this change I put the withId(animalsniffer) loading inside the
withId(java) to avoid a plugin ordering failure. That made it safe again
for binder to load animalsniffer, but it is still best to remove the
plugin from binder as it is misleading.

I did not upgrade Android plugin versions as newer versions (even 3.6)
require dealing with androidx (#8421).
2022-01-07 09:54:50 -08:00
ZHANG Dapeng 3ad4d9bfb7
all: clean up code related to android api level less than 19 2022-01-07 08:13:32 -08:00
ZHANG Dapeng 042f9879d4
all: remove deprecated StreamInfo.transportAttrs (#8768)
APIs such as `StreamInfo.getTransportAttrs()` were [deprecated](860e97d12a (diff-aa4049f54d6d5d462700e9221344184a37d2068b3ba7d715abd417b1df5bf883R114)) since 1.41.0. Removing now.
2021-12-20 09:46:25 -08:00
Terry Wilson fc57cad4ec
Revert "Revert "core/auth: Remove CallCredentials2 (#8464)"" (#8572)
This reverts commit a91cc85dfd.
2021-10-05 10:34:44 -07:00
Eric Anderson 816a54a83b api: Add doc snippet to convert types for defaultServiceConfig()
Tested with Jackson's `new ObjectMapper().readValue(json, Map.class)`.

Fixes #8300
2021-09-27 14:14:35 -07:00
Eric Anderson 192688f1f2 netty: Requests with Connection header are malformed
Although this is part of HTTP/2 and should have already been handled
already, it was noticed as part of RBAC work to avoid matching
hop-by-hop headers. See gRFC A41.

Also add a warning if creating Metadata.Key for "Connection". Use this
to try to help diagnose a client if it happens to blindly copy headers
from HTTP/1, as PROTOCOL_ERROR is hard to debug.

This rolls-forward 6e89919 after it was reverted in 7669656, now that
the test proxy has been fixed.
2021-09-27 12:59:15 -07:00
Zhouyihai Ding e41df60bea
core: change the mapping from ChannelLogLevel to java.util.logging.Level
Instead of `ChannelLogLevel.{DEBUG,INFO}` mapping to the same java level, `ChannelLogLevel.{WARNING,ERROR}` will shame the same java level. This allows us to be able to independently control the visibility of `ChannelLogLevel.DEBUG` logs which are the most verbose.
2021-09-22 09:43:08 -07:00
ZHANG Dapeng 29d238afca
api,stub: clarify StreamObserver and Listener param type (#8544) 2021-09-21 10:38:41 -07:00
Eric Anderson 7669656725 Revert "netty: Requests with Connection header are malformed"
This reverts commit 6e89919e32.

This was found to break a test proxy. We'll work on fixing the proxy and
then roll this forward again.
2021-09-15 15:20:40 -07:00
Terry Wilson 876f56e2ea
api: Stabilize the Status.asException() call. (#8520)
Removes the ExperimentalApi annotation from this call.

Contributes to: #4683
2021-09-13 14:54:25 -07:00
Eric Anderson 6e89919e32
netty: Requests with Connection header are malformed
Although this is part of HTTP/2 and should have already been handled
already, it was noticed as part of RBAC work to avoid matching
hop-by-hop headers. See gRFC A41.

Also add a warning if creating Metadata.Key for "Connection". Use this
to try to help diagnose a client if it happens to blindly copy headers
from HTTP/1, as PROTOCOL_ERROR is hard to debug.
2021-09-13 11:30:19 -07:00
Sergii Tkachenko a91cc85dfd
Revert "core/auth: Remove CallCredentials2 (#8464)"
This reverts commit 7cde473efa.
2021-09-02 17:20:20 -07:00
Terry Wilson 7cde473efa
core/auth: Remove CallCredentials2 (#8464)
- Removes CallCredentials2
- Removes CallCredentials2ApplyingTest
- Adds two tests from CallCredentials2ApplyingTest to CallCredentialsApplyingTest
- Updates GoogleAuthLibraryCallCredentials to extend from CallCredentials instead of CallCredentials2
2021-09-01 09:49:20 -07:00
ZHANG Dapeng bdf9a96476
core: enable retry by default (#8402)
Stabilize `enableRetry()` and `disableRetry()`.

Disable retry in `ManagedChannelImplTest` because each call attempt will fork the headers to a new instance, and add a ClientStreamTracer.Factory for bufferSizeLimit in CallOptions, which makes verification not straightforward.
2021-08-11 14:44:23 -07:00
ZHANG Dapeng fd2a58a55e
all: implement retry stats (#8362) 2021-08-11 10:24:37 -07:00
Eric Anderson 51d1484c3c api: Document that NameResolvers shouldn't block
Fixes #8190
2021-08-09 16:41:26 -07:00
Eric Anderson 0e7e0b4f57 api: Clarify Server APIs can be used before start()
Fixes #8349
2021-08-06 11:26:17 -07:00
Eric Anderson 62b4364a77 api: Fix Javadoc reference to NameResolver.Args
NameResolver.Helper was a short-lived class that didn't get very far. We
chose NameResolver.Args instead and didn't mirror LoadBalancer.
2021-08-02 13:09:40 -07:00
ZHANG Dapeng 860e97d12a
all: API refactoring in preparation to support retry stats (#8355)
Rebased PR #8343 into the first commit of this PR, then (the 2nd commit) reverted the part for metric recording of retry attempts. The PR as a whole is mechanical refactoring. No behavior change (except that some of the old code path when tracer is created is moved into the new method `streamCreated()`).

The API change is documented in go/grpc-stats-api-change-for-retry-java
2021-07-31 18:33:02 -07:00
John Cormie ecac0da655
Clarify the ServerCallHandler API contract. (#8339)
- Focus the summary fragment
- Clarify that implementations don't just have access to "call" and
"headers" while running -- they in fact take ownership of these
arguments from the caller.
- Make explicit the caller's obligation to the returned Listener.
- Clarify that "{@code call} will be closed with an error" is actually
an obligation placed on the caller (who may be a user-defined
ServerInterceptor).
2021-07-26 09:58:15 -07:00
yifeizhuang 4c1272febd
api: use <scheme,provider> map in nameResoverRegistry (#8323)
An improvement that makes name resolver provider scheme matching more explicit in name resolver registry.
2021-07-21 10:03:55 -07:00
yifeizhuang 6857d1b482
fix ServerBuilder callExecutor javadoc about direct executor (#8305) 2021-07-08 13:57:14 -07:00
yifeizhuang 7644350ecb
core: fix jumpstream listener not set when closing stream inline (#8290)
* Revert "core: rollback executor supplier, needs investigation (#8289)"

This reverts commit 1b57d48ac1.

* set jumpStream listener before close stream
2021-06-28 08:50:20 -07:00
yifeizhuang 1b57d48ac1
core: rollback executor supplier, needs investigation (#8289)
* Revert "core: fix boq conformance failures (#8281)"

This reverts commit c1ad5de135.

* Revert "core: allow per-service/method executor (#8266)"

This reverts commit c540229d79.
2021-06-25 13:10:45 -07:00
yifeizhuang c540229d79
core: allow per-service/method executor (#8266)
Add ServerCallExecutorSupplier interface in serverBuilder to allow defining which executor to to handle the server call.
Split StreamCreated() contextRunnable into two to support this new feature: one for method lookup, the other for server call handling. methodLookup() runs on default executor, handleServerCall() may run on the executorSupplier executor.
callbacks are queued after methodLookup() and handleServerCall() on serializing executor to ensure stream listener is set when callbacks starts running.
Make executor settable in serializing executor to allow switching executor for the server call handling runnable as a result of the outcome of the method lookup runnable.
2021-06-21 11:17:36 -07:00
Chengyuan Zhang 25122f9e83
api: clean up duplicated method in InternalServerInterceptors (#8261) 2021-06-15 15:11:56 -07:00
Eric Anderson 5642e01243
Replace failOnVersionConflict() with custom requireUpperBoundDeps
failOnVersionConflict has never been good for us. It is equivalent to
Maven dependencyConvergence which we discourage our users to use because
it is too tempermental and _creates_ version skew issues over time.
However, we had no real alternative for determining if our deps would be
misinterpeted by Maven.

failOnVersionConflict has been a constant drain and makes it really hard
to do seemingly-trivial upgrades. As evidenced by protobuf/build.gradle
in this change, it also caused _us_ to introduce a version downgrade.

This introduces our own custom requireUpperBoundDeps implementation so
that we can get back to simple dependency upgrades _and_ increase our
confidence in a consistent dependency tree.
2021-06-11 14:01:18 -07:00
Chengyuan Zhang e5d0e9d9a8
api, core: support zero copy into protobuf (#8102)
Enables a codepath for zero-copy protobuf deserialization. Two new InputStream extension interfaces are added:

- HasByteBuffer: allows access to the underlying buffers containing inbound bytes directly without copying
- Detachable: allows customer marshaller to keep the buffers around until the application code is done with using the protobuf messages

Applications can implement a custom marshaller that takes over the ownership of ByteBuffers and wrap them into ByteStrings with protobuf's UnsafeByteOperations support. Then a RopeByteString, which is a in-place composite of ByteStrings can be created. This enables using the zero-copy codepath (requires immutable ByteBuffer indication) of CodedInputStream for deserialization.
2021-05-14 14:45:03 -07:00
Eric Anderson e08b9db208
Use @DoNotCall for static methods in Builders that throw
Since static methods are pseudo-inherited by Builder implementations but
are trivially accidentally used, we re-define static methods in each
builder to make them behave more like the caller would expect. However,
not all the methods actually work; some just throw because the caller
was certainly not getting what they would expect.

Annotating with `@DoNotCall` can expose the problems at compile time
instead of runtime. While `@Deprecated` would also be an option, it is a
bit harder to figure out the ramifications and whether we want to go
that route.

This change was suggested by a lint tool for XdsServerBuilder and it
seems appropriate so I applied it to the other similar cases I could
find.
2021-05-12 10:12:52 -07:00
Eric Anderson 16eb5a47ec Stabilize ChannelCredentials
Some of the experimental API annotations were changed to other issues or
became `@Internal` to match their related APIs.

Fixes #7479
2021-05-03 16:22:43 -07:00
Eric Anderson d42f3b8fcb Stabilize ServerCredentials
Some of the experimental API annotations were changed to other issues or
became @Internal to match their related APIs.

Fixes #7621
2021-05-03 16:10:24 -07:00
Chengyuan Zhang 9614738a7d
core, grpclb, xds: let leaf LB policies explicitly refresh name resolution when subchannel connection is broken (#8048)
Currently each subchannel implicitly refreshes the name resolution when its state changes to IDLE or TRANSIENT_FAILURE. That is, this feature is built into subchannel's internal implementation. Although it eliminates the burden of having LB implementations refreshing the resolver when connections to backends are broken, this is gives LB policies no chance to disable or override this refresh (e.g., in some complex load balancing hierarchy like xDS, LB policies may embed a resolver inside for resolving backends so the refreshing resolution operation should be hooked to the resolver embedded in the LB policy instead of the one in Channel).

In order to make this transition smoothly, we add a check to SubchannelImpl that checks if the LoadBalancer has explicitly called Helper.refreshNameResolution for broken subchannels created by it. If not, it logs a warning and do the refresh.

A temporary LoadBalancer.Helper API ignoreRefreshNameResolution() is added to avoid false-positive warnings for xDS that intentionally does not want a refresh. Once the migration is done, this should be deleted.
2021-04-16 10:49:06 -07:00
yifeizhuang 6a9c9901e4
grpclb: support multiple authorities in lb backends for all SRV records (#7951) 2021-03-11 13:29:41 -08:00
Chengyuan Zhang b5c0a4a97a Make addServices() a final method on ServerBuilder and delete from its forwarders. 2021-03-05 10:03:22 -08:00
Chengyuan Zhang 37b94b3074
api: delete deprecated NameResolver APIs (#7936)
Deletes deprecated (~2 years) NameResolver APIs that uses NameResolver.Helper/Attributes for passing information from Channel to resolver.
2021-03-04 13:08:18 -08:00
Chengyuan Zhang a598b973a3
api: add ServerBuilder.addServices() API (#7926) 2021-02-28 23:36:27 -08:00
Eric Anderson d937ec5baf api: Add mTLS and Trust/KeyManager Credentials API 2021-02-19 09:30:24 -08:00
Serhii Zabelnykov 9ba419adc0
api: add nullable annotation to trailersFromThrowable (#7856) 2021-02-08 23:39:38 -08:00
Sergii Tkachenko 461b10a907 services: add support for channelz.GetServer() 2021-02-01 19:33:16 -05:00
ZHANG Dapeng 92e7fd370b
core: user is responsible to override authority for resolvingOobChannelBuilder
ManagedChannelImpl should not override authority for createResolvingOobChannel(target, creds), because ManagedChannelImpl does not know what target and creds are.
2021-01-29 09:50:59 -08:00
ZHANG Dapeng 9437783838
core: enhance ManagedChannelBuilder.overrideAuthority()
Enhance `ManagedChannelBuilder.overrideAuthority()` to make it impossible to use a different authority to a backend by wrapping ClientTransportFactory.newClientTransport() and setting ClientTransportOptions’ authority. To avoid confusing the LB policy, it would need to keep the original addresses to return during `Subchannel.getAddresses()`

The class `OverrideAuthorityNameResolverFactory` is deleted and its logic is moved into `ManagedChannelImpl`.
2021-01-29 09:29:06 -08:00
Nick Hill 2072df9be6
Random acts of garbage reduction
I noticed some opportunities to reduce allocations on hot paths
2021-01-21 10:45:31 -08:00
Eric Anderson 03d04f1944 api: Reword retry javadoc to make clear service config is source of configuration
Multiple users have tried things like
`mcb.enableRetry().maxRetryAttempts(3)` and been confused when no
retries were performed. Providing a reference to the gRFC and
`defaultServiceConfig()` should greatly increase the clarity of how to
use the method.
2021-01-13 11:36:08 -08:00
Chengyuan Zhang b66d182bb9
api: delete LoadBalancer.Helper APIs that had been deprecated for a long time (#7793) 2021-01-11 15:25:35 -08:00
ZHANG Dapeng ccef406f89
api: fix LoadBalancer javadoc 2021-01-05 13:12:06 -08:00
Eric Anderson b3899087d0 api: Improve code clarity by using Arrays.copyOf()
As noticed by a linter
2020-12-23 13:08:01 -08:00
ZHANG Dapeng 90d61178a3
all: ChannelCredentials.withoutBearerTokens() and LoadBalancer.Helper API change (#7748)
API change (See go/grpc-rls-callcreds-to-server):

- Add `ChannelCredentials.withoutBearerTokens()`
- Add `createResolvingOobChannelBuilder(String, ChannelCredentials)`, `getChannelCredentials()` and `getUnsafeChannelCredentials()` for `LoadBalancer.Helper`

This PR does not include the implementation of `createResolvingOobChannelBuilder(String, ChannelCredentials)`.
2020-12-22 22:48:39 -08:00
ZHANG Dapeng af29777686
all: migrate to interceptor-based config selector
This is migration following #7610
2020-12-04 11:11:57 -08:00
ZHANG Dapeng ac2327deb7
api,core: interceptor-based config selector (#7610)
Interceptor-based config selector will be needed for fault injection.

Add `interceptor` field to `InternalConfigSelector.Result`. Keep `callOptions` and `committedCallback` fields for the moment, because it needs a refactoring to migrate the existing xds config selector implementation to the new API.
2020-11-30 09:16:22 -08:00
wanyingd1996 2bf5ef54da
api: Added documentation for Call onClose hanging problem 2020-11-19 12:45:16 -08:00
Sergii Tkachenko 79d2e0c326 core: fix typos in Forwarding* classes 2020-11-18 15:36:56 -05:00
Eric Anderson 980956d503 api: Expose ForwardingServerBuilder for XdsServerBuilder
This reduces ABI issues caused by returning the more precise
XdsServerBuilder in the API. See
https://github.com/grpc/grpc-java/issues/7552.
2020-11-18 11:31:24 -08:00
Eric Anderson 60319dad2d api: Add ServerCredentials 2020-11-13 11:13:33 -08:00
ST-DDT 566f16ea0b
api: Clarify expectations regarding ServerCall#close (#7580) 2020-11-02 11:13:36 -08:00
Sergii Tkachenko d314c68126
Fix builders ABI backward compatibility broken in v1.33.0
* fix channel builders ABI backward compatibility broken in v1.33.0
* fix server builders ABI backward compatibility broken in v1.33.0
* makes ForwardingServerBuilder package-private
2020-10-29 12:06:37 -04:00
ST-DDT b7355052c4
Add implementation note regarding server interceptors and thread locals 2020-10-13 13:11:16 -07:00
Chengyuan Zhang 7dbf6a2c1c
xds: clarify required and optional fields in config selector result (#7496) 2020-10-09 01:04:34 -07:00
Eric Anderson c8a94d1059 api: Add ChannelCredentials 2020-10-07 13:58:37 -05:00
Eric Anderson 4c1bab9ed5 Prepare for JUnit 4.13
It deprecates ExpectedException and Assert.assertThat(T, org.hamcrest.Matcher).
Without Java 8 we don't want to migrate away from ExpectedException at
this time. We tend to prefer Truth over Hamcrest, so I swapped the one
instance of Assert.assertThat() to use Truth. With this change we get a
warning-less build with JUnit 4.13. We don't yet upgrade because we
still need to support JUnit 4.12 for some use-cases, but will be able to
upgrade to 4.13 soon when they upgrade.
2020-09-28 17:07:50 -05:00
Chengyuan Zhang bf7a42dbd1
api, core: delete io.grpc.LoadBalancer.loadBalancingConfig attribute (#7440) 2020-09-18 12:54:48 -07:00
ZHANG Dapeng ee5b5929d5
api,netty: Fix TruthIncompatibleType 2020-09-15 11:22:44 -07:00
Philipp Kern 07012421ad
core: add accessor for bare method name in MethodDescriptor (#7339)
Added getBareMethodName and extractBareMethodName for accessing the unqualified method name.
2020-09-03 14:27:18 -07:00
Sergii Tkachenko 07b812b1f5 api, core: create ForwardingServerBuilder and ServerImplBuilder 2020-09-03 16:26:04 -04:00
Sergii Tkachenko 522e70d1d7 api: remove incomplete sentence in javadoc 2020-09-03 11:02:47 -04:00
Sergii Tkachenko 5cfbe1061a api: Fix a small typo in ForwardingChannelBuilderTest 2020-08-27 15:00:13 -04:00
Eric Anderson 03f83bbac2 api: Fix NameResolver.ConfigOrError javadoc
It appears getAttributes() javadoc was accidentally copied when
ConfigOrError was moved in commit 0244418d2. This restores the
documentation from before the move.
2020-08-24 10:24:23 -07:00
wanyingd1996 6eced95a54
api: removed deprecated method blockingExecutor (#7242) 2020-08-12 15:29:30 -07:00
Eric Anderson 020fb36753 Fix lint warnings 2020-08-07 14:49:50 -05:00
Eric Anderson e92b2275f9 Update to Error Prone 2.4
Most of the changes should be semi-clear why they were made. However, BadImport
may not be as obvious: https://errorprone.info/bugpattern/BadImport . That
impacted classes named Type, Entry, and Factory. Also
PublicContructorForAbstractClass:
https://errorprone.info/bugpattern/PublicConstructorForAbstractClass

The JdkObsolete issue is already resolved but is not yet in a release.
2020-08-06 10:56:16 -05:00
Eric Anderson 80d62bfce2 Upgrade to Mockito 3.3.3
verifyZeroInteractions has the same behavior as verifyNoMoreInteractions. It
was deprecated in Mockito 3.0.1 and replaced with verifyNoInteractions, which
does not change behavior depending on previous verify() calls. All instances
were replaced with verifyNoInteractions, except those in
ApplicationThreadDeframerTest which were replaced with verifyNoMoreInteractions
since there is a verify() call in `@Before`.
2020-08-06 10:49:23 -05:00
Chengyuan Zhang 1ed24feecd
xds: include a status for the result of ConfigSelector (#7260) 2020-07-30 15:21:38 -07:00
ZHANG Dapeng 9f56b8cea2
api: change ConfigSelector.Result to use callback instead of interceptor
We found that the interceptor approach for `ConfigSelector` would be adding a layer of indirection for no gain: The API Result selectConfig(LoadBalancer.PickSubchannelArgs args) consumes headers among other inputs, because route matching might need to match the headers; and the API produces ClientInterceptor among other outputs. But the headers is not available until clientCall.start(listner, headers), whereas the interceptor need be applied to the call before clientCall.start(). So the input is not available until the output is applied. That means we will need to delay calling the downstream newCall() (which will either be RealChannel or the interceptor) until start() is called.

So we want to change to the other approach similar to what c-core is taking: Have `Result(Object config, CallOptions, Runnable committedCallback)`, where CallOption is the selector modified CallOption, and committedCallback is used to monitor the call lifecycle.
2020-07-17 13:33:44 -07:00
ZHANG Dapeng d342b111f9
api: add InternalConfigSelector abstract class 2020-07-16 13:52:03 -07:00
Eric Anderson 2dab629a0a api: Deprecate ManagedChannelBuilder.nameResolverFactory
It has been our intention for years to remove nameResolverFactory. We should
make it clear to users to avoid new code depending on it and so they can tell
us why they need it so we can provide replacements.
2020-06-30 14:34:35 -05:00
Eric Anderson debc3cdc79 api: Add documentation for Provider SPI discovery 2020-06-30 14:34:35 -05:00
Jihun Cho f5258dca17
api,core: add LoadBalancer.Helper#createResolvingOobChannelBuilder api (#7136) 2020-06-17 12:36:14 -07:00
Elliotte Rusty Harold 417d7700dd
deps: Update guava to 29.0 (#7079) 2020-06-03 13:48:02 -07:00
Eric Anderson 146857952c api: Remove ref to deleted InternalNotifyOnServerBuild 2020-06-02 07:28:44 -07:00
Kun Zhang 96a32ed768
core/doc: clarify when ClientCall.cancel() can be called.
The original javadoc may be misunderstood as "one must call
halfClose() before calling cancel()".
2020-05-07 18:41:22 -07:00
ZHANG Dapeng 0044f8ce56
all: migrate gradle build to java-library plugin
- Use gradle configuration `api` for dependencies that are part of grpc public api signatures.
- Replace deprecated gradle configurations `compile`, `testCompile`, `runtime` and `testRuntime`.
- With minimal change in dependencies: If we need dep X and Y to compile our code, and if X transitively depends on Y, then our build would still pass even if we only include X as `compile`/`implementation` dependency for our project. Ideally we should include both X and Y explicitly as `implementation` dependency for our project, but in this PR we don't add the missing Y if it is previously missing.
2020-05-04 16:44:30 -07:00
ZHANG Dapeng ce9d217920
all: introduce gradle util functions to manage guava dependency
Define util function to exclude guava's transitive dependencies jsr305 and animal-sniffer-annotations, and always manually add them as runtimeOnly dependency. error_prone_annotations is an exception: It is also excluded but manually added not as runtimeOnly. It must always compile with guava, otherwise users will see warning spams if guava is in the compile classpath but error_prone_annotations is not.
2020-05-01 22:59:28 -07:00
Chengyuan Zhang a423900491
api, core, services: make ProtoReflectionService interceptor compatible (#6967)
Eliminate the hack of InternalNotifyOnBuild mechanism for letting ProtoReflectionService get access to the Sever instance, which makes ProtoReflectionService incompatible with server interceptors. This change put the Server instance into the Context and let the ProtoReflectionService RPC obtain it in its RPC Context. Also enhanced ProtoReflectionService so that one service instance can be used across multiple servers.
2020-05-01 10:39:38 -07:00
Eric Anderson 4674b27736 api,stub: Improve waitForReady documentation 2020-04-30 16:03:52 -07:00
Kun Zhang 54cac75d47
core: refine LoadBalancer javadoc (#6950)
Update renamed components and references to deprecated APIs.
2020-04-20 15:51:36 -07:00
Jihun Cho 68297d6d7c
core: implement Helper#createResolvingOobChannel (#6923) 2020-04-17 16:07:38 -07:00
ST-DDT c89bf49b6a
api: Fix javadoc reference to deprecated method (#6894) 2020-04-02 16:43:28 -07:00
Chris Nokleberg e081f414a7
core: copy the SchemaDescriptor when rebuilding descriptor (#6851)
useMarshalledMessages works by duplicating a ServerServiceDefinition while replacing just the marshallers. It currently does not copy over the SchemaDescriptors, which breaks at least the ProtoReflectionService.
2020-03-30 14:07:24 -07:00
Chris Nokleberg a4275b63f4
core: preserve KnownLength when wrapping InputStream (#6852)
useInputStreamMessages ensures that the InputStream supports marking by wrapping the stream in a BufferedInputStream if markSupported() returns false. This change uses a new subclass of BufferedInputStream that also implements KnownLength, when the original stream also implements KnownLength.
2020-03-30 10:09:15 -07:00
Eric Anderson 47d545ad70 api: Fix MethodType documentation overspecification
The server does not _have_ to wait until half close in CLIENT_STREAMING, and
commonly wouldn't in error cases. {client,server}SendsOneMessage were way
over-specifying the behavior and included unnecessary and incorrect words like
"immediately." Those methods shouldn't be the defining the behavior in that
much precision anyway; that would be the job of the individual enum values, if
anything.
2020-03-09 12:16:01 -07:00
Chengyuan Zhang 6a7e47b8a5
core, grpclb: change policy selection strategy for Grpclb policy (take two: move logic of querying SRV into Grpclb's own resolver) (#6723)
Eliminated the code path of resolving Grpclb balancer addresses in grpc-core and moved it into GrpclbNameResolver, which is a subclass of DnsNameResolver. Main changes:

- Slightly changed ResourceResolver and its JNDI implementation. ResourceResolver#resolveSrv(String) returns a list of SrvRecord so that it only parse SRV records and does nothing more. It's gRPC's name resolver's logic to use information parsed from SRV records.

- Created a GrpclbNameResolver class that extends DnsNameResolver. Logic of using information from SRV records to set balancer addresses as ResolutionResult attributes is implemented in GrpclbNameResolver only.

- Refactored DnsNameResolver, mainly the resolveAll(...) method. Logics for resolving backend addresses and service config are modularized into resolveAddresses() and resolveServiceConfig() methods respectively. They are shared implementation for subclasses (i.e., GrpclbNameResolver).
2020-03-02 01:03:25 -08:00
Jihun Cho 2162ad0436
service: HealthCheckingLoadBalancerFactory using its own attribute (#6704) 2020-02-28 17:11:20 -08:00
ZHANG Dapeng 5677a0b723
api,netty: fix MethodDescriptor and InternalKnownTransport for netty-shaded
Resolves #6765
2020-02-27 12:53:11 -08:00
Chengyuan Zhang 3955e4e184
api: fix Javadoc warnings. (#6763) 2020-02-26 11:51:01 -08:00
Eric Anderson dd8165b2a7 api: Add ExperimentalApi to Metadata.BinaryStreamMarshaller
This was missed in d1078591 and the API has not yet been released.
2019-12-27 13:33:46 -08:00
Jihun Cho 90969b3471
core: make service config error handling optional implementation (#6564) 2019-12-26 15:07:20 -08:00
ST-DDT 2afe13487c api: Fix javadoc for ManagedChannelBuilder#forTarget(String)
The dns scheme is only the default scheme with grpc-java. Other
libraries could add more NameResolvers and thus change the default. For
compatibility reasons, the schema should therefore be specified
explicitly.
2019-12-16 15:51:53 -08:00
Dounan Shi 9e02cf089e Gracefully shutdown example servers (#6512) 2019-12-13 16:19:45 -08:00
markb74 d107859145 Support for lazily serialized values in Metadata.
First add a new a Metadata.BinaryStreamMarshaller interface which
serializes to/from instances of InputStream, and a corresponding
Key.of() factory method.

Values set with this type of key will be kept unserialized internally,
alongside a reference to the Marshaller. A new method
InternalMetadata.serializePartial(), returns values which are either
byte[] or InputStream, and allows transport-specific handling of
lazily-serialized values.

For the regular serialize() method, stream-marshalled values will be
converted to byte[] via an InputStreams.
2019-12-12 15:34:30 -08:00
Tomo Suzuki 80699f8be9 all: bump Animal-sniffer-annotation to 1.18 (#6488) 2019-12-05 13:15:59 -08:00
Chengyuan Zhang eb21c646b2
api, core: make scheduled executor service accessible for NameResolver.Args (#6455)
Added new API on NameResolver.Args to access ScheduledExecutorService, which is wrapped transport executor.
2019-11-21 16:14:13 -08:00
ZHANG Dapeng 2d454d478c
Revert "Revert "all: remove deprecated usePlaintext(boolean)""
This reverts commit 316a739e67.
2019-11-18 16:53:52 -08:00
Chengyuan Zhang 86bfefdaf2
api, core: make channel logger accessible through NameResolver.Args (#6430) 2019-11-18 16:33:39 -08:00
Chengyuan Zhang 94eb93bd3a
api: enforce NameResolver.Args creation with builder (#6437) 2019-11-18 15:31:44 -08:00
Eric Anderson 4dba65bad4 api: Rename blockingExecutor to offloadExecutor
The API review for #6279 came up with a more meaningful name that
better explains the intent. A setter for the old name was left in
ManagedChannelBuilder to ease migration to the new name by current
users.
2019-11-04 13:16:08 -08:00
sanjaypujare 7dbf12fe2a
api,stub : fix 2 typos (CallCredentials2 to CallCredentials and javadoc comment in AbstractStub) (#6343) 2019-10-28 10:03:49 -07:00
Carl Mastrangelo 4503a233f4 api: stabilize safe and idempotent methods in MethodDescriptor 2019-10-22 10:59:11 -07:00
Jihun Cho ae11b9facc
api,core,stub: fix lint errors (#6305) 2019-10-18 17:30:00 -07:00
Jihun Cho eef47b26b8
core,grpclb: DnsNameResolver will use srv record by default if grpclb (#6298) 2019-10-18 13:00:47 -07:00
Eric Anderson 40f401d0e7 api: Clarify setting safe/idempotent may change other value 2019-10-17 10:01:34 -07:00
Eric Anderson 9eca2dcc4f api: Add ExperimentalApi annotations for blockingExecutor
These should have been present when initially added in #6238, but we forgot.
2019-10-16 13:58:55 -07:00
Eric Anderson 3ce5df3f78 api: Safe implies idempotent 2019-10-16 13:29:38 -07:00
Eric Anderson fa45a71ec9 api: Allow streaming methods to be safe 2019-10-16 10:08:42 -07:00
Grant Oakley adcfb3e623 api,core: Adds an Executor field to NameResolver.Args.
Adds an Executor to NameResolver.Args, which is optionally set on ManagedChannelBuilder. This allows NameResolver implementations to avoid creating their own thread pools if the application already manages its own pools.

Addresses #3703.
2019-10-14 08:46:26 -07:00
ZHANG Dapeng 316a739e67
Revert "all: remove deprecated usePlaintext(boolean)"
This reverts commit 296857b4e7.
2019-10-10 15:56:47 -07:00
ZHANG Dapeng 296857b4e7
all: remove deprecated usePlaintext(boolean) 2019-10-08 09:27:39 -07:00
ZHANG Dapeng 90b3c88fe2
api: avoid infinite loop in handleResolvedAddresses
If a `LoadBalancer` implementation does not override `handleResolvedAddressGroups()`, or overrides `handleResolvedAddressGroups()` but calls `super.handleResolvedAddressGroups()` at the beginning or the end, it will be trapped in an infinite loop.
2019-10-03 15:58:18 -07:00
Jihun Cho e9ac1b4a76
all: update modules to wait until other module's sourceSet is available (#6232) 2019-10-02 15:05:44 -07:00
ZHANG Dapeng 19b09160c9
all: stabilize ManagedChannelBuilder.usePlaintext() 2019-09-18 15:16:31 -07:00
Eric Anderson 2b945774b6 Apply animalsniffer plugin explicitly when needed 2019-09-13 09:42:17 -07:00
Eric Anderson 4215b80b81 Apply java plugin explicitly when needed 2019-09-13 09:42:17 -07:00