Commit Graph

1575 Commits

Author SHA1 Message Date
Ran 20ba79e6e0
core: add accessor for perfmark (#5687)
* core: add accessor for perfmark

* core: update BUILD.bazel to exclude internal classes
2019-05-08 17:01:55 -07:00
Yang Song ea4e2bffec all: Upgrade OpenCensus versions. (#5657)
Also updated CensusModule to use the new helper methods ContextUtils.withValue() instead of directly manipulating the context keys. See census-instrumentation/opencensus-java#1864.
2019-05-08 16:05:37 -07:00
Kun Zhang f8d0868e1d
Revert "core: pass Subchannel state updates to SubchannelStateListener rather than LoadBalancer (#5503)" (#5684)
This reverts commit 62b03fd7e6.

Effectively reverts its follow-up commits:
dc218b6d4d
405d8c3865
44840fe813
2019-05-08 09:01:45 -07:00
Carl Mastrangelo a7660eeef7
core: factor service config state management out of ManagedChannelImpl 2019-05-07 08:36:11 -07:00
Kun Zhang 63f636b4b6
api: NameResolver.Args deprecates NameResolver.Helper. (#5664)
Having two Helpers (the other being LoadBalancer.Helper) is proven to
be confusing, and the one in NameResolver is fundamentally different
from the one from LoadBalancer, as the latter mutates the states while
the former doesn't. Renaming it to Args make it less awkward to
expose it to LoadBalancer, which is needed for creating NameResolvers
for per-locality routing in the XdsLoadBalancer.
2019-05-03 16:45:38 -07:00
Carl Mastrangelo 54a9a15ac4
core: perfmark API changes 2019-05-02 15:36:48 -07:00
NickUfer 6807f39155 Removes the class `io.grpc.internal.MoreThrowables` and replaces it with
`com.google.common.base.Throwables`
2019-05-02 14:23:09 -07:00
Kun Zhang 973885457f
core: change ClientStreamTracer.StreamInfo to a final class with a builder (#5648)
As we are now endorsing the wrapping of ClientStreamTracers by
providing ForwardingClientStreamTracer, there is a need for altering
StreamInfo, especially CallOptions before it's passed onto the
delegate.  A Builder class and a toBuilder() provides a robust way
to copy the rest of the fields.

This is a breaking change for anybody who creates StreamInfo, which is
unlikely in non-test code, because StreamInfo was added as late as
1.20.0.
2019-04-30 09:10:56 -07:00
Carl Mastrangelo ce6358e57f
core: add getService to MethodDescriptor 2019-04-24 17:45:41 -07:00
Carl Mastrangelo 4b2e60a06b
core: remove scopeid overloads of perfmark 2019-04-24 15:07:43 -07:00
Eric Anderson 187fe9e146 Lint fixes 2019-04-23 14:51:34 -07:00
Carl Mastrangelo 04e07034f3
all: update to truth 0.44 2019-04-23 10:50:49 -07:00
Eric Anderson f4d48fec62
core: Add NameResolverRegistry
NameResolverRegistry takes on all the logic previously in
NameResolverProvider. But it also allows manual registration of
NameResolvers, which is useful when the providers have complex
construction or need objects injected into them.

This also avoids a circular dependency during class loading since
previously loading any Provider searched for all Providers via
ClassLoader since ClassLoader handling was static within the parent
class.

Fixes #5562
2019-04-22 10:22:46 -07:00
Kun Zhang 39e66fa22b
core: delete ManagedChannelBuilder.loadBalancerFactory() and all deprecated factories (#5480)
This has been deprecated since 1.18.0
2019-04-17 14:46:19 -07:00
Carl Mastrangelo a395eec4a3
core: update LB and NR API names
Updates #1770
2019-04-17 12:45:29 -07:00
Eric Anderson 80c3c992a6 core: Move io.grpc to grpc-api
io.grpc has fewer dependencies than io.grpc.internal. Moving it to a
separate artifact lets users use the API without bringing in the deps.
If the library has an optional dependency on grpc, that can be quite
convenient.

We now version-pin both grpc-api and grpc-core, since both contain
internal APIs.

I had to change a few tests in grpc-api to avoid FakeClock. Moving
FakeClock to grpc-api was difficult because it uses
io.grpc.internal.TimeProvider, which can't be moved since it is a
production class. Having grpc-api's tests depend on grpc-core's test
classes would be weird and cause a circular dependincy. Having
grpc-api's tests depend on grpc-core is likely possible, but weird and
fairly unnecessary at this point. So instead I rewrote the tests to
avoid FakeClock.

Fixes #1447
2019-04-16 21:45:40 -07:00
Jihun Cho 71f32bb700
core: fix typo in comment (#5597) 2019-04-15 17:29:45 -07:00
Chengyuan Zhang 636161712d
core/util: create a ForwardingClientStreamTracer class for delegation use (#5589)
* core/util: create a ForwardingClientStreamTracer class for delegation use

* add ExperimentalApi annotation
2019-04-12 18:06:17 -07:00
Kun Zhang 62b03fd7e6
core: pass Subchannel state updates to SubchannelStateListener rather than LoadBalancer (#5503)
Resolves #5497

## Motivation

In hierarchical `LoadBalancer`s (e.g., `XdsLoadBalancer`) or wrapped `LoadBalancer`s (e.g., `HealthCheckingLoadBalancerFactory`, the top-level `LoadBalancer` receives `Subchannel` state updates from the Channel impl, and they almost always pass it down to its children `LoadBalancer`s.

Sometimes the children `LoadBalancer`s are not directly created by the parent, thus requires whatever API in the middle to also pass Subchannel state updates, complicating that API. For example, the proposed [`RequestDirector`](https://github.com/grpc/grpc-java/issues/5496#issuecomment-476008051) includes `handleSubchannelState()` solely to plumb state updates to where they are used. We also see this pattern in `HealthCheckingLoadBalancerFactory`, `GrpclbState` and `SubchannelPool`.

Another minor issue is, the parent `LoadBalancer` would need to intercept the `Helper` passed to its children to map Subchannels to the children `LoadBalancer`s, so that it pass updates about relevant Subchannels to the children.  Otherwise, a child `LoadBalancer` may be surprised by seeing Subchannel not created by it, and it's not efficient to broadcast Subchannel updates to all children.

## API Proposal
We will pass a `SubchannelStateListener` when creating a `Subchannel` to accept state updates, those updates could be directly passed to where the `Subchannel` is created, skipping the explicit chaining in the middle.

Also define a first-class object `CreateSubchannelArgs` to pass arguments for the reasons below:
1. It may avoid breakages when we add new arguments to `createSubchannel()`.  For example, a `LoadBalancer` may wrap `Helper` and intercept `createSubchannel()` in a hierarchical case. It may not be interested in all arguments. Passing a single `CreateSubchannelArgs` will not break the parent `LoadBalancer` if we add new fields later.
2. This also reduces the eventual size of Helper interface, as the convenience `createSubchannel()` that accepts one EAG instead of a List is no longer necessary, since that convenience is moved into `CreateSubchannelArgs`.

```java
interface SubchannelStateListener {
  void onSubchannelState(Subchannel subchannel, ConnectivityStateInfo newState);
}

abstract class LoadBalancer.Helper {
  abstract Subchannel createSubchannel(CreateSubchannelArgs args);
}

final class CreateSubchannelArgs {
  final List<EquivalentAddressGroup> getAddresses();
  final Attributes getAttributes();
  final SubchannelStateListener getStateListener();
  final class Builder () {
    ...
  }
}
```

The new `createSubchannel()` must be called from synchronization context, as a step towards #5015.

## How the new API helps

Most hierarchical `LoadBalancer`s would just let the listener from the child `LoadBalancer`s directly pass through to gRPC core, which is less boilerplate than before.

Without any effort by the parent, each child will only see updates for the Subchannels it has created, which is clearer and more efficient.

If a parent `LoadBalancer` does want to look at or alter the Subchannel state updates for its delegate (like in `HealthCheckingLoadBalancerFactory`), it can still do so in the wrapping `LoadBalancer.Helper` passed to the delegate by intercepting the `SubchannelStateListener`.

## Migration implications
Existing `LoadBalancer` implementations will continue to work, while they will see deprecation warnings when compiled:
 - The old `LoadBalancer.Helper#createSubchannel` variants are now deprecated, but will work until they are deleted. They create a `SubchannelStateListener` that delegates to `LoadBalancer#handleSubchannelState`.
 - `LoadBalancer#handleSubchannelState` is now deprecated, and will throw if called and the implementation doesn't override it. It will be deleted in a future release.

The migration for most `LoadBalancer` implementation would be moving the logic from `LoadBalancer#handleSubchannelState` into a `SubchannelStateListener`.
2019-04-12 10:58:09 -07:00
Kun Zhang 0244418d2d
core: Move ConfigOrError up level up. (#5578)
This class is used in other places than just NameResolver.Helper.  It
should not be an inner class of Helper.

Strictly speaking this is an API-breaking change.  However, this is
part of the service config error handling API that hasn't been done
yet.  Nobody has a legitimate reason to use it.
2019-04-10 16:28:23 -07:00
Kun Zhang 880cfd09cd
core: make the NameResolver.start() change backward compatible for forwarding callers. (#5561)
This will give time for pre-existing external callers (e.g.,
forwarding NameResolvers) to migrate to the new start().
2019-04-08 16:09:31 -07:00
Kun Zhang a157052117
core: make the LoadBalancer.handleResolvedAddressGroups() change backward compatible. (#5563)
This will give time for pre-existing external callers (e.g.,
forwarding LoadBalancers) to migrate to the new handleResolvedAddresses().
2019-04-08 15:34:52 -07:00
Kun Zhang 1e901d3b8c
core: make newNameResolver() change backward compatible for callers. (#5560)
We assumed that we were the only caller.  Turns out there are
forwarding NameResolver too.  Implementing the old override will give
them time to migrate to the new API.

Resolves #5556
2019-04-08 12:02:54 -07:00
Carl Mastrangelo 483697f754
core: change service config to ConfigOrError
Both the config and the error need to be passed to the managed channel so it can decide to keep or reject the config. Passing only the parsed object means the managed channel cannot implement the error handling gRFC.
2019-04-08 11:06:13 -07:00
Chengyuan Zhang 9a2ef07b71
core: use FakeClock.ScheduledExecutorService for KeepAliveManagerTest (#5501)
* core: use FakeClock.ScheduledExecutorService for KeepAliveManagerTest

* add annotation for accessing stopwatch in synchronized section only
2019-04-05 12:49:04 -07:00
ZHANG Dapeng 1c276a823b
core: refactor lookUpServiceConfig(boolean) to disableServiceConfigLookUp()
Refactor as discussed in #5189. Will backport to v1.20.0 to reduce a cycle of deprecation process.
2019-04-04 14:01:19 -07:00
Carl Mastrangelo faf6ff9f98
core: add client and server call perfmark annotations
This code is highly experimental, so we can change it at will later. This PR is to go ahead and try it out.

Perfmark task calls are added to the client and server calls public APIs, recording when the calls begin and end. They use separate scope IDs (roughly these are Thread IDs) for the listener and the call due to no synchronization between them. However, they both use the same PerfTags, which allows them to be associated.

In the future, we can plumb the tag down into the stream to include deeper information about whats going on in a call.
2019-04-03 18:16:22 -07:00
Carl Mastrangelo d8b5d84ce7
perfmark: add a perf annotation package 2019-03-29 11:29:36 -07:00
Carl Mastrangelo ecccdbb3b0
core: update since javadoc, and add toBuilder for NameResolver results 2019-03-29 10:43:08 -07:00
Carl Mastrangelo 17d67f17fa
all: add LoadBalancer overload for Resolution results 2019-03-29 09:31:24 -07:00
Kun Zhang 026e4c53bd
Start 1.21.0 development cycle (#5515) 2019-03-28 13:27:45 -07:00
Carl Mastrangelo 5ef8377efa
core: remove Type from ConfigOrError 2019-03-28 09:40:50 -07:00
Nick Hill 8e41f6e43b core: Avoid locks in SynchronizationContext (#5504)
Similar to what's done in SerializingExecutor, it's easy to make SynchronizationContext non-blocking.
2019-03-26 13:54:01 -07:00
Carl Mastrangelo 53f4ad21b4
core: fix DNS JNDI not working if there is an unavailability cause 2019-03-25 16:10:13 -07:00
Carl Mastrangelo f4a31ec62d
core: deprecate NR.L and add NR.Results 2019-03-22 16:38:28 -07:00
ZHANG Dapeng a2cda8d15d
all: fix lint 2019-03-20 09:01:25 -07:00
Tim van der Lippe d35fbd7eee all: Update to Mockito 2
This is the public port of cl/238445847

Fixes #5319
2019-03-19 14:17:52 -07:00
Carl Mastrangelo c6b505229c
all: move LB parsing logic into LB.Factory 2019-03-19 13:33:13 -07:00
Carl Mastrangelo 6b4a3796a6
core: change DNS error handling to fail on all invalid configs 2019-03-19 09:22:02 -07:00
ZHANG Dapeng 1735adc4c0
core: channelBuilder.defaulServiceConfig() and lookUpServiceConfig() 2019-03-14 16:57:16 -07:00
ZHANG Dapeng 283f04983b
core: reorder code in NameResolver.Listener.onAddress() 2019-03-13 16:54:10 -07:00
ZHANG Dapeng bd77e886d5
doc: s/<string>/<strong>/ in javadoc 2019-03-12 13:46:13 -07:00
Eric Anderson d7e53e871b
Merge pull request #5454 from ejona86/protobuf-3.7.0
Upgrade to Protobuf 3.7.0
2019-03-11 15:39:50 -06:00
Eric Anderson 57e94d19ea core: Document grpc does not perform compression nego on client 2019-03-11 15:36:21 -06:00
Eric Anderson 656dcc1c7c core,stub: Document grpc performs compression nego on server 2019-03-11 15:36:21 -06:00
ZHANG Dapeng 97ff7fe50a
core: fix thread safety in NameResolver.Listener 2019-03-11 14:35:49 -07:00
Jihun Cho 5ba6619ce5
all: fix lint error (#5464) 2019-03-11 13:58:37 -07:00
Jihun Cho b6d7f6e84f
all: fix lint errors (#5462) 2019-03-11 10:52:12 -07:00
Carl Mastrangelo 0c23735cfc
core: separate service config parsing and add NR.Helper method 2019-03-10 15:36:34 -07:00
Kun Zhang f095926d2c
core: stop catching exceptions from NameResolver.start() (#5452)
It's not supposed to throw. Any exception from it should be considered
a bug and deserves a panic.
2019-03-08 15:21:36 -08:00
Carl Mastrangelo e5e01b5169
core,grpclb: use better generics on service config 2019-03-08 14:11:13 -08:00
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
Eric Anderson e74576b85b Remove old BetaApi failure suppressions
We've been on newer versions of Guava for a while now; these no longer
do anything.

Reworded the comment for Stopwatch.createUnstarted(), because it is not
safe (it doesn't matter if the method isn't marked Beta; you have to use
Ticker), except for the fact it is only used in our tests.
2019-01-08 16:07:40 -08:00
ZHANG Dapeng 4337da6d7d
Start 1.19.0 development cycle 2019-01-02 15:31:01 -08:00
Carl Mastrangelo b6af40e510 examples,netty: fix lint errors 2019-01-02 15:30:31 -08:00
ZHANG Dapeng df21e40285
all: fix lint 2019-01-02 15:28:44 -08:00
Carl Mastrangelo a4859c1e93
core: revert stream tracer order change to fix internal test 2018-12-20 18:45:38 -08:00
David Hoover 87cf40437c core: Mark CallOptions' deadline/executor as @Nullable
They are, but weren't consistently marked like the other members
2018-12-19 15:47:54 -08:00
Carl Mastrangelo 6779a5aa75
core,netty: refactor server builder
* makes Census tracing factories at the end of the user added ones
* makes more vars in AbstractServerImplBuilder package private
* annotates methods in ASIB to be clearer
* simplifies several of the setters to be single line
* Makes the generics on the Tracer factories proper
2018-12-17 17:22:33 -08:00
Carl Mastrangelo 1bf8476cd7
core: standardize logid format and add details for channelz 2018-12-17 17:22:11 -08:00
ZHANG Dapeng 0cf91e333b
core: hide RetriableStream type from ClientTransportProvider 2018-12-12 10:04:39 -08:00
ZHANG Dapeng 07f96f8000
core: fix a typo in javadoc 2018-12-10 10:53:08 -08:00
Kun Zhang c0175e4cbe
core: add LoadBalancer.canHandleEmptyAddressListFromNameResolution() (#5148)
Currently ManagedChannelImpl will interpret empty address list from
NameResolver as an error, and LoadBalancer will NEVER receive an empty
list from handleResolvedAddressGroups().  There is a case in the
request-routing design where a LoadBalancer only receives service
config with which it constructs children NameResolver/LoadBalancer
pairs, thus no address is expected at this level.

canHandleEmptyAddressListFromNameResolution() is a signal to Channel
(and to the parent LoadBalancer in case of hierachical LoadBalancers)
about whether it accepts empty address lists.  The default is false,
which is the current behavior.

The logic is currently duplicated in ManagedChannelImpl and
AutoConfiguredLoadBalancer.  The one in ManagedChannelImpl will be
removed once we delete ManagedChannelBuilder.loadBalancerFactory() as
AutoConfiguredLoadBalancer will always be the top-level LoadBalancer
by then.
2018-12-10 10:18:19 -08:00
Grant Oakley 01f79bb909 core: fix bug in CallOptions#withOption()
Previously, overwriting an existing Key would cause the original CallOptions instance to also be mutated.

See #5142

Also adds a regression test for this issue.
2018-12-07 16:32:02 -08:00
Eric Anderson 1299986999 core: Fix reversed arguments to assertEquals 2018-12-07 11:37:21 -08:00
Kun Zhang 1fbf7bb3a7
core: add ManagedChannelBuilder.defaultLoadBalancingPolicy() (#5135)
ManagedChannelBuilder.loadBalancingFactory() overrides the proper
policy selection logic implemented in AutoConfiguredLoadBalancer, thus
has problems in cases where NameResolver returns balancer addresses,
because custom LoadBalancers normally don't differentiate between
normal server addresses with balancer addresses.  The policy selection
logic will filter out balancer addresses.
2018-12-07 08:30:58 -08:00
Eric Anderson de9bc0bcf1 Specify Locale to toLowerCase and lint fixes 2018-12-06 17:15:48 -08:00
Kun Zhang 4631c0c7e8
core: fix a bug that Channel won't work if NameResolver returns a ServiceConfig without LB config. (#5134) 2018-12-06 16:51:45 -08:00
Kun Zhang 0cc0f2d170
core: do not fail RPCs if balancer address exists but grpclb is unavailable (#5129)
When service owner turns on grpclb through service config, it
shouldn't break existing clients that don't have grpclb in their
classpath.

Resolves #4602
2018-12-06 13:40:30 -08:00
Carl Mastrangelo 2d654496ee
context: make Deadline toString() more readable 2018-12-05 17:44:44 -08:00
Kun Zhang 3a86a176fe
core: add LoadBalancer.Helper.refreshNameResolution() (#5121) 2018-12-05 13:11:45 -08:00
ST-DDT 0dda74dda4 core: Fix deprecation warning in RoundRobinLoadBalancerFactory 2018-12-05 10:03:02 -08:00
ZHANG Dapeng 0c95dad0da
core: fix bazel NameResolverProvider not found 2018-12-05 09:45:41 -08:00
Kun Zhang 5054aefe03
core: support LoadBalancingConfig from Service Config (#5073) 2018-12-04 16:56:06 -08:00
Kun Zhang b5acbedd55
core: record real-time metrics to OpenCensus (updated to 1.18.0) (#5099)
Real-time metrics are total sent/received bytes and messages per
method, and are updated as the events occur rather than at the end of
RPCs.
2018-11-29 16:30:58 -08:00
Kun Zhang 2961857451
core: refactor flags in CensusStatsModule. (#5095)
There are currently three boolean flags, and there will be one more
soon.  Put them all in the top-level class instead of passing them as
arguments on lower levels.
2018-11-28 14:20:40 -08:00
Kun Zhang 98ae834dfa
core: use SynchronizationContext.schedule() for NameResolver refresh (#5089)
This also fixes the bug where NameResolverRefresh is not run from
syncContext if run from ScheduledExecutorService.
2018-11-28 09:42:29 -08:00
Kun Zhang 3ff4790212
core: allow ClientStreamTracer to intercept trailers. (#5088)
This would allow LoadBalancers to intercept trailers which could carry
load information.
2018-11-27 12:47:31 -08:00
Kun Zhang c8b2cdc023
core/services: test/debug friendlier (#5079)
Raise visibility of AutoConfiguredLoadBalancerFactory as internal
tests need to access it from a different package.

Rename HealthCheckingLoadBalancerFactory.LoadBalancerImpl to
*.HealthCheckingLoadBalancer so that its toString() output is more
informative.
2018-11-21 10:45:18 -08:00
Kun Zhang 268793f321
core: add (de)register() in LoadBalancerRegistry. (#5070) 2018-11-20 12:07:31 -08:00
zpencer 777bbbb121
core: TimeProvider should not assume that the clock never changes (#4883)
We should reflect changes in the system clock.
2018-11-20 11:34:58 -08:00
ZHANG Dapeng 6b15aa9e4e
core: implement hedging 2018-11-20 09:38:01 -08:00
Jihun Cho 1506135333 Start 1.18.0 development cycle 2018-11-19 14:49:35 -08:00
Eric Anderson 033cf21118 core: Explicitly mention MCB.intercept's execution order
New users are much more likely to use MCB to add an interceptor instead
of ClientInterceptors, so may not be aware of the interesting execution
order.
2018-11-19 11:02:44 -08:00
Jihun Cho ab5257504b
core: use fakeClock in MessageDeframer tests to fix flaky test (#5055) 2018-11-14 15:13:10 -08:00
Kun Zhang 5b87e99622
core: move round-robin to util and include it to hard-coded list (#5057)
This is needed for internal issue b/119247688.

A particular test that runs GRPC Android build in a non-Android
environment failed because RoundRobinLoadBalancerProvider was deleted
by ProGuard but the service-loader META-INF file still referred to it,
causing a loading failure.

This could be fixed by adding RoundRobinLoadBalancerProvider to the
hard-coded list, which is recognized by ProGuard then it will keep the
class.

However, we don't expect anyone to use RoundRobinLoadBalancerProvider
on Android, including the class on Android would increase code size,
which Android apps are sensitive to. Hence we move
RoundRobinLoadBalancerProvider to a different package (util), which is
built as a separate artifact internally which Android users usually
don't depend on. (Note that in open-source util is in the same artifact as core,
which is unfortunately).
2018-11-13 17:06:01 -08:00
Rodrigo Queiro 8481943866 Add missing j2objc dependency to Bazel build
This avoids a warning when building artifacts that depend on Guava.

Fixes #5046.
2018-11-13 13:39:35 -08:00
Eric Anderson 7a89ce2a90 Lint fixes
Remove unused variables and prefer ArrayDeque to LinkedList. The swap to
Queue from Deque was just to make it more obvious what the usage was,
since the original swap to Deque was to avoid the same LinkedList lint
violation (3d51756d).
2018-11-09 17:15:25 -08:00
Yang Song 09b13fecaa core: Update OpenCensus version to 0.17.0 (#4494) 2018-11-09 16:44:01 -08:00
ZHANG Dapeng bff008fbc8
core: Emit bin-headers with unpadded encoding
Following the [grpc PROTOCOL-HTTP2 spec](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md)
"Note that HTTP2 does not allow arbitrary octet sequences for header values so binary header values must be encoded using Base64 as per https://tools.ietf.org/html/rfc4648#section-4. Implementations MUST accept padded and un-padded values and should emit un-padded values. "
2018-11-09 13:39:01 -08:00
Jihun Cho a7196eb311
core: remove I/O from DNS test which caused flaky test (#5044) 2018-11-07 16:00:26 -08:00
Carl Mastrangelo e7e88a9af8
core: narrow SharedResourceHolder types, and make the scheduler unconfigurable 2018-11-07 13:12:21 -08:00
Kun Zhang 6b48eb4e08
core: ChannelLogger (#5024)
Introduce ChannelLogger, which is a utility provided to LoadBalancer implementations (potentially NameResolvers too) for recording events to channel trace. This is immediately required by client-side health checking (#4932, https://github.com/grpc/proposal/blob/master/A17-client-side-health-checking.md) to record an error about disabling health checking. It is also useful for any LoadBalancer implementations to record important information.

ChannelLogger implementation is backed by the internal ChannelTracer/Channelz. Because Channelz limits the number of retained events, and events are lost once the process ends, I have expanded it to also log Java logger. This would provide a "last resort" in cases where there are too many events or off-line investigation is needed. All logs are prefixed with logId so that they can be easily associated with the involved Channel/Subchannel.

To prevent log spamming, the logs are all at FINE level or below so that they are not visible by default. They are logged to ChannelLogger's logger, so that user can have precise control.

There are also more verbose information that may not fit in ChannelTracer, but can be useful for debugging. It's desirable that these logs are associated with logId, but they currently manually include the logId, which is cumbersome and may result in inconsistency. For this use case, I added the DEBUG level for ChannelLogger, which formats the log in the same way as other levels, while not recorded to Channelz.

I have converted most logging and channel tracer recording in the Channel implementation and LoadBalancers.
2018-11-06 16:48:09 -08:00
Eric Anderson f8f86da480 core: Add missing synchronization in KeepAliveManager 2018-11-06 09:28:38 -08:00
Eric Anderson 424daa0920 core: Improve error for Auto-LB configuration failure
The ManagedChannelImpl change prevents any LB initialization failure
from producing a useless exception like:
java.lang.NullPointerException
	at io.grpc.internal.ManagedChannelImpl.shutdownNameResolverAndLoadBalancer(ManagedChannelImpl.java:321)
	at io.grpc.internal.ManagedChannelImpl.panic(ManagedChannelImpl.java:738)
	at io.grpc.internal.ManagedChannelImpl$1.uncaughtException(ManagedChannelImpl.java:144)

Instead, now it will have the expected panic behavior of an INTERNAL
Status with a proper cause.

Since the NPE in AutoConfiguredLoadBalancerFactory wouldn't mean much to
users, it now has a more explicit message.
2018-11-05 14:08:50 -08:00
ZHANG Dapeng 85b244bb41
core,netty,testing: Support dup headers joined with commas
Following the [spec](https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md) on duplicate header names:

**Custom-Metadata** header order is not guaranteed to be preserved except for values with duplicate header names. Duplicate header names may have their values joined with "," as the delimiter and be considered semantically equivalent. Implementations must split Binary-Headers on "," before decoding the Base64-encoded values.
2018-11-01 16:17:05 -07:00
zpencer 3d51756d61
core, services: fix more import lints (#5021) 2018-11-01 16:14:42 -07:00
Kun Zhang f5d0f40bdf
services: client-side health checking main implementation (#5014)
Spec: https://github.com/grpc/proposal/blob/master/A17-client-side-health-checking.md

This comes in the form of a wrapper LoadBalancerFactory. The public wrapping utility and the wrapping of RoundRobinLoadBalancer will come in follow-up changes.
2018-10-31 09:29:46 -07:00
zpencer f3e371c712
core, grpclb: fix import lints (#5017) 2018-10-30 14:24:02 -07:00
Kun Zhang 7d19683018
core: suggest LoadBalancer.Helper.createSubChannel() to be called from SynchronizationContext (#5016)
Because otherwise the user logic around Subchannel creation will
likely to race with handleSubchannelState().

Will log a warning if LoadBalancer.Helper.createSubChannel() is called
outside of the SynchronizationContext.

Adds SynchronizationContext.throwIfNotInThisSynchronizationContext()
to facilitate this warning.  It can also be used by LoadBalancer
implementations to make it a requirement.
2018-10-30 07:22:15 -07:00
Kun Zhang 4c6e202df3
core: service-loader-based LoadBalancerProvider (#4996)
LoadBalancerProvider is the interface that extends LoadBalancer.Factory. LoadBalancerRegistry is the one that loads the providers through service loader, and allows users to access providers through their names.

pick_first and round_robin balancer factories, which are experimental public API are now deprecated. Their providers are internal, as they are accessible by policy name.

AutoConfiguredLoadBalancerFactory is modified to access implementations purely by their names, thus hard-coded class names are no longer needed, and it can support arbitrary policy selected by service config.
2018-10-29 10:39:11 -07:00