Commit Graph

1424 Commits

Author SHA1 Message Date
Carl Mastrangelo 6b0325c84f
core: normalize log statement callsite
Make the "logged" method be consistent, and refer to the public logging class name and method.  This makes the log statements return the same class name used to set the log level.  

Before:

```
190306 13:29:39.290:D 1 [io.grpc.internal.ChannelTracer.logOnly] [Channel<1>: (localhost:10000)] Channel for 'localhost:10000' created
190306 13:29:39.414:D 1 [io.grpc.internal.ChannelTracer.logOnly] [Channel<1>: (localhost:10000)] Exiting idle mode
190306 13:29:39.622:D 17 [io.grpc.internal.ChannelTracer.logOnly] [Channel<1>: (localhost:10000)] Resolved address: [[[/127.0.0.1:10000]/{}]], config={}
190306 13:29:39.623:D 17 [io.grpc.internal.ChannelTracer.logOnly] [Channel<1>: (localhost:10000)] Address resolved: [[[/127.0.0.1:10000]/{}]]
190306 13:29:39.624:D 17 [io.grpc.internal.ChannelTracer.logOnly] [Subchannel<3>] Subchannel for [[[/127.0.0.1:10000]/{}]] created
```

After:

```
190306 13:49:15.654:D 1 [io.grpc.ChannelLogger.log] [Channel<1>: (localhost:10000)] Channel for 'localhost:10000' created
190306 13:49:15.772:D 1 [io.grpc.ChannelLogger.log] [Channel<1>: (localhost:10000)] Exiting idle mode
190306 13:49:15.995:D 18 [io.grpc.ChannelLogger.log] [Channel<1>: (localhost:10000)] Resolved address: [[[/127.0.0.1:10000]/{}]], config={}
190306 13:49:15.995:D 18 [io.grpc.ChannelLogger.log] [Channel<1>: (localhost:10000)] Address resolved: [[[/127.0.0.1:10000]/{}]]
190306 13:49:15.997:D 18 [io.grpc.ChannelLogger.log] [Subchannel<3>] Subchannel for [[[/127.0.0.1:10000]/{}]] created
190306 13:49:15.999:D 18 [io.grpc.ChannelLogger.log] [Channel<1>: (localhost:10000)] Child Subchannel created
```
2019-03-06 15:29:46 -08:00
Carl Mastrangelo 5cc71f1de9
netty, core: pass log-only channel logger into transport 2019-03-06 11:49:42 -08:00
Kun Zhang b0bbd7537b
core/grpclb: propagation and parsing of grpclb config (#5419)
Make sure the config for grpclb is passed to the GrpclbLoadBalancer, which will support two child policies -- "round_robin" (default) and "pick_first".

Previously the presence of balancer addresses would dictate "grpclb" policy, despite of the service config. Service config will now take precedence instead.

Implement config parsing logic in GrpclbLoadBalancer. Per offline discussions with @markdroth and @ejona86, we will ignore configuration errors for now. The more appropriate config error handling is upcoming.
2019-03-05 15:39:48 -08:00
ZHANG Dapeng b7dd92e7bb
core: suppress android lint error for javax.naming.*
Resolves #5422
2019-03-05 14:46:38 -08:00
Carl Mastrangelo 801cc5c189
core,netty,okhttp: propagate the subchannel logger to the transport 2019-03-04 15:16:53 -08:00
Kun Zhang 2336eb6f57
test: test the header mutation inside newClientStreamTracer() (#5421)
newClientStreamTracer() is called from transport implementations, thus
needs to be tested in AbstractTransportTest.
2019-03-04 13:53:03 -08:00
Kun Zhang a15a3117de
core: deprecate LoadBalancer.Helper#getNameResolverFactory (#5418)
This was added for the potential use case of needing to resolve target
names (of the same scheme as the top-level channel's target's) in the
LoadBalancer.  Now actual use cases come up in xDS that we need to
resolve fully-qualified target strings with arbitrary schemes.  This
method has never been used and won't fit future uses because it's too
restrictive.
2019-03-04 13:37:49 -08:00
Kun Zhang 59a336c3ae
core: add internal transport attribute ATTR_CLIENT_EAG_ATTRS (#5420)
This is needed for GRPCLB pick_first support, which needs to attach
tokens to headers, and the tokens are per server. In pick_first, all
addresses are in a single Subchannel, thus the LoadBalancer needs to
know which backend is used for a new stream.
2019-03-04 12:38:26 -08:00
Kun Zhang 0e7b8fd9ef
core: add LoadBalancer.Helper#createResolvingOobChannel() (#5415)
This can be used by xds LoadBalancer to create a channel to the XDS
traffic director, as the service config will only specify the target
name of the balancer.

This PR only adds the interface to unblock the xds work.
Implementation would take some time thus will come later.
2019-03-04 09:42:17 -08:00
Kun Zhang 02f55189aa
core: refactor load-balancing config handling (#5397)
The LoadBalancingConfig message, which looks like
```json
{
  "policy_name" : {
    "config_key1" : "config_value1",
    "config_key2" : "config_value2"
   }
}
```
appears multiple times. It gets super tedious and confusing to handle, because both the whole config and the value (in the above example is `{ "config_key1" : "config_value1" }`) are just `Map<String, Object>`, and each user needs to do the following validation:
 1. The whole config must have exactly one key
 2. The value must be a map

Here I define `LbConfig` that holds the policy name and the config value, and a method in `ServiceConfigUtil` that converts the parsed JSON format into `LbConfig`.

There is also multiple cases where you need to handle a list of configs (top-level balancing policy, child and fallback policies in xds, grpclb child policies). I also made another helper method in `ServiceConfigUtil` to convert them into `List<LbConfig>`.

Found and fixed a bug in the xds code, where the top-level balancer should pass the config value (excluding the policy name), not the whole config to the child balancers. Search for "supported_1_option" in the diff to see it in the tests.
2019-03-01 19:05:33 -08:00
Kun Zhang 8806403b3a
core: remove unnecessary private method (#5417) 2019-03-01 17:28:30 -08:00
Eric Anderson a818c81a71 testing: Move AbstractTransportTest to core to avoid Truth dep
Fixes #5301
2019-02-28 21:33:19 -07:00
Carl Mastrangelo c5d2d483e2
all: try out mockito rule 2019-02-27 16:40:47 -08:00
Nguyen Quang Huy 69a4917a8c doc: Remove some duplicated words in comment
Correct spelling for code comment.
2019-02-25 10:18:52 -08:00
Kun Zhang 83b92cfc9f
core: pass transport attributes to ClientStreamTracer.Factory.newClientStreamTracer() (#5380)
This will be a new override.  The old override is now deprecated.

In order to pass new information without adding new overrides, I shoved most information
into an object called StreamInfo.  The Metadata is left out to draw attention because
it's mutable.

Motivation: this is needed for correctly supporting pick_first in GRPCLB.  GRPCLB needs to
add a token to the headers, and the token varies among servers.  With round_robin, GRPCLB
create a Subchannel for each server, thus can attach the token when the Subchannel is picked.
To implement pick_first, all server addresses will be put in a single Subchannel, we will
need to add the header in newClientStreamTracer(), by looking up the server address from
the transport attributes and deciding which token to add.
2019-02-21 11:13:51 -08:00
Kun Zhang 86f974333e
core: delete deprecated ClientStreamTracer.Factory#newClientStreamTracer (#5377) 2019-02-20 12:07:15 -08:00
Kun Zhang b867f8e4fc
core: make NameResolver not thread-safe (#5364)
Resolves #2649

As a prerequisite, added `getSynchronizationContext()` to `NameResolver.Helper`.

`DnsNameResolver` has gone through a small refactor around the `Resolve` runnable, which makes it a little simpler.
2019-02-20 11:45:38 -08:00
Dan 05b6156d43 core: using correct key for hedging max attempts 2019-02-19 15:22:16 -08:00
Eric Anderson 9a38dea91c Revert "core: Update gRPC to use span kind and raw full method. (#5328)"
This reverts commit d47379947f.

This caused test failures internally, where gRPC failed with
"IllegalArgumentException: Invalid trace name". Not only was this
failure unexpected, it was also weird that it failed with an
IllegalArgumentException instead of the normal StatusRuntimeException.
2019-02-13 09:44:21 -08:00
Carl Mastrangelo 041cf2abd4
Start 1.20.0 development cycle 2019-02-12 14:46:28 -08:00
Eric Anderson 8d429ab056 core: Add "fake" dependency on Guava's failureaccess
This allows users to upgrade to newer versions of Guava without breaking
the build due to missing transitive dependencies. Without it, when
increasing the Guava version to 27.0+ you see errors like:

stub/src/main/java/io/grpc/stub/ClientCalls.java:487: error: cannot access InternalFutureFailureAccess
  private static final class GrpcFuture<RespT> extends AbstractFuture<RespT> {
                       ^
  class file for com.google.common.util.concurrent.internal.InternalFutureFailureAccess not found

Note that using a runtime_dep does not fix the compilation error.

Long-term we will want our users to migrate to
jvm_maven_import_external. However, if we use it ourselves, it will
effectively require our users to use it immediately themselves. It has
low penetration today, including lack of usage by tools like
johnynek/bazel-deps.

Fixes #5214
2019-02-12 14:17:28 -08:00
Kun Zhang e875a8c6a3
core: introduce NameResolver.Helper and deprecate the params on newNameResolver() (#5345)
Context: [#4159 (comment)](https://github.com/grpc/grpc-java/issues/4159#issuecomment-415827641)

`Attributes` is appropriate for plumbing optional objects, especially useful for a long plumbing path where components in the middle may not care or see all objects in the container. It's not the case for the `params` on `newNewResolver()`. Both the default port and the proxy detector are guaranteed to be there and the plumbing path is very short. In this case, a first-class object is more appropriate and easier to use.

The `Helper` will also have `getSynchronizationContext()` (#2649) and a method to parse and validate service config. We we also considering merging `Listener` into the `Helper`, to make `NameResolver` match the `LoadBalancer` API.
2019-02-12 10:14:59 -08:00
Eric Anderson 1bead99241 core: Place Nullable annotation before modifiers
Since Nullable is not a type annotation, it is normal to put it before any
modifiers (like "private"). This fixes a lint failure.
2019-02-11 17:11:51 -08:00
Bogdan Drutu d47379947f core: Update gRPC to use span kind and raw full method. (#5328) 2019-02-11 11:04:20 -08:00
Kun Zhang 138e958c4a
core: ProxiedSocketAddress on public API (#5344)
Combine the public `ProxyParameters` and the internal `ProxySocketAddress` as `HttpConnectProxiedSocketAddress`. The more specific name signifies the type of the proxy we currently support, and makes room for other proxy types (e.g., SOCKS) in the future. The combination simplifies NameResolver implementation.

Introduce `ProxiedSocketAddress` as the base class that is returned by `ProxyDetector`, mainly for clarification and documentation. Added documentation about proxy in general on `ProxyDetector`.
2019-02-11 09:56:59 -08:00
Kun Zhang 139e544338
core: RoundRobinLoadBalancer updates picker before shutting down subchannels. (#5338)
This should lower the chance of the race between the pick and the
shutdown (#2562).
2019-02-07 15:57:41 -08:00
Michael Plump bcb11b1155 core: add @CheckReturnValue to Status. 2019-02-07 14:00:10 -08:00
Carl Mastrangelo c958cce744
core: fix tracking issue for port listener 2019-02-07 11:07:44 -08:00
Carl Mastrangelo f6ec07d87d
core,netty: expose listening on multiple ports 2019-02-06 15:49:59 -08:00
kenji yoshida 6b68d874f5 core: fix typo. s/intercepter/interceptor/ 2019-02-06 09:22:45 -08:00
ZHANG Dapeng ea8968beed
xds: implement xds plugin selection
- defined XdsLbState, playing a similar role to GrpclbState
- there are two modes of XdsLbState: STANDARD and CUSTOM
- on `XdsLoadBalancer.handleResolvedAddressGroups()`, the `xdsLoadBalancer` will update the `xdsLbState` based on the lb config in the attributes passed in
2019-02-05 14:07:09 -08:00
Carl Mastrangelo 3a39b81cf5
all: remove java6 type args 2019-02-04 10:03:50 -08:00
Tim van der Lippe a31473ef20 all: fix usages of any(<Primitive>.class) matchers
In Mockito 2, if a method expects a primitive type, but an any(<Primitive>.class) matcher is used in its place, it will throw an error. To prepare for this upcoming breakage, change
all existing any(<Primitive>.class) matchers to use the correct any<Primitive>() matcher.
2019-02-04 09:01:00 -08:00
ZHANG Dapeng 0dbab26bb4
all: fix lint 2019-02-01 17:06:27 -08:00
Eric Anderson ddb16c5b4b Upgrade Guava to 26.0-android
This reverts commit 4adcf24363. The downgrade of
Guava has gone out in a release, so we can upgrade it again in the next
release.
2019-02-01 10:16:38 -08:00
Eric Anderson c75d9bc19f core: Fix racy creation/set of the retry Future
This fixes two races: a data race where scheduledRetry is accessed
by cancel() and confusion where scheduledRetry could be set to null by
the schedule()d runnable before it is set by the schedule() return
value.

Although it seems these races can't actually cause problems due to other
conditions/constraints, it's hard to reason about. So let's plug these
preemptively, even if we can't add tests that trigger them.

ScheduledHedging was not specific to hedging, so can now be reused for
this retry case. It was renamed to avoid being misleading.
2019-01-31 16:24:34 -08:00
ZHANG Dapeng d0ecc08705
all: fix lint 2019-01-31 09:31:13 -08:00
Carl Mastrangelo ed0a9f3f1d
netty: support listening on multiple ports 2019-01-29 10:13:40 -08:00
Carl Mastrangelo 27253353e7
core: fix service config prefix matching in Dns
Fixes #5280
2019-01-28 12:46:23 -08:00
Eric Gribkoff ce2ae1fb6c
core: remove channel reference from ManagedChannelWrapper (#5283)
This avoids a memory leak when the channel itself participates in a
reference cycle (e.g., when an interceptor retains a reference to an
Android app's context). With the current implementation, the static
`ManagedChannelOrphanWrapper.refs` map will keep the channel reachable
and prevent the ref cycle from being GCed.
2019-01-25 16:36:04 -08:00
Carl Mastrangelo f6689a1f86
all: fix lint errors 2019-01-25 16:09:59 -08:00
Eric Gribkoff 1d97b50315
core: do not lose status when RST_STREAM with NO_ERROR received (#5264) 2019-01-24 08:50:09 -08:00
Ignacio del Valle Alles 3a38e59bae core: Allow specifying a ProxyDetector per ManagedChannel 2019-01-23 16:57:40 -08:00
Carl Mastrangelo 3d2e375aa1
core: drop VisibleForTesting on ServiceConfigUtil 2019-01-23 15:10:50 -08:00
Eric Anderson 5dbe53c050 core: Remove incorrect usages of VisibleForTesting
The visibility is (correctly) used in non-testing scenarios.
2019-01-15 18:58:43 -08:00
Eric Anderson ca41aeaac9 core: Use Truth's isEmpty/hasSize
It produces clearer result error messages where there are failures.
2019-01-14 17:00:16 -08:00
Eric Anderson bcd2372280 core: disable SRV records lookup
SRV has not yet been enabled in a release. Since work is rapidly
underway to replace GRPC-LB with a service config+XDS-based solution,
there's now thoughts that we won't ever enable grpclb by default (but
may allow it to be automatically enabled when using GoogleDefaultChannel
or similar). Since things are being worked out, disable it.

This effectively reverts c729a0f.
2019-01-11 15:13:33 -08:00
Kun Zhang 1ed196c585
core: promote the new API in CallCredentials2 (#5216)
This is the 3rd step of #4901

- The deprecated `CC.applyRequestMetadata(... Attributes ...)` is now **replaced** by the new API `CC.applyRequestMetadata(... CC.MetadataApplier ...)` transformed from `CC2.applyRequestMetadata(... CC2.MetadataApplier ...)`.
- The Attributes keys in `CallCredentials` were deprecated, and now deleted.
- The deprecated interface `CC.MetadataApplier` is **replaced** by an equivalent abstract class.
- `CallCredentials2` is now marked as deprecated, while keeping its interface intact so that it won't break current implementations that are still on `CallCredentials2`.
- From this point on, implementations should do a one-line change from `extends CallCredentials2` to `extends CallCredentials`
- `GoogleAuthLibraryCallCredentials` is kept as `CallCredentials2` for now, as there is an internal consumer that expects it to be `CallCredentials2`.
2019-01-10 15:16:18 -08:00
Kun Zhang 7475b7f110
core: fix a channel panic bug caused by calling NameResolver.refresh() when it's not started (#5223)
Resolves #5222
2019-01-10 11:28:58 -08:00
Eric Anderson 4adcf24363
Downgrade to Guava 25.1
This is temporary for the 1.18 release to give users a bit more time to
get past the breaking changes to Beta APIs in Guava 26.

Fixes #5166
2019-01-08 16:22:48 -08:00