Commit Graph

70 Commits

Author SHA1 Message Date
Eric Anderson e7ce41dd94 all: Style, unused, and errorprone fixes 2016-10-12 16:57:01 -07:00
Kun Zhang 132f7a9a33 core: Census integration for stats (#2262)
Highlights
==========

StatsTraceContext
-----------------

The bridge between gRPC library and Census. It keeps track of the total
payload sizes and the elapsed time of a Call. The rest of the gRPC code
doesn't invoke Census directly.

Context propagation
-------------------

StatsTraceContext carries CensusContext (and the upcoming TraceContext)
and is attached to the gRPC Context.

1. StatsTraceContext is created by ManagedChannelImpl, by calling
createClientContext(), which inherits the current CensusContext if available.

2. ManagedChannelImpl passes StatsTraceContext to ClientCallImpl, then
to the stream, then to the framer and deframer explicitly.

3. ClientCallImpl propagates the CensusContext to the headers.

1. ServerImpl creates a StatsTraceContext by implementing a new callback
method StatsTraceContext methodDetermined(MethodDescriptor, Metadata) on
ServerTransportListener.

2. NettyServerHandler calls methodDetermined() before creating the
stream, and passes the StatsTraceContext to the stream.

3. When ServerImpl creates the gRPC Context for the new ServerCall, it
calls the new method statsTraceContext() on ServerStream and puts the
StatsTraceContext in the Context.

Metrics recording
-----------------

1. Client-side start time: when ClientCallImpl is created

2. Server-side start time: when methodDetermined() is called

3. Server-side end time: in ServerStreamListener.closed(), but before
calling onComplete() or onCancel() on ServerCall.Listener.

4. Client-side end time: in ClientStreamListener.closed(), but before
calling onClonse() on ClientCall.Listener

Message sizes are recorded in MessageFramer and MessageDeframer. Both
the uncompressed and wire (possibly compressed) payload sizes are
counted.

TODOs
=====

The CensusContext created from headers on the server side should be
attached to the gRPC Context for the call.  It's not done at this moment
because Census lacks the proper API to do it. It only affects tracing
and resource accounting, but doesn't affect stats functionality
2016-10-06 17:15:24 -07:00
Carl Mastrangelo 141eed5ed0 core: change Metadata internals to avoid garbage creation
Before:
Benchmark                                                                   (headerCount)    Mode     Cnt        Score    Error  Units
InboundHeadersBenchmark.defaultHeaders_clientHandler                                  N/A    avgt      10      240.879 ±  4.903  ns/op
InboundHeadersBenchmark.defaultHeaders_serverHandler                                  N/A    avgt      10      882.354 ± 16.177  ns/op
InboundHeadersBenchmark.grpcHeaders_clientHandler                                     N/A    avgt      10      208.068 ±  5.380  ns/op
InboundHeadersBenchmark.grpcHeaders_serverHandler                                     N/A    avgt      10      477.604 ±  8.200  ns/op
OutboundHeadersBenchmark.convertClientHeaders                                           1  sample  234233      125.232 ± 11.903  ns/op
OutboundHeadersBenchmark.convertClientHeaders                                           5  sample  344367      264.343 ± 18.318  ns/op
OutboundHeadersBenchmark.convertClientHeaders                                          10  sample  392273      439.640 ±  2.589  ns/op
OutboundHeadersBenchmark.convertClientHeaders                                          20  sample  221506      855.115 ± 38.899  ns/op
OutboundHeadersBenchmark.convertServerHeaders                                           1  sample  253676      111.941 ±  2.742  ns/op
OutboundHeadersBenchmark.convertServerHeaders                                           5  sample  368499      248.255 ±  2.601  ns/op
OutboundHeadersBenchmark.convertServerHeaders                                          10  sample  390015      439.651 ± 11.040  ns/op
OutboundHeadersBenchmark.convertServerHeaders                                          20  sample  221807      840.435 ± 21.667  ns/op
OutboundHeadersBenchmark.encodeClientHeaders                                            1  sample  230139      432.866 ± 25.503  ns/op
OutboundHeadersBenchmark.encodeClientHeaders                                            5  sample  226901      765.095 ± 19.969  ns/op
OutboundHeadersBenchmark.encodeClientHeaders                                           10  sample  260495     1268.239 ± 21.850  ns/op
OutboundHeadersBenchmark.encodeClientHeaders                                           20  sample  311526     2059.973 ± 23.503  ns/op

After:

Benchmark                                                                   (headerCount)    Mode     Cnt        Score    Error  Units
InboundHeadersBenchmark.defaultHeaders_clientHandler                                  N/A    avgt      10      104.317 ±  1.973  ns/op
InboundHeadersBenchmark.defaultHeaders_serverHandler                                  N/A    avgt      10      395.666 ± 11.056  ns/op
InboundHeadersBenchmark.grpcHeaders_clientHandler                                     N/A    avgt      10       64.147 ±  4.076  ns/op
InboundHeadersBenchmark.grpcHeaders_serverHandler                                     N/A    avgt      10      228.299 ±  2.874  ns/op
OutboundHeadersBenchmark.convertClientHeaders                                           1  sample  252451      102.718 ±  2.714  ns/op
OutboundHeadersBenchmark.convertClientHeaders                                           5  sample  239976      225.812 ± 38.824  ns/op
OutboundHeadersBenchmark.convertClientHeaders                                          10  sample  258119      364.475 ± 57.217  ns/op
OutboundHeadersBenchmark.convertClientHeaders                                          20  sample  260138      676.950 ± 36.243  ns/op
OutboundHeadersBenchmark.convertServerHeaders                                           1  sample  276064      105.371 ±  1.859  ns/op
OutboundHeadersBenchmark.convertServerHeaders                                           5  sample  255128      190.970 ± 16.475  ns/op
OutboundHeadersBenchmark.convertServerHeaders                                          10  sample  272923      366.769 ± 28.204  ns/op
OutboundHeadersBenchmark.convertServerHeaders                                          20  sample  264797      641.961 ± 18.879  ns/op
OutboundHeadersBenchmark.encodeClientHeaders                                            1  sample  226078      425.262 ±  3.481  ns/op
OutboundHeadersBenchmark.encodeClientHeaders                                            5  sample  253606      675.488 ± 26.001  ns/op
OutboundHeadersBenchmark.encodeClientHeaders                                           10  sample  286556     1157.014 ± 12.923  ns/op
OutboundHeadersBenchmark.encodeClientHeaders                                           20  sample  345649     1874.806 ± 36.227  ns/op
2016-09-19 14:25:48 -07:00
Jakob Buchgraber 4aadf550ee netty: Fix receipt of ClosedChannelException instead of actual error. Fixes #1330.
Our API allows pings to be send even after the transport has been shutdown. We currently
don't handle the case, where the Netty channel has been closed but the NettyClientHandler
has not yet been removed from the pipeline, correctly. That is, we need to query the shutdown
status whenever we receive a ClosedChannelException.

Also, some cleanup.
2016-09-12 19:17:34 +02:00
Carl Mastrangelo 893ef44b4c all/tests: add a ClientCall and ServerCall suitable for use in tests 2016-09-02 17:09:49 -07:00
Kun Zhang 58d78dd0aa core: add ServerTransportFilter
Called whenever a ServerTransport is ready and terminated.  Has the
ability to modify transport attributes, which ServerCall.attributes()
are based on.

Related changes:

- Attribute keys for remote address and SSL session are now moved from
ServerCall to a neutral place io.grpc.Grpc, because they can also be
used from ServerTransportFilter, and probably will be used on the
client-side too.  The old keys on ServerCall is marked deprecated and
are equivalent to the new keys.
- Added transportReady() to ServerTransportListener.

Resolves #2132
2016-08-31 14:45:15 -07:00
Eric Anderson 7d464fcb02 inprocess: Avoid creating unnecessary threads
Implementations of ManagedClientTransport.start() are restricted from
calling the passed listener until start() returns, in order to avoid
reentrency problems with locks. For most transports this isn't a
problem, because they need additional threads anyway. InProcess uses no
additional threads naturally so ends up needing a thread just to
notifyReady. Now transports can just return a Runnable that can be run
after locks are dropped.

This was originally intended to be a performance optimization, but the
thread also causes nondeterminism because RPCs are delayed until
notifyReady is called. So avoiding the thread reduces needless fakes
during tests.
2016-08-02 13:16:36 -07:00
Louis Ryan c1ef8061d1 Fix selection of security Provider to conscruct SSLContext
Cleanup redundant API un TestUtils
Fix TlsTest to be ignored on JKD7 correctly
2016-07-18 14:25:27 -07:00
Louis Ryan f52b4e52cd Make the OkHTTP transport AppEngine friendly. AppEngine may support
conscrypt at some point which would allow ALPN to function
Clarify the SSLContext.getDefault is not used when constructing the
default SSLSocketFactory.
2016-07-13 18:27:43 -07:00
Jakob Buchgraber 7504b79f00 netty: add logging to find cause of ClosedChannelException.
- See #1330 for details.
- Also, Netty 4.1.2.Final comes with additional information where
a (usually statically cached) ClosedChannelException was triggered [1]

[1] https://github.com/netty/netty@e845670#diff-8c9a7d1d9b0fdb6c5aef2794d05a9f88
2016-07-09 14:50:39 +02:00
ZHANG Dapeng 8ed2dc8bec testware: fix flakes caused by pickUnusedPort
Resolves #1756

The thread-unsafe method `io.grpc.testing.TestUtils.pickUnusedPort` causes flakes (#1756) in windows. Need to avoid use of this method in test as in windows the tests are running in different jvms and concurrent calls of this method in multiple processes tend to return the same port number.

There are some usages of this method in benchmarks, so moved the method to `io.grpc.benchmarks.Utils` and the method will only be used in benchmarks and not in test.
2016-06-28 13:34:38 -07:00
Eric Anderson 5487ea8f54 Remove unused variables
This fixed a threading issue in ServerImpl because the unused variable
should have been used.
2016-06-24 12:11:03 -07:00
Eric Anderson 66ab956f9e Reapply "Eliminate MethodDescriptor from startCall and interceptCall for servers"
This reverts commit ef178304cb, which
itself was a revert.
2016-06-23 09:27:47 -07:00
Eric Anderson ef178304cb Revert "Eliminate MethodDescriptor from startCall and interceptCall for servers"
This reverts commit 3df1446deb.

The commit was adding to the difficulty of integration for testing. By
itself it isn't bad, so this is a temporary revert until the many other
commits are absorbed and then it will be reapplied.

This does have a manual edit for ClientCallsTest.
2016-06-20 15:18:18 -07:00
Kun Zhang 38b950f4f9 core: add transportInUse() to transport listener.
A transport is "in use" iff number of streams > 0. In following changes
the channel will use this information when deciding whether it should
transit to the IDLE mode (#1276).
2016-06-15 13:40:44 -07:00
Louis Ryan 3df1446deb Eliminate MethodDescriptor from startCall and interceptCall for servers
Make the MethodDescriptor a property of ServerCall
Move ServerMethodDefinition into ServerServiceDefinition
2016-06-13 14:39:58 -07:00
Eric Anderson c6fd94ca85 Implement shutdownNow
Fixes #448
2016-06-02 17:39:59 -07:00
Jakob Buchgraber d25b65bb53 testing: add tests for Netty bug where a channel would break after a RST_STREAM frame. Fixes #1682 2016-06-02 18:34:07 +02:00
Carl Mastrangelo 1cc76d8132 core,netty,okhttp: move user agent out of client call and into the transport 2016-05-25 15:11:42 -07:00
nmittler d9d4d8b70f Updating status codes to match the spec.
Fixes #1605
2016-05-09 13:55:50 -07:00
Carl Mastrangelo bc661e7fbb all: Finish adding tracking issues for ExperimentalApi 2016-05-03 16:15:57 -07:00
Jakob Buchgraber 46eefe34fb Strip cause from InProcessTransport between client and server. Fixes #1716 2016-04-29 23:36:59 +02:00
Jakob Buchgraber 9de87e3acd Add tests for call.cancel() from within messageRead. 2016-04-29 18:16:58 +02:00
Carl Mastrangelo d0d946ec9f new name 2016-04-18 16:21:53 -07:00
Carl Mastrangelo c4e8b1f10f Rename internal.Server to internal.TransportServer 2016-04-18 15:50:20 -07:00
Carl Mastrangelo b3bc7fc499 Try out using Truth library 2016-04-05 11:33:20 -07:00
Eric Anderson 3a920cdcca Add missing generics to some ServerCall usages 2016-03-17 17:05:25 -07:00
buchgr 3c68c053f7 Remove ReferenceCounted and add close() to ClientTransportFactory. Fixes #927 2016-03-17 00:31:04 +01:00
Lukasz Strzalkowski 6a67a97a73 Add attributes to ServerCall 2016-03-16 15:39:42 -07:00
Kun Zhang 2491402036 Remove or use unused variables. 2016-03-04 17:05:23 -08:00
Eric Anderson 1170afd168 Add transport test for Netty
Netty client shutdown would race with the negotiation handling and
circumvent AbstractBufferingHandler. Use a new command in order to
leave channel.close() available for abrupt killing of the connection
when connecting.

ping_afterTermination was previously racey that made it succeed. After
fixing the test, Netty would consistently fail to call callback. After
fixing Netty to fail the callback it was not using the right status
because when Netty's channel is closed none of our handlers are run.
This reliably fails the future with ClosedChannelException, which is
useless, so now we special-case that exception and fill in the reason
for shutdown.

To prevent accidentally reporting Status.OK, the transports no longer
use OK when calling transportShutdown. The OK status was already no
longer being consumed, since keying off whether transportReady was
called is more helpful.

This fixes #1330
2016-03-01 17:43:30 -08:00
Eric Anderson b17a249fc4 Create new AbstractTransportTest for Transports
This is lower-level than the existing AbstractTransportTest. It should
be used by all transports, but InProcessTransport is the only one as
part of this commit.
2016-02-25 16:23:17 -08:00
Carl Mastrangelo 42d787288e Use default keystore 2016-02-22 17:18:32 -08:00
Eric Anderson 484c46c62b Revert minor grammar tweaks to avoid syncing readme
The certs are used a lot of places, and we would prefer they stay
identical. This small grammar changes from 95d7bfd don't seem to
contribute enough for the effort envolved to sync.
2016-01-25 14:23:43 -08:00
Matt Hildebrand 95d7bfd2b9 Add some initial integration tests for GRPC's TLS support.
Tests run using Jetty ALPN only, not using OpenSSL.
2016-01-21 13:46:19 -08:00
Carl Mastrangelo 3fef40368d Make TestUtils able to read from input stream. This makes it easier to pass in an input stream from a resource 2015-12-07 17:28:25 -08:00
Xudong Ma 975c38e77c Keep our certs used for testing the same with their internal version 2015-12-04 13:45:48 -08:00
Julien Boeuf 088def1985 Updating the server1 cert so that it can be used with Go.
The encoding of the issuer field in this cert is now a PRINTABLESTRING
as opposed to UTF8STRING in the previous server1.pem which was causing
the Go issue.

- https://github.com/grpc/grpc/pull/4096
- https://github.com/grpc/grpc-go/pull/442

Sorry I should have done this java PR and have it approved before
submitting the grpc-go and grpc PRs.
2015-11-17 21:43:45 -08:00
Eric Anderson 1cfba96d17 Enforce sending headers before messages on server
ServerCall already had "headers must be sent before any messages, which
must be sent before closing," but the implementation did not enforce it
and our async server handler didn't obey.

The benefit of forcing sending headers first is that it removes the only
implicit call in our API and interceptors dealing just with metadata
don't need to override sendMessage. The implicit behavior was bug-prone
since it wasn't obvious you were forgetting that headers may not be
sent.
2015-09-11 17:39:40 -07:00
Eric Anderson d966163bbb Mark classes in testing as ExperimentalApi
We've not done any real work to make sure they have reasonable APIs.
2015-09-10 15:56:58 -07:00
Xudong Ma 0a51f0fbd9 Move StreamRecorder to testing package. 2015-09-01 09:15:03 -07:00
Carl Mastrangelo a508c1d4f5 Remove Headers 2015-08-24 11:41:10 -07:00
Xudong Ma 7dbca92435 Remove deprecated method. 2015-08-18 10:03:17 -07:00
Carl Mastrangelo 572f4332a7 Remove Trailers 2015-08-13 17:11:29 -07:00
Carl Mastrangelo b141093b3b Make serverInterceptor use MethodDescriptor 2015-08-07 09:28:29 -07:00
Carl Mastrangelo e76b8e7ee8 Renamed Server payload to message 2015-08-05 17:10:37 -07:00
Jack Coughlin 1ac64bd09d Remove ServerDelayInterceptor from AbstractTransportTest 2015-07-27 07:25:41 -07:00
Jack Coughlin 3e26b993ce Enforce request deadline
Use a ScheduledExecutorService in the ChannelImpl to terminate the
request by closing the ClientStream with status DEADLINE_EXCEEDED
2015-07-14 16:47:45 -07:00
Xudong Ma 8f51457ee1 Rename getSslSocketFactoryForCertainCert to be newSslSocketFactoryForCa.
Fixes #560
2015-06-25 14:46:05 -07:00
Jack Coughlin 77878a04ee Pass timeout header in ChannelImpl 2015-06-17 16:03:13 -07:00