Skip to content

Commit

Permalink
api: Hide internal metric APIs
Browse files Browse the repository at this point in the history
Some APIs were marked experimental but had internal APIs in their
surface. These were all changed to internal. And then the internal APIs
were mostly hidden from generated documentation.

All these APIs will eventually become public and maybe even stable. But
they need some iteration before we're ready for others to start using
them.
  • Loading branch information
ejona86 committed May 9, 2024
1 parent 1e731be commit f737cbc
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 16 deletions.
4 changes: 4 additions & 0 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ dependencies {
tasks.named("javadoc").configure {
source sourceSets.context.allSource
// We want io.grpc.Internal, but not io.grpc.Internal*
exclude 'io/grpc/*MetricInstrument.java'
exclude 'io/grpc/*MetricInstrumentRegistry.java'
exclude 'io/grpc/Internal?*.java'
exclude 'io/grpc/MetricRecorder.java'
exclude 'io/grpc/MetricSink.java'
}

tasks.named("sourcesJar").configure {
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/io/grpc/ForwardingChannelBuilder2.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public T disableServiceConfigLookUp() {
}

@Override
public T addMetricSink(MetricSink metricSink) {
protected T addMetricSink(MetricSink metricSink) {
delegate().addMetricSink(metricSink);
return thisT();
}
Expand Down
6 changes: 6 additions & 0 deletions api/src/main/java/io/grpc/InternalManagedChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
/**
* Internal accessors for {@link ManagedChannelBuilder}.
*/
@Internal
public final class InternalManagedChannelBuilder {
private InternalManagedChannelBuilder() {}

Expand All @@ -27,5 +28,10 @@ public static <T extends ManagedChannelBuilder<T>> T interceptWithTarget(
return builder.interceptWithTarget(factory);
}

public static <T extends ManagedChannelBuilder<T>> T addMetricSink(
ManagedChannelBuilder<T> builder, MetricSink metricSink) {
return builder.addMetricSink(metricSink);
}

public interface InternalInterceptorFactory extends ManagedChannelBuilder.InterceptorFactory {}
}
2 changes: 1 addition & 1 deletion api/src/main/java/io/grpc/LoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ public NameResolverRegistry getNameResolverRegistry() {
*
* @since 1.64.0
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/11110")
@Internal
public MetricRecorder getMetricRecorder() {
return new MetricRecorder() {};
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/io/grpc/ManagedChannelBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,8 @@ public T disableServiceConfigLookUp() {
* @return this
* @since 1.64.0
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/11110")
public T addMetricSink(MetricSink metricSink) {
@Internal
protected T addMetricSink(MetricSink metricSink) {
throw new UnsupportedOperationException();
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/io/grpc/MetricSink.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* An internal interface representing a receiver or aggregator of gRPC metrics data.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/11110")
@Internal
public interface MetricSink {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ public ManagedChannelImplBuilder enableCheckAuthority() {
}

@Override
public ManagedChannelImplBuilder addMetricSink(MetricSink metricSink) {
protected ManagedChannelImplBuilder addMetricSink(MetricSink metricSink) {
metricSinks.add(checkNotNull(metricSink, "metric sink"));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void configureServerBuilder(ServerBuilder<?> serverBuilder) {
* Configures the given {@link ManagedChannelBuilder} with OpenTelemetry metrics instrumentation.
*/
public void configureChannelBuilder(ManagedChannelBuilder<?> builder) {
builder.addMetricSink(sink);
InternalManagedChannelBuilder.addMetricSink(builder, sink);
InternalManagedChannelBuilder.interceptWithTarget(
builder, openTelemetryMetricsModule::getClientInterceptor);
}
Expand Down
10 changes: 6 additions & 4 deletions rls/src/test/java/io/grpc/rls/RlsLoadBalancerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.grpc.ConnectivityStateInfo;
import io.grpc.EquivalentAddressGroup;
import io.grpc.ForwardingChannelBuilder2;
import io.grpc.InternalManagedChannelBuilder;
import io.grpc.LoadBalancer.CreateSubchannelArgs;
import io.grpc.LoadBalancer.Helper;
import io.grpc.LoadBalancer.PickDetailsConsumer;
Expand Down Expand Up @@ -310,10 +311,11 @@ public void metricsWithRealChannel() throws Exception {
.start());
MetricSink metrics = mock(MetricSink.class, delegatesTo(new NoopMetricSink()));
ManagedChannel channel = grpcCleanupRule.register(
InProcessChannelBuilder.forName("fake-bigtable.googleapis.com")
.defaultServiceConfig(parseJson(getServiceConfigJsonStr()))
.addMetricSink(metrics)
.directExecutor()
InternalManagedChannelBuilder.addMetricSink(
InProcessChannelBuilder.forName("fake-bigtable.googleapis.com")
.defaultServiceConfig(parseJson(getServiceConfigJsonStr()))
.directExecutor(),
metrics)
.build());

StreamRecorder<Void> recorder = StreamRecorder.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.grpc.ConnectivityStateInfo;
import io.grpc.DoubleHistogramMetricInstrument;
import io.grpc.EquivalentAddressGroup;
import io.grpc.InternalManagedChannelBuilder;
import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.CreateSubchannelArgs;
import io.grpc.LoadBalancer.Helper;
Expand Down Expand Up @@ -1268,11 +1269,13 @@ public void metricWithRealChannel() throws Exception {
.start());
MetricSink metrics = mock(MetricSink.class, delegatesTo(new NoopMetricSink()));
Channel channel = grpcCleanupRule.register(
InProcessChannelBuilder.forName(serverName)
.defaultServiceConfig(Collections.singletonMap(
"loadBalancingConfig", Arrays.asList(Collections.singletonMap(
"weighted_round_robin", Collections.emptyMap()))))
.addMetricSink(metrics)
InternalManagedChannelBuilder.addMetricSink(
InProcessChannelBuilder.forName(serverName)
.defaultServiceConfig(Collections.singletonMap(
"loadBalancingConfig", Arrays.asList(Collections.singletonMap(
"weighted_round_robin", Collections.emptyMap()))))
.directExecutor(),
metrics)
.directExecutor()
.build());

Expand Down

0 comments on commit f737cbc

Please sign in to comment.