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 {
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 {

View File

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

View File

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

View File

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

View File

@ -628,8 +628,8 @@ public abstract class ManagedChannelBuilder<T extends ManagedChannelBuilder<T>>
* @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();
}

View File

@ -23,7 +23,7 @@ import java.util.Set;
/**
* 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 {
/**

View File

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

View File

@ -145,7 +145,7 @@ public final class GrpcOpenTelemetry {
* 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);
}

View File

@ -42,6 +42,7 @@ import io.grpc.ConnectivityState;
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;
@ -310,10 +311,11 @@ public class RlsLoadBalancerTest {
.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();

View File

@ -44,6 +44,7 @@ import io.grpc.ConnectivityState;
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;
@ -1268,11 +1269,13 @@ public class WeightedRoundRobinLoadBalancerTest {
.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());