-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core, census: move census dependency out of grpc-core #6577
core, census: move census dependency out of grpc-core #6577
Conversation
…s into grpc-census package.
…ensusServerStreamTracerFactory to eliminate dependencies on method signature.
… tracer factory with custom census stats module.
322ff09
to
b43535d
Compare
b43535d
to
7ff29e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fair. I think we'll just want to reduce the API surface before merging.
@@ -67,6 +68,7 @@ | |||
* starts earlier than the ServerCall. Therefore, only one tracer is created per stream/call and | |||
* it's the tracer that reports the summary to Census. | |||
*/ | |||
@VisibleForTesting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this should be marked @Internal
or similar? @VisibleForTesting
does not really limit users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to @Internal
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CensusStatsModule
and CensusTracingModule
are now package-private.
null, | ||
GrpcUtil.STOPWATCH_SUPPLIER, | ||
true, | ||
recordStartedRpcs, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't have to be now, but we'll probably want to re-think how this configuration in tests is done. Could be as simple as having a method on the builder that disables the census interceptors and then requiring they be added back manually by the test code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously this is done with AbstractManagedChannelImplBuilder#overrideCensusStatsModule(CensusStatsModule)
by injecting a CensusStatsModule
with custom implementation for testing. Now, I changed it to AbstractManagedChannelImplBuilder#setCensusStatsInterceptor(ClientInterceptor)
. Same idea, directly use the injected interceptor to replace the default census interceptor.
…_census_dep_out_of_core
core/src/main/java/io/grpc/internal/AbstractManagedChannelImplBuilder.java
Outdated
Show resolved
Hide resolved
/** | ||
* Returns a {@link ClientInterceptor} with custom stats implementation. | ||
*/ | ||
public static ClientInterceptor getClientInterceptor(CensusStatsModule censusStats) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method doesn't seem like it adds much. I'd expect to just make CensusStatsModule.getClientInterceptor() public instead of this. The benefit of a method like this is if we are able to hide CensusStatsModule, but this method isn't doing that.
But even better, it seems the only users of the Module construct it to just get the interceptor. Let's instead make this almost the same as the first getClientInterceptor method, just with more arguments. At that point we should make CensusStatsModule package-private.
Ditto for server-side.
* Accessor for getting {@link ClientInterceptor} or {@link ServerStreamTracer.Factory} with | ||
* default Census stats implementation. | ||
*/ | ||
public final class CensusStatsAccessor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this to InternalCensusStatsAccessor
and mark it @Internal
. It looks like we'll need to do a resonable amount of work before we can use zero-arg (or almost zero) methods to construct the objects here. Once we get to zero (or almost zero) we can make something here public or use the package-private+public-inner-class trick.
*/ | ||
@VisibleForTesting | ||
protected final T overrideCensusStatsModule(CensusStatsModule censusStats) { | ||
this.censusStatsOverride = censusStats; | ||
protected final T setCensusStatsInterceptor(ClientInterceptor statsInterceptor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to consider just adding an interceptor like normal, instead of having a special method for it. We would no longer need testing's TestingAccessor
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed tests to apply census interceptor/stream tracer factory as normal ones. This eliminates the special methods on channel/server builder for overriding census interceptor/stream tracer factory. With this approach, we would still need accessors for disabling default census interceptor/stream tracer factory.
…nterceptor/tracer factory that were used for testing. Tests directly apply census interceptor/tracer factory as applying normal interceptor/tracer factory.
d2c7256
to
c549c8d
Compare
…file implementation for the specific test.
89a56ad
to
35ebeda
Compare
…sting tracer factory for interop test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That cleaned up quite a bit.
recordRealTimeMetrics); | ||
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | ||
| InvocationTargetException e) { | ||
// Do nothing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may consider logging this at FINE/DEBUG level. Especially because it includes IllegalAccessException and InvocationTargetException. Ditto below and for server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Done.
Hello @voidzcy , this broke our monitoring. After updating from 1.24.1 to 1.27.2, the maven dependency 'io.grpc:grpc-core:1.27.2' did not include the new grpc-census artifact as transitive dependency and we had to include it explicitly. While this was probably the intention of the PR, we were still quite surprised by this breaking change. |
@gfelbing, if you were able to add grpc-census artifact and it work, then it wasn't a "breaking change." Any time when changing dependencies you may need to make sure they are correct. I'm sorry it surprised you, but there doesn't seem much more we can do about it, unless you have a suggestion for something that would have helped. |
… census dependency out of grpc-core (grpc#6577) Decouples grpc-core with census, while still preserve the default integration of census in grpc-core. Users wishing to enable census needs to add grpc-census to their runtime classpath. - Created a grpc-census module: - Moved CensusStatsModule.java and CensusTracingModule.java into grpc-census from grpc-core. CensusModuleTests.java is also moved. They now belong to io.grpc.census package. Moved DeprecatedCensusConstants.java into io.grpc.census.internal (is this necessary?) in grpc-census. - Created CensusStatsAccessor.java and CensusTracingAccessor.java, which are used to create census ClientInterceptor and ServerStreamTracer.Factory. - Everything in grpc-census are package private, except the accessor classes. They only publicly expose ClientInterceptor and ServerStreamTracer.Factory, no Census specific types are exposed. - Use runtime reflection to load and apply census stats/tracing to channel/server builders, if grpc-census is found in runtime classpath. - Removed special APIs on AbstractManagedChannelImplBuilder and AbstractServerImplBuilder for overriding census module. They are only used for testing. Now we changed tests to apply Census ClientInterceptor and ServerStreamTracer.Factory just as normal interceptor/stream tracer factory. Test writer is responsible for taking care of the ordering concerns of interceptors and stream tracer factories.
Major changes:
Created a
grpc-census
module:CensusStatsModule.java
andCensusTracingModule.java
intogrpc-census
fromgrpc-core
.CensusModuleTests.java
is also moved. They now belong toio.grpc.census
package.DeprecatedCensusConstants.java
intoio.grpc.census.internal
(is this necessary?) ingrpc-census
.CensusStatsAccessor.java
andCensusTracingAccessor.java
, which are used to create censusClientInterceptor
andServerStreamTracer.Factory
.grpc-census
are package private, except the accessor classes. They only publicly exposeClientInterceptor
andServerStreamTracer.Factory
, no Census specific types are exposed.grpc-core
's integration of census is done at runtime by reflection.Removed special APIs on
AbstractManagedChannelImplBuilder
andAbstractServerImplBuilder
for overriding census module. They are only used for testing. Now we changed tests to apply CensusClientInterceptor
andServerStreamTracer.Factory
just as normal interceptor/stream tracer factory. Test writer is responsible for taking care of the ordering concerns of interceptors and stream tracer factories.