Skip to content

Commit 94e92f4

Browse files
committed
census: use no arg methods for ClientInterceptors and StreamFactories
1 parent 6530b70 commit 94e92f4

File tree

2 files changed

+34
-69
lines changed

2 files changed

+34
-69
lines changed

census/src/main/java/io/grpc/census/GrpcCensus.java

Lines changed: 33 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121
import io.grpc.ClientInterceptor;
2222
import io.grpc.ServerBuilder;
2323
import io.grpc.ServerStreamTracer;
24-
import io.opencensus.stats.StatsRecorder;
25-
import io.opencensus.tags.Tagger;
26-
import io.opencensus.tags.propagation.TagContextBinarySerializer;
2724
import io.opencensus.trace.Tracing;
2825

26+
/**
27+
* The entrypoint for OpenCensus instrumentation functionality in gRPC.
28+
*
29+
* <p>GrpcCensus uses {@link io.opencensus.api.OpenCensus} APIs for instrumentation.
30+
*
31+
*/
2932
public final class GrpcCensus {
3033

34+
private GrpcCensus() {}
35+
3136
private static final Supplier<Stopwatch> STOPWATCH_SUPPLIER = new Supplier<Stopwatch>() {
3237
@Override
3338
public Stopwatch get() {
@@ -38,40 +43,15 @@ public Stopwatch get() {
3843
/**
3944
* Returns a {@link ClientInterceptor} with default stats implementation.
4045
*/
41-
public static ClientInterceptor newClientStatsInterceptor(
42-
boolean recordStartedRpcs,
43-
boolean recordFinishedRpcs,
44-
boolean recordRealTimeMetrics,
45-
boolean recordRetryMetrics) {
46+
public static ClientInterceptor newClientStatsInterceptor() {
4647
CensusStatsModule censusStats =
4748
new CensusStatsModule(
4849
STOPWATCH_SUPPLIER,
49-
true, /* propagateTags */
50-
recordStartedRpcs,
51-
recordFinishedRpcs,
52-
recordRealTimeMetrics,
53-
recordRetryMetrics);
54-
return censusStats.getClientInterceptor();
55-
}
56-
57-
/**
58-
* Returns a {@link ClientInterceptor} with custom stats implementation.
59-
*/
60-
public static ClientInterceptor newClientStatsInterceptor(
61-
Tagger tagger,
62-
TagContextBinarySerializer tagCtxSerializer,
63-
StatsRecorder statsRecorder,
64-
Supplier<Stopwatch> stopwatchSupplier,
65-
boolean propagateTags,
66-
boolean recordStartedRpcs,
67-
boolean recordFinishedRpcs,
68-
boolean recordRealTimeMetrics,
69-
boolean recordRetryMetrics) {
70-
CensusStatsModule censusStats =
71-
new CensusStatsModule(
72-
tagger, tagCtxSerializer, statsRecorder, stopwatchSupplier,
73-
propagateTags, recordStartedRpcs, recordFinishedRpcs, recordRealTimeMetrics,
74-
recordRetryMetrics);
50+
true,
51+
true,
52+
true,
53+
false,
54+
true);
7555
return censusStats.getClientInterceptor();
7656
}
7757

@@ -89,44 +69,22 @@ public static ClientInterceptor newClientTracingInterceptor() {
8969
/**
9070
* Returns a {@link ServerStreamTracer.Factory} with default stats implementation.
9171
*/
92-
public static ServerStreamTracer.Factory getServerStreamTracerFactory(
93-
boolean recordStartedRpcs,
94-
boolean recordFinishedRpcs,
95-
boolean recordRealTimeMetrics) {
72+
private static ServerStreamTracer.Factory newServerStatsStreamTracerFactory() {
9673
CensusStatsModule censusStats =
9774
new CensusStatsModule(
9875
STOPWATCH_SUPPLIER,
99-
true, /* propagateTags */
100-
recordStartedRpcs,
101-
recordFinishedRpcs,
102-
recordRealTimeMetrics,
103-
false);
104-
return censusStats.getServerTracerFactory();
105-
}
106-
107-
/**
108-
* Returns a {@link ServerStreamTracer.Factory} with custom stats implementation.
109-
*/
110-
public static ServerStreamTracer.Factory getServerStreamTracerFactory(
111-
Tagger tagger,
112-
TagContextBinarySerializer tagCtxSerializer,
113-
StatsRecorder statsRecorder,
114-
Supplier<Stopwatch> stopwatchSupplier,
115-
boolean propagateTags,
116-
boolean recordStartedRpcs,
117-
boolean recordFinishedRpcs,
118-
boolean recordRealTimeMetrics) {
119-
CensusStatsModule censusStats =
120-
new CensusStatsModule(
121-
tagger, tagCtxSerializer, statsRecorder, stopwatchSupplier,
122-
propagateTags, recordStartedRpcs, recordFinishedRpcs, recordRealTimeMetrics, false);
76+
true,
77+
true,
78+
true,
79+
false,
80+
true);
12381
return censusStats.getServerTracerFactory();
12482
}
12583

12684
/**
12785
* Returns a {@link ServerStreamTracer.Factory} with default tracing implementation.
12886
*/
129-
public static ServerStreamTracer.Factory getServerStreamTracerFactory() {
87+
private static ServerStreamTracer.Factory newServerTracingStreamTracerFactory() {
13088
CensusTracingModule censusTracing =
13189
new CensusTracingModule(
13290
Tracing.getTracer(),
@@ -135,14 +93,21 @@ public static ServerStreamTracer.Factory getServerStreamTracerFactory() {
13593
}
13694

13795
/**
138-
* Configures the given {@link ServerBuilder} with the provided serverStreamTracerFactory.
96+
* Configures the given {@link ServerBuilder} with serverStreamTracerFactory for stats.
97+
*
98+
* @param serverBuilder the server builder to configure
99+
*/
100+
public static void configureServerBuilderWithStatsTracer(ServerBuilder<?> serverBuilder) {
101+
serverBuilder.addStreamTracerFactory(newServerStatsStreamTracerFactory());
102+
}
103+
104+
/**
105+
* Configures the given {@link ServerBuilder} with serverStreamTracerFactory for tracing.
139106
*
140107
* @param serverBuilder the server builder to configure
141-
* @param serverStreamTracerFactory the server stream tracer factory to configure
142108
*/
143-
public static void configureServerBuilder(ServerBuilder<?> serverBuilder,
144-
ServerStreamTracer.Factory serverStreamTracerFactory) {
145-
serverBuilder.addStreamTracerFactory(serverStreamTracerFactory);
109+
public static void configureServerBuilderWithTracingTracer(ServerBuilder<?> serverBuilder) {
110+
serverBuilder.addStreamTracerFactory(newServerTracingStreamTracerFactory());
146111
}
147112

148113
}

core/src/main/java/io/grpc/internal/ServerImplBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static ServerBuilder<?> forPort(int port) {
9999
ServerCallExecutorSupplier executorSupplier;
100100

101101
/**
102-
* An interface to provide to provide transport specific information for the server. This method
102+
* An interface to provide transport specific information for the server. This method
103103
* is meant for Transport implementors and should not be used by normal users.
104104
*/
105105
public interface ClientTransportServersBuilder {

0 commit comments

Comments
 (0)