Commit Graph

519 Commits

Author SHA1 Message Date
Kun Zhang 8ee9fb5183 core: add internal API to disable stats and/or tracing. (#3464) 2017-09-15 10:00:12 -07:00
Carl Mastrangelo abea73c0af core: add finalizer checks for ManagedChannels (#3452)
* core: add finalizer checks for ManagedChannels

Cleaning up channels is something users should do.  To promote this
behavior, add a log message to indicate that the channel has not
been properly cleaned.

This change users WeakReferences to avoid keeping the channel
alive and retaining too much memory.  Only the id and the target
are kept.  Additionally, the lost references are only checked at
JVM shutdown and on new channel creation.  This is done to avoid
Object finalizers.

The test added checks to see that the message is logged.  Since
java does not allow forcing of a GC cycle, this code is best
effort, giving up after about a second.  A custom log filter is
added to hook the log messages and check to see if the correct
one is present.  Handlers are not used because they are
hierarchical, and would be annoying to restore their state after
the test.

The other tests in the file contribute a lot of bad channels.  This
is reasonable, because they aren't real channels.  However, it does
mean that less than half of them are being cleaned up properly.
After trying to fix a few, it is too hard to do.  It would only
serve to massively complicate the tests.

Instead, this code just keeps track of how many it wasn't able to
clean up, and ignores them for the test.  They are still logged,
because really they should be closed.
2017-09-14 21:19:22 -07:00
zpencer 2b1363d586 core,netty,okhttp,protobuf-lite: avoid @Beta guava classes (#3463) 2017-09-14 19:39:06 -07:00
zpencer bda67784c0 core,netty,okhttp: strip outbound headers with reserved names (#3098)
These will be stripped:
CONTENT_TYPE, TE, USER_AGENT
2017-09-14 15:26:36 -07:00
Eric Anderson 2d711687f9 Revert "netty: hide ProtocolNegotiator, and expose initial ChannelHandler"
This reverts commit 332c46ff1a.

We need the protocol negotiator exposed for alternative
handshake/security mechanisms.
2017-09-14 12:15:04 -07:00
Carl Mastrangelo 332c46ff1a netty: hide ProtocolNegotiator, and expose initial ChannelHandler
* netty: hide ProtocolNegotiator, and expose initial ChannelHandler

This change does two things: it hides the ProtocolNegotiator from
NSB, and exposes an internal "init channel" on NSB and NCB.  The
reason for the change is that PN is not a powerful enough
abstraction for internal Google use (and for some other outside
users with highly specific uses).

The new API exposes adding a ChannelHandler to the pipeline upon
registration of the channel.

To accomplish this, NettyClientTransport is modified to use
ChannelInitializer.  There is a comment explaining why it cannot
be used, but after looking at the the original discussion, I
believe the reasons for doing so are no longer applicable.

Specifically, at the time that CI was removed, there was no
WriteQueue class.  The WQ class buffers all writes and executes
them on the EventLoop.  Prior to WQ it was not the case that all
writes happened on the loop, so it could race.  If the write was
not on the loop, it would be put on the loops execution queue,
but with the CI handler as the target.  Since CI removed itself
upon registration, the write wouldn get fired on the wrong
handler.

With the additional of WQ, this is no longer a problem.  All
writes go through WQ, and only execute on the loop, so pipeline
changes are no longer racy.

...That is, except for the initial noop write.  This does still
experience the race.  If the channel is failed during
registration or connect, the lifecycle manager will fail for
differing, racy reasons.

====

To make things more uniform across NCT and NST, I have put them
both back to using CI.  I have added listeners to each of the
bootstrap futures.  I have also moved the initial write to the
CI, so that it always goes through the the buffering negotiation
handler.

Lastly, racy shutdown errors will be logged so that if multiple
callbacks try to shutdown, it will be obvious where they came
from and in which order they happened.

I am not sure how to test the raciness of this code, but I *think*
it is deterministic.  From my reading, Promises are resolved
before channel events so the first future to complete should be the
winner.  Since listeners are always added from the same thread,
and resolved by the loop, I think this forces determinism.

One last note: the negotiator has a scheme that is hard coded
after the transport has started.  This makes it impossible to
change schemes after the channel is started.  Thats okay, but it
should be a use case we knowingly prevent.  Others may want to
do something more bold than we do.
2017-09-12 19:56:25 -07:00
Eric Gribkoff ec600feb87 okhttp: set GET method in headers (#3316) 2017-09-11 13:58:33 -07:00
zpencer e6fc6f33a5 netty: NOOP_MESSAGE must be staged before connect() (#3411)
Addresses flakey test
Fixes #3408
2017-08-28 17:48:14 -07:00
Eric Anderson 6164b7b2ee Move jmh benchmarks to their respective modules
The benchmarks should be close to the code they're benchmarking, like
we do with tests.

This includes a bugfix to SerializingExecutorBenchmark to let it run.

The io.grpc.benchmarks.netty benchmarks in benchmarks/ depend on
ByteBufOutputMarshaller from benchmarks's main, so they were not moved.
2017-08-28 13:37:39 -07:00
Eric Anderson 97c625fa79 netty: Update to Netty 4.1.15
We'll need to figure out what we want to do about the deprecated API.
We'll probably just drop the verification check, but need to look into
it a bit.
2017-08-28 10:23:13 -07:00
Carl Mastrangelo c024f17429 netty,okhttp: include more detail about ALPN missing
Additionally: include info on why android classes are missing
2017-08-24 16:00:36 -07:00
zpencer 68e8dc240c netty: graceful shutdowns should for streams to close (#3386)
Previously we have a hard timeout of 5s, which isn't very graceful.
2017-08-24 10:16:12 -07:00
John Hume 7d0229a1f5 Also fix bazel name of io.netty:netty-transport 2017-08-23 15:48:08 -07:00
ZHANG Dapeng fe1583c9b4 netty: fix transport spuriously in notInUse state
Previously, if two streams are added (but not active yet), then the transport is changed into inUse; after that, if one of them gets active and then closed and removed, then the transport will be changed into and staying at notInUse, although the other stream could later be active.
2017-08-23 13:38:05 -07:00
Eric Anderson 6ca91c4356 netty: Handle shutdown and failures during negotiator
NettyClientTransport needs to call close() on the Channel directly
instead of sending a message, since the message would typically be
delayed until negotiation completes.

The closeFuture() closes too early to be helpful, which is very
unfortunate. Using it squelches the negotiator's error handling. We now
rely on the handlers to report shutdown without any back-up. The
handlers error handling has matured, so maybe this is okay.
2017-08-18 14:38:48 -07:00
Kun Zhang 41410345e6 core: pass status to ManagedClientTransport.shutdown() (#3351)
This aligns with shutdownNow(), which is already accepting a status.
The status will be propagated to application when RPCs failed because
of transport shutdown, which will become useful information for debug.
2017-08-16 10:23:07 -07:00
ZHANG Dapeng 577bbefd1a netty: fix keepalive test flakiness
In `NettyHandlerTestBase` class, extended Netty's `EmbeddedChannel` by overriding`eventLoop()` to return an `eventLoop` that uses `FakeClock.getScheduledExecutorService() to schedule tasks.

Resolves #3326
2017-08-15 10:49:01 -07:00
ZHANG Dapeng 34f31fe3c6 netty: Not to ignore tests for window overriding
As noted after `@Ignore`
> Re-enable once https://github.com/grpc/grpc-java/issues/1175 is fixed

#1175 has been closed for a long time, should re-enable the tests.
2017-08-14 12:58:17 -07:00
ZHANG Dapeng c71e2919de all: fix typo of overridden
s/overriden/overridden/g
2017-08-11 16:53:53 -07:00
Eric Gribkoff 9b74f8e756 core,netty,okhttp: add option to deframe in app thread 2017-08-11 16:52:45 -07:00
Eric Gribkoff 16575d01a3 core,netty,okhttp,testing: switch to StreamListener.messagesAvailable 2017-08-11 16:52:45 -07:00
Paul Gross 72b9ee22b8 all: Fix mismatch in naming Bazel Maven jars
This commit aligns the naming of the Bazel Maven jars with the names
used by Bazel's migration-tooling project:

https://github.com/bazelbuild/migration-tooling

Unfortunately, we can't fix @com_google_protobuf_java because it's
required by Bazel itself.

Fixes #3328
2017-08-11 16:39:43 -07:00
Eric Gribkoff 1386453830 netty: check for stream before freeing flow control bytes on client 2017-08-10 15:02:34 -07:00
Eric Anderson 4147632bed netty: Update netty to 4.1.14
EmbeddedChannel now runs all pending tasks when the Channel is closed.
This caused the Http2ConnectionHandler to clear deframer references (on
channelInactive) on errors when it previously didn't. Now that the
errors were handled more fully, it exposed bugs in tests.
2017-08-07 14:11:57 -07:00
Carl Mastrangelo 02cb718767 testing,core: don't use mocks for stream tracers (#3305)
This is a big, but mostly mechanical change.  The newly added Test*StreamTracer classes are designed to be extended which is why they are non final and have protected fields.  There are a few notable things in this:

1.  verifyNoMoreInteractions is gone.   The API for StreamTracers doesn't make this guarantee.  I have recovered this behavior by failing duplicate calls.  This has resulted in a few bugs in the test code being fixed.

2.  StreamTracers cannot be mocked anymore.  Tracers need to be thread safe, which mocks simply are not.  This leads to a HUGE number of reports when trying to find real races in gRPC.

3.  If these classes are useful, we can promote them out of internal.  I just put them here out of convenience.
2017-08-03 16:59:06 -07:00
Carl Mastrangelo 3efaccd81f netty: support `status()` on Headers
* netty: support `status()` on Headers

Recent Netty change a91df58ca1
caused the `status()` method to be invoked, which AbstractHttp2Headers does not implement.
This change is necesary to upgrade to Netty 4.1.14
2017-07-27 12:17:27 -07:00
Eric Anderson bd743f3afd core: Channel uses transport's ScheduledExecutorService
Coupled with the similar change on server-side, this removes the need for a
thread when using Netty. For InProcess and OkHttp, it would allow us to let the
user to provide the scheduler for tests or application-wide thread sharing.
2017-07-25 14:26:16 -07:00
ZHANG Dapeng 883a85ee93 core,netty,okhttp: remove 2-arg ClientTransport.newStream()
to keep only one `newStream()` method in the `ClientTransport` interface
2017-07-25 14:12:36 -07:00
Eric Anderson 994f200d15 core: Server uses transport's ScheduledExecutorService
For Netty, this reduces the number of threads necessary for servers (although
until channel is converted, actual number of threads isn't impacted) and
naturally reduces contention and timeout latency.

For InProcess, this gets us closer to allowing applications to provide all
executors, which is especially useful during tests.
2017-07-19 10:31:26 -07:00
Eric Anderson d325919f62 core: Use Class.forName(String) in provider for Android
Class.forName(String) is understood by ProGuard, removing the need for
manual ProGuard configuration and allows ProGuard to rename the provider
classes. Previously the provider classes could not be renamed.

Fixes #2633
2017-07-19 10:15:03 -07:00
zpencer ec4837bf10 netty: quieter errors in NettyServerTransport (#3234)
Some errors such as connection resets should be logged at FINE, the
rest should be INFO rather than SEVERE.

fixes #1768
2017-07-14 13:59:36 -07:00
ZHANG Dapeng ff0ad5fac3 testing: refactor part of TestUtils to internal
Moved the following APIs from `io.grpc.testing.TestUtils` to `io.grpc.internal.TestUtils`:

`InetSocketAddress testServerAddress(String host, int port)`
`InetSocketAddress testServerAddress(int port)`
`List<String> preferredTestCiphers()`
`File loadCert(String name)`
`X509Certificate loadX509Cert(String fileName)`
`SSLSocketFactory newSslSocketFactoryForCa(Provider provider, File certChainFile)`
`void sleepAtLeast(long millis)`

APIs not to be moved:

`ServerInterceptor recordRequestHeadersInterceptor()`
`ServerInterceptor recordServerCallInterceptor()`
2017-07-10 16:30:38 -07:00
Carl Mastrangelo 4bce872718 netty: remove unneeded licence file 2017-07-06 13:11:22 -07:00
Eric Anderson c436561fc5 all: Use fixed version number for java 6/7 signatures
This is important for stable builds, as if the signature changes the old source
may no longer validate.
2017-06-30 15:25:34 -07:00
zpencer f559cf4adf netty: client transport needs to flush fence operation (#3137)
This the cause of the flakey serverNotListening test, because the
NOOP_MESSAGE just sits around the pipeline. As a result, the
listener does not fire within the 1s verification timeout.
2017-06-28 10:23:48 -07:00
Kun Zhang 47e90f7823 netty: fix NettyHandlerSettings synchronized on wrong object. (#3144)
Bug introduced in commit 8c017337eb
2017-06-27 16:20:53 -07:00
Kun Zhang 8c017337eb netty: InternalHandlerSettings should not be used by non-Internal classes. (#3143)
InternalHandlerSettings is part of "netty:internal" inside google,
which is used to allow controlled exposure of internals.
"netty:internal" depends on "netty", which consists of the rest of the
netty subproject.  Therefore, "netty" should not depend on
"netty:internal".
2017-06-27 14:22:01 -07:00
zpencer 0fa2225623 netty: fix race condition for listeners attaching to connect future (#3122)
Sadly, the serverNotListening test is still flakey after this change, but this PR fixes a legit problem.

The listener to the connect future depends on the channel pipeline being intact. But the way it is attached allows the connect attempt to fail, and have the entire pipeline being torn down by netty before the .addListener actually runs. The result is that the listener will be attached to an already completed future, and the logic will be applied to an empty pipeline.

The fundamental problem is that there are two threads, the grpc thread, and the netty thread. This PR moves the listener attaching code into the netty thread, guaranteeing the listener is attached before any connection is made. It makes more sense for the code to live inside AbstractBufferingHandler, since handlers are generally free to swallow exceptions (the alternative is to make NettyClientHandler forward exceptions up the pipeline from itself). AbstractBufferingHandler needs the special guarantees, so it will be the one with special code.
2017-06-22 22:07:51 -07:00
Simon Horlick 6d9e149dcb build: Add Bazel java_grpc_library rule
Bazel third party dependencies are specified in repositories.bzl which
gives the consumer the ability to opt-out of any dependencies they use
directly in their own project.

Fixes #2756
2017-06-22 13:06:49 -07:00
Eric Gribkoff e01cec5c2c netty: push sslContext initialization into transportCreationParamsFilterFactory 2017-06-19 23:20:59 -07:00
ZHANG Dapeng 544ceded6b netty: rename HandlerSettings to InternalHandlerSettings 2017-06-19 09:04:04 -07:00
Eric Anderson cb53bbf0be all: Filter out Internal* classes from Javadoc
core's sources already have filters applied, so it isn't necessary to
copy them to all.
2017-06-16 14:53:51 -07:00
Carl Mastrangelo 6ef77e0609 core: hide access to Status code and message keys 2017-06-08 10:16:06 -07:00
Eric Anderson c48610b890 netty: Eagerly create SslContext
Creating the SslContext can throw, generally due to broken ALPN. We want
that to propagate to the caller of build(), instead of within the
channel where it could easily cause hangs.

We still delay creation until actual build() time, since TLS is not
guaranteed to work and the application may be configuring plaintext or
similar later before calling build() where SslContext is unnecessary.

The only externally-visible change should be the exception handling.
I'd add a test, but the things throwing are static and trying to inject
them would be pretty messy.

Fixes #2599
2017-06-06 12:00:01 -07:00
Eric Anderson adc2de7533 netty: Clarify max header list size configuration 2017-06-05 14:55:16 -07:00
Carl Mastrangelo 166108a943 all: fix licence whitespace 2017-06-01 14:28:37 -07:00
Carl Mastrangelo 3bfd630bff all: update to Apache 2 licence
Also, update the authors.
2017-05-31 13:29:01 -07:00
Carl Mastrangelo ee38b3754e core: remove 2 suffix from streams 2017-05-26 16:59:54 -07:00
Carl Mastrangelo 7b821a0e50 netty: increase message quantum
This is a minor change setting the size of data frames sent when
interleaving RPCs.  The size was ~1024bytes previously, which
resulted in the `writev` syscalls sending many smaller chunks
before hitting the low water mark.  The end effect is larger calls
to `writev`, as seen with strace.

The effect of this is noticeable when sending a lot of data.  When
sending as many 1MB messages as possible it nearly doubles the
rate.

Before:

```
INFO: single throughput GRPC
50.0%ile Latency (in nanos):		280856575
90.0%ile Latency (in nanos):		349618175
95.0%ile Latency (in nanos):		380444671
99.0%ile Latency (in nanos):		455172095
99.9%ile Latency (in nanos):		537198591
100.0%ile Latency (in nanos):		566886399
QPS:                           346
Count:                         103984
```

After:
```
gRPC
50.0%ile Latency (in nanos):		125948927
90.0%ile Latency (in nanos):		166322175
95.0%ile Latency (in nanos):		177276927
99.0%ile Latency (in nanos):		193840127
99.9%ile Latency (in nanos):		226841599
100.0%ile Latency (in nanos):		256110591
QPS:                           774
Count:                         232340
```
2017-05-26 16:08:26 -07:00
zpencer 347eb09d92 all: Minor updates to expand javadocs (#2991)
all: Minor updates to expand javadocs
2017-05-17 17:12:45 -07:00
Łukasz Strzałkowski 67eefa69b4 Upgrade to netty and netty-tcnative
* Upgrade netty to 4.1.11.Final
  * Upgrade netty-tcnative to 2.0.1.Final
  * Remove `FixedHttp2ConnectionDecoder` as it's no longer needed
  * Use new, extensible `DefaultHttp2HeadersDecoder` for custom headers handling
2017-05-15 10:57:43 -07:00
ZHANG Dapeng 28ad3ba335 netty: fix server keepalive not initialized bug
fixes #2982
2017-05-12 09:05:21 -07:00
Muxi Yan f674776a6c Add/Fix some docs (#2970)
* Add/Fix some docs

* Address comments

* Address comments

* Address comments

* Add remarks

* Build fixes

* Revision

* More revision
2017-05-04 10:57:49 -07:00
ZHANG Dapeng 7d048af68e javadoc: fix broken links in javadoc 2017-05-02 16:21:43 -07:00
Carl Mastrangelo 06e823e251 netty: reduce severity of disconnect message 2017-05-02 09:51:22 -07:00
zpencer a317912a14 Channel.authority() should return the value of overrideAuthority (#2956)
AbstractManagedChannelImplBuilder accepts an overrideAuthority parameter, but this value is not hooked up to the name resolver object. Ultimately, Channel.authority consults with the NameResolver, so the overrideAuthority should be hooked into the NameResolverFactory, while all other functionality should be preserved.

Also, add unit tests for all the variants of OkHttpChannelBuilder and NettyChannelBuilder constructors, namely to test the slightly different NettyChannelBuilder(SocketAddress) code path.

Fixes #2682
2017-04-27 14:17:38 -07:00
Eric Gribkoff b6bf252566 interop-testing: add cacheable_unary test 2017-04-21 10:22:05 -07:00
Eric Gribkoff e36d229dc2 core,netty: remove grpc-payload-bin from GET requests 2017-04-21 10:22:05 -07:00
ZHANG Dapeng e576c4cb4c netty: more coverage on server keepalive
cover the missed code path of `ping` and `onPingTimeout` in `NettyServerHandler`
2017-04-20 10:38:55 -07:00
ZHANG Dapeng 4989736684 core: clamp keepAliveTime/Timeout in a way easier for test 2017-04-17 15:06:25 -07:00
ZHANG Dapeng 4a96e25955 netty: implement server max connection idle 2017-04-17 14:35:22 -07:00
Eric Anderson 393ebf7cdd netty,okhttp: handle ENHANCE_YOUR_CALM and too_many_pings
Any ENHANCE_YOUR_CALM is good reason to log, but too_many_pings also
triggers increase of the keepalive time for later connections.
2017-04-17 14:25:16 -07:00
Kun Zhang 6618f9739e core: add inboundHeaders() to ClientStreamTracer. (#2921)
Also renamed headersSent to outboundHeaders
2017-04-17 14:01:34 -07:00
ZHANG Dapeng 75324e9918 netty: fix flaky max connection age tests using sleepAtLeast
resolves #2898
2017-04-14 09:42:42 -07:00
ZHANG Dapeng ffc64b70bb netty: move connection.addListner inside constructor of NettyServerHandler
For convenience of implementing max connection idle.
2017-04-13 14:34:18 -07:00
Carl Mastrangelo be61af42e9 core: use RESOURCE_EXHAUSTED for max message size failures 2017-04-13 08:35:48 -07:00
ZHANG Dapeng f1de741a2a netty: ignore flaky max connection age tests
#2898
2017-04-10 16:06:07 -07:00
Eric Anderson b56a728502 all: Use "keepalive time" instead of "keepalive delay"
It should have always been 'time', to match the terminology of TCP
Keepalive.
2017-04-10 15:48:18 -07:00
Eric Anderson af4982b763 netty,okhttp: Allow keepalive without calls
Again, the server can enforce this, so clients shouldn't go wild with
their new-found freedom.
2017-04-10 15:48:18 -07:00
Eric Anderson 0277b91762 okhttp,netty: Normalize client-side keepalive APIs
This improves the docs a bit and makes OkHttp look like Netty.
2017-04-10 15:48:18 -07:00
ZHANG Dapeng 81da785f75 netty: add jitter to max connection age 2017-04-10 13:38:47 -07:00
ZHANG Dapeng 83a06cc1a5 netty: implement server max connection age 2017-04-10 11:32:28 -07:00
Eric Anderson cfc6634650 netty: Pass boolean to builder instead of permit/deny specialized naming
While we can use permit/deny in this one case, it isn't generalizable to
other cases. In order to avoid always questioning how to deal with
boolean config options, just pass the boolean in all cases.

This mirrors what is being done with the client-side's
keepAliveWithoutCalls.

These methods were very recently added, so there is a low risk of
breakage.
2017-04-10 10:34:03 -07:00
Kun Zhang 903197b2aa core: StreamTracer (#2863)
Background
==========

LoadBalancer needs to track RPC measurements and status for
load-reporting.  We need to introduce a "Tracer" API for that.

Since such API is very close to the current
Census(instrumentation)-based stats reporting mechanism in terms of what
are recorded, we will migrate the Census-based stats reporting under the
new Tracer API.

Alternatives
============

We considered plumbing the LB-related information from the LoadBalancer
to the core, and recording those information along with the currently
recorded stats to Census. The LB-related information, such as LB_ID,
reason for dropping reqeusts etc, would be added to the Census
StatsContext as tags.

Since tags are held by StatsContext before eventually being recorded by
providing the measurements, and StatsContext is immutable, this would
require a way for LoadBalancer to override the StatsContext, which means
LoadBalancer API would has direct reference to the Census StatsContext.
This is undesirable because Census API is not stable yet.

Part of the LB-related information is whether the client has received
the initial headers from the server.  While such information can be
grabbed by implementing a ClientInterceptor, it must be recorded along
with other information such as LB_ID to be useful, and LB_ID is only
available in GrpclbLoadBalancer.

Bottom line, trying to use solely the Census StatsContext API to record
LB load information would require extra data plumbing channel between
ClientInterceptor, LoadBalancer and the gRPC core, as well as exposing
Census API on the gRPC API.  Even with those extensive changes, we are
yet to find a working solution. Therefore, we abandoned this idea and
propose this PR.

Summary of changes
==================

API summary
-----------
Introduce "StreamTracer" API, a callback interface for receiving stats
and tracing related updates concerning **a single stream**.
"ClientStreamTracer" and "ServerStreamTracer" add side-specific
events. A stream can have zero or more tracers and report to all of
them.

On the client-side, CallOptions now takes a list of
ClientStreamTracer.Factory. Opon creating a ClientStream, each of the
factory creates a ClientStreamTracer for the stream. This allows
ClientInterceptors to install its own tracer factories by overriding the
CallOptions.

Since StreamTracer only tracks the span of a stream, tracking of a
ClientCall needs to be done in a ClientInterceptor.  By installing its
own StreamTracer when a ClientCall is created, ClientInterceptor can
associate the updates for a Call with the updates for the Streams
created for that Call.  This is how we keep the existing Census
reporting mechanism in CensusStreamTracerModule.

On the server-side, ServerStreamTracer.Factory is added through the
ServerBuilder, and is used to create ServerStreamTracers for every
ServerStream.

The Tracer API supports propagation of stats/tracing information through
Context and metadata.  Both client-side and server-side tracer factories
have access to the headers object.  Client-side tracer relies on
interceptor to read the Context, while server-side tracer has
filterContext() method that can override the Context.

Implementation details
----------------------

Only real streams report stats.  Pseudo streams such as delayed stream,
failing stream don't report.  InProcess transport streams currently
don't report stats.

"StatsTraceContext" which used to receive updates from core and report
directly to Census (StatsContext), now delegates to the StreamTracers of
a stream.  On the client-side, the scope of a StatsTraceContext reduces
from ClientCall to a ClientStream to match the scope of StreamTracer.

The Census-specific logic that was in StatsTraceContext is moved into
CensusStreamTracerModule, which produces factories for StreamTracers
that report to Census.

Reporting with StatsTraceContext is moved out of the Channel/Call layer
into Transport/Stream layer, to match the scope change of
StatsTraceContext.

Bug fixed
----------------

The end of a server-side call was reported in ServerCallImpl's
ServerStreamListenerImpl.closed(), which was wrong.  Because closed()
receiving OK doesn't necessarily mean the RPC ended with OK.  Instead it
means the server has successfully sent the final status, which may be
non-OK, to the client.

Now the end report is done in both ServerStream.close(any Status) and
before calling ServerStreamListener.closed(non-OK).  Whichever happens
first is the reported status.

TODOs
=====

A follow-up change to the LoadBalancer API will add a
ClientStreamTracer.Factory to the PickResult to complete the API needed
by load-reporting.
2017-04-07 11:03:24 -07:00
Eric Anderson 4236027713 netty: Add config for server keepalive enforcement
Now that there is a config, the new defaults are now being enabled.
Previously there were no default limits. Now keepalives may not be more
frequent than every 5 minutes and only when there are outstanding RPCs.
2017-04-06 15:48:33 -07:00
Eric Anderson 3818087aa4 netty: Handle channel creation failure
Something "very bad" has happened, but without grpc propagating the
cause from the Future it is very difficult to figure out what.

Fixes #2296
2017-04-06 11:11:49 -07:00
ZHANG Dapeng 1c1864be73 netty: refactor NettyChannelBuilder keepalive API (#2874)
To be in line with `NettyServerBuilder` APIs
- Deprecated `enableKeepAlive(boolean enable)` and
`enableKeepAlive(boolean enable, long keepAliveDelay, TimeUnit delayUnit, long keepAliveTimeout, 
TimeUnit timeoutUnit)`
which never worked in v1.2

- Added `keepAliveTime(long keepAliveTime, TimeUnit timeUnit)` and
`keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)`
2017-04-04 18:19:41 -07:00
Eric Anderson 90788305a3 netty: Add server keepalive enforcement
Everything is currently permitted, but I've tested with other
configurations and all tests pass. I'll set the restrictive default at
the same time as adding a configuration API.
2017-04-04 16:47:42 -07:00
Eric Anderson f9eb545df0 netty: Fix client keepalive initialization (again)
d116cc9 fixed the NPE, but the initialization of the manager happened
_after_ newHandler() was called, so a null manager was passed to the
handler.

Fixes #2828
2017-03-31 17:21:33 -07:00
ZHANG Dapeng c4bbe66506 netty: expose server side keepalive API
expose server side keepalive API in NettyServerBuilder
2017-03-31 10:35:03 -07:00
Eric Anderson 4096d4b668 core,netty: support GET verb in AbstractClientStream2 2017-03-30 14:18:14 -07:00
ZHANG Dapeng 8114b93113 netty: Server side keep alive
use KeepAliveManager in NettyServerHandler
2017-03-30 09:24:04 -07:00
ZHANG Dapeng 6789eac581 core,netty,okhttp: KeepAliveManager with Pinger
Modified KeepAliveManager to use a Pinger interface, which can send ping or shutdown transport for both server and client.
2017-03-23 13:34:19 -07:00
Carl Mastrangelo ee12cc2a34 all: update to latest version of errorprone 2017-03-22 22:09:04 -07:00
ZHANG Dapeng 3ffa5a9660 Okhttp: keepAlivedManager#onTransportShutdown moved from shutdown to stopIfNecessary and refactored
`keepAlivedManager#onTransportshutdown` should not be called in `transport.shutdown()` because it is possible that there are still open RPC streams, and maybe inactive, so keepalive is still needed.
2017-03-22 10:26:45 -07:00
ZHANG Dapeng a14689eff8 netty: move startWriteQueue right after channel is constructed
Now that the commit 65e4d9f has split the channel instantiation and `connect()`, we can `startWriteQueue()` even earlier.
2017-03-20 11:54:57 -07:00
Eric Anderson 19afd8b48b core: Support keepalive even when transport is idle
Nothing is using this yet, but it will be used on both client and
server.
2017-03-15 17:15:19 -07:00
Eric Anderson 2cb6ecc3b3 netty: Backport SETTINGS ACK sequencing fix
This fix was made in netty/netty#6521. Fixes #2801
2017-03-14 14:21:51 -07:00
Eric Anderson 9ef07916f7 netty: Copy DefaultHttp2ConnectionDecoder in prep for backport 2017-03-14 14:21:51 -07:00
ZHANG Dapeng 891581f14d all: fix errorprones
fix JavaStyle and ErrorProne warnings found in internal weekly import:

- Calls to ExpectedException#expect should always be followed by exactly one statement.
- Do not mock 'java.util.concurrent.Future'
2017-03-06 10:45:42 -08:00
Kun Zhang 9c76b48356 netty/test: be less agreesive on checking cause
For #2762

If it doesn't fix the flaky test, status.toString() will print out the
whole stack trace so that we will know what's in there.
2017-03-03 10:31:34 -08:00
Eric Anderson c415dc8d40 netty: Use tcnative in tests instead of Jetty ALPN
I'm quite confused how we went this long using Jetty ALPN for the Netty
tests. Anyway, we strongly prefer tcnative, so we should be using it in
the tests.
2017-02-24 17:04:35 -08:00
Eric Anderson 675080b208 all: Enable ErrorProne during compilation
ErrorProne provides static analysis for common issues, including
misused variables GuardedBy locks.

This increases build time by 60% for parallel builds and 30% for
non-parallel, so I've provided a way to disable the check. It is on by
default though and will be run in our CI environments.
2017-02-24 14:53:23 -08:00
Lukasz Strzalkowski d116cc9875 netty: Fix NPE in NettyClientTransport
Fixes NPE when keepalive is enabled.

* Move creation of keepAliveManager to the bottom of start()
* Enable keepAlive in NettyClientTransportTest
* Add test cases checking if keepalive is enabled/disabled, specifically.

Fixes #2726
2017-02-16 10:29:52 -08:00
Eric Anderson ae68718881 netty: remove unused code in a test 2017-02-13 16:56:10 -08:00
Łukasz Strzałkowski 26913bb82e netty: include SETTINGS_MAX_HEADER_LIST_SIZE in SETTINGS
Closes #2350
2017-02-13 07:37:54 -08:00
Ryan Michela 4029b3f0c2 Implement missing authority API for HandlerRegistry 2017-02-10 17:19:20 -08:00
Eric Anderson cc000be12d netty: Fix CheckReturnValue failure in test 2017-02-09 17:16:19 -08:00
Eric Anderson 42aa64c647 all: swap to newer animalsniffer plugin
The new plugin uses a newer version of animalsniffer, allows overriding
the animalsniffer version used, and has up-to-date handling. The
up-to-date handling cuts fully incremental parallel build times in half,
from 5.5s to 2.7s.

The previous plugin was supposed to be verifying tests. However, either
it wasn't verifying them or its verification was broken.
2017-02-07 12:49:01 -08:00
Carl Mastrangelo dfe61e4ed3 netty: fix race in server channel startup and shutdown 2017-02-06 15:44:03 -08:00