Skip to content
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

Merged
merged 24 commits into from
Jan 13, 2020

Conversation

voidzcy
Copy link
Contributor

@voidzcy voidzcy commented Dec 28, 2019

Major changes:

  • 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.
  • grpc-core's integration of census is done at runtime by reflection.

  • 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.

@voidzcy voidzcy force-pushed the refactor/move_census_dep_out_of_core branch 2 times, most recently from 322ff09 to b43535d Compare December 28, 2019 03:43
@voidzcy voidzcy force-pushed the refactor/move_census_dep_out_of_core branch from b43535d to 7ff29e7 Compare December 28, 2019 03:53
@voidzcy voidzcy marked this pull request as ready for review December 30, 2019 05:21
Copy link
Member

@ejona86 ejona86 left a 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
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to @Internal.

Copy link
Contributor Author

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,
Copy link
Member

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.

Copy link
Contributor Author

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.

/**
* Returns a {@link ClientInterceptor} with custom stats implementation.
*/
public static ClientInterceptor getClientInterceptor(CensusStatsModule censusStats) {
Copy link
Member

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 {
Copy link
Member

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) {
Copy link
Member

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.

Copy link
Contributor Author

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.
@voidzcy voidzcy force-pushed the refactor/move_census_dep_out_of_core branch from d2c7256 to c549c8d Compare January 9, 2020 21:28
@voidzcy voidzcy force-pushed the refactor/move_census_dep_out_of_core branch from 89a56ad to 35ebeda Compare January 9, 2020 21:40
Copy link
Member

@ejona86 ejona86 left a 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.
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Done.

@gfelbing
Copy link
Contributor

gfelbing commented Mar 5, 2020

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.

@ejona86
Copy link
Member

ejona86 commented Mar 5, 2020

@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.

dfawley pushed a commit to dfawley/grpc-java that referenced this pull request Jan 15, 2021
… 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.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants