api: Hide internal metric APIs

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.
This commit is contained in:
Eric Anderson 2024-05-07 13:50:45 -07:00
parent 1e731be49a
commit f737cbc143
10 changed files with 31 additions and 16 deletions

View File

@ -55,7 +55,11 @@ dependencies {
tasks.named("javadoc").configure { tasks.named("javadoc").configure {
source sourceSets.context.allSource source sourceSets.context.allSource
// We want io.grpc.Internal, but not io.grpc.Internal* // 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/Internal?*.java'
exclude 'io/grpc/MetricRecorder.java'
exclude 'io/grpc/MetricSink.java'
} }
tasks.named("sourcesJar").configure { tasks.named("sourcesJar").configure {

View File

@ -258,7 +258,7 @@ public abstract class ForwardingChannelBuilder2<T extends ManagedChannelBuilder<
} }
@Override @Override
public T addMetricSink(MetricSink metricSink) { protected T addMetricSink(MetricSink metricSink) {
delegate().addMetricSink(metricSink); delegate().addMetricSink(metricSink);
return thisT(); return thisT();
} }

View File

@ -19,6 +19,7 @@ package io.grpc;
/** /**
* Internal accessors for {@link ManagedChannelBuilder}. * Internal accessors for {@link ManagedChannelBuilder}.
*/ */
@Internal
public final class InternalManagedChannelBuilder { public final class InternalManagedChannelBuilder {
private InternalManagedChannelBuilder() {} private InternalManagedChannelBuilder() {}
@ -27,5 +28,10 @@ public final class InternalManagedChannelBuilder {
return builder.interceptWithTarget(factory); 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 {} public interface InternalInterceptorFactory extends ManagedChannelBuilder.InterceptorFactory {}
} }

View File

@ -1255,7 +1255,7 @@ public abstract class LoadBalancer {
* *
* @since 1.64.0 * @since 1.64.0
*/ */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/11110") @Internal
public MetricRecorder getMetricRecorder() { public MetricRecorder getMetricRecorder() {
return new MetricRecorder() {}; return new MetricRecorder() {};
} }

View File

@ -628,8 +628,8 @@ public abstract class ManagedChannelBuilder<T extends ManagedChannelBuilder<T>>
* @return this * @return this
* @since 1.64.0 * @since 1.64.0
*/ */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/11110") @Internal
public T addMetricSink(MetricSink metricSink) { protected T addMetricSink(MetricSink metricSink) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@ -23,7 +23,7 @@ import java.util.Set;
/** /**
* An internal interface representing a receiver or aggregator of gRPC metrics data. * 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 { public interface MetricSink {
/** /**

View File

@ -687,7 +687,7 @@ public final class ManagedChannelImplBuilder
} }
@Override @Override
public ManagedChannelImplBuilder addMetricSink(MetricSink metricSink) { protected ManagedChannelImplBuilder addMetricSink(MetricSink metricSink) {
metricSinks.add(checkNotNull(metricSink, "metric sink")); metricSinks.add(checkNotNull(metricSink, "metric sink"));
return this; return this;
} }

View File

@ -145,7 +145,7 @@ public final class GrpcOpenTelemetry {
* Configures the given {@link ManagedChannelBuilder} with OpenTelemetry metrics instrumentation. * Configures the given {@link ManagedChannelBuilder} with OpenTelemetry metrics instrumentation.
*/ */
public void configureChannelBuilder(ManagedChannelBuilder<?> builder) { public void configureChannelBuilder(ManagedChannelBuilder<?> builder) {
builder.addMetricSink(sink); InternalManagedChannelBuilder.addMetricSink(builder, sink);
InternalManagedChannelBuilder.interceptWithTarget( InternalManagedChannelBuilder.interceptWithTarget(
builder, openTelemetryMetricsModule::getClientInterceptor); builder, openTelemetryMetricsModule::getClientInterceptor);
} }

View File

@ -42,6 +42,7 @@ import io.grpc.ConnectivityState;
import io.grpc.ConnectivityStateInfo; import io.grpc.ConnectivityStateInfo;
import io.grpc.EquivalentAddressGroup; import io.grpc.EquivalentAddressGroup;
import io.grpc.ForwardingChannelBuilder2; import io.grpc.ForwardingChannelBuilder2;
import io.grpc.InternalManagedChannelBuilder;
import io.grpc.LoadBalancer.CreateSubchannelArgs; import io.grpc.LoadBalancer.CreateSubchannelArgs;
import io.grpc.LoadBalancer.Helper; import io.grpc.LoadBalancer.Helper;
import io.grpc.LoadBalancer.PickDetailsConsumer; import io.grpc.LoadBalancer.PickDetailsConsumer;
@ -310,10 +311,11 @@ public class RlsLoadBalancerTest {
.start()); .start());
MetricSink metrics = mock(MetricSink.class, delegatesTo(new NoopMetricSink())); MetricSink metrics = mock(MetricSink.class, delegatesTo(new NoopMetricSink()));
ManagedChannel channel = grpcCleanupRule.register( ManagedChannel channel = grpcCleanupRule.register(
InProcessChannelBuilder.forName("fake-bigtable.googleapis.com") InternalManagedChannelBuilder.addMetricSink(
.defaultServiceConfig(parseJson(getServiceConfigJsonStr())) InProcessChannelBuilder.forName("fake-bigtable.googleapis.com")
.addMetricSink(metrics) .defaultServiceConfig(parseJson(getServiceConfigJsonStr()))
.directExecutor() .directExecutor(),
metrics)
.build()); .build());
StreamRecorder<Void> recorder = StreamRecorder.create(); StreamRecorder<Void> recorder = StreamRecorder.create();

View File

@ -44,6 +44,7 @@ import io.grpc.ConnectivityState;
import io.grpc.ConnectivityStateInfo; import io.grpc.ConnectivityStateInfo;
import io.grpc.DoubleHistogramMetricInstrument; import io.grpc.DoubleHistogramMetricInstrument;
import io.grpc.EquivalentAddressGroup; import io.grpc.EquivalentAddressGroup;
import io.grpc.InternalManagedChannelBuilder;
import io.grpc.LoadBalancer; import io.grpc.LoadBalancer;
import io.grpc.LoadBalancer.CreateSubchannelArgs; import io.grpc.LoadBalancer.CreateSubchannelArgs;
import io.grpc.LoadBalancer.Helper; import io.grpc.LoadBalancer.Helper;
@ -1268,11 +1269,13 @@ public class WeightedRoundRobinLoadBalancerTest {
.start()); .start());
MetricSink metrics = mock(MetricSink.class, delegatesTo(new NoopMetricSink())); MetricSink metrics = mock(MetricSink.class, delegatesTo(new NoopMetricSink()));
Channel channel = grpcCleanupRule.register( Channel channel = grpcCleanupRule.register(
InProcessChannelBuilder.forName(serverName) InternalManagedChannelBuilder.addMetricSink(
.defaultServiceConfig(Collections.singletonMap( InProcessChannelBuilder.forName(serverName)
"loadBalancingConfig", Arrays.asList(Collections.singletonMap( .defaultServiceConfig(Collections.singletonMap(
"weighted_round_robin", Collections.emptyMap())))) "loadBalancingConfig", Arrays.asList(Collections.singletonMap(
.addMetricSink(metrics) "weighted_round_robin", Collections.emptyMap()))))
.directExecutor(),
metrics)
.directExecutor() .directExecutor()
.build()); .build());