Skip to content

Commit 20f1d73

Browse files
committed
fix: suggested changes
1 parent d8180d6 commit 20f1d73

17 files changed

Lines changed: 430 additions & 439 deletions

File tree

api/src/main/java/io/grpc/InternalTcpMetrics.java

Lines changed: 51 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,89 +16,83 @@
1616

1717
package io.grpc;
1818

19-
import java.util.ArrayList;
2019
import java.util.Arrays;
2120
import java.util.Collections;
2221
import java.util.List;
2322

2423
/**
2524
* TCP Metrics defined to be shared across transport implementations.
25+
* These metrics and their definitions are specified in
26+
* <a href=
27+
* "https://github.com/grpc/proposal/blob/master/A80-tcp-metrics.md">gRFC
28+
* A80</a>.
2629
*/
2730
@Internal
2831
public final class InternalTcpMetrics {
2932

30-
private InternalTcpMetrics() {}
33+
private InternalTcpMetrics() {
34+
}
3135

3236
private static final List<String> OPTIONAL_LABELS = Arrays.asList(
3337
"network.local.address",
3438
"network.local.port",
3539
"network.peer.address",
3640
"network.peer.port");
3741

38-
public static final DoubleHistogramMetricInstrument MIN_RTT_INSTRUMENT =
42+
public static final DoubleHistogramMetricInstrument MIN_RTT_INSTRUMENT =
3943
MetricInstrumentRegistry.getDefaultRegistry()
4044
.registerDoubleHistogram(
41-
"grpc.tcp.min_rtt",
42-
"Minimum round-trip time of a TCP connection",
43-
"s",
44-
getMinRttBuckets(),
45-
Collections.emptyList(),
46-
OPTIONAL_LABELS,
47-
false);
45+
"grpc.tcp.min_rtt",
46+
"Minimum round-trip time of a TCP connection",
47+
"s",
48+
Collections.emptyList(),
49+
Collections.emptyList(),
50+
OPTIONAL_LABELS,
51+
false);
4852

49-
public static final LongCounterMetricInstrument CONNECTIONS_CREATED_INSTRUMENT =
53+
public static final LongCounterMetricInstrument CONNECTIONS_CREATED_INSTRUMENT =
5054
MetricInstrumentRegistry
51-
.getDefaultRegistry()
52-
.registerLongCounter(
53-
"grpc.tcp.connections_created",
54-
"The total number of TCP connections established.",
55-
"{connection}",
56-
Collections.emptyList(),
57-
OPTIONAL_LABELS,
58-
false);
55+
.getDefaultRegistry()
56+
.registerLongCounter(
57+
"grpc.tcp.connections_created",
58+
"The total number of TCP connections established.",
59+
"{connection}",
60+
Collections.emptyList(),
61+
OPTIONAL_LABELS,
62+
false);
5963

60-
public static final LongUpDownCounterMetricInstrument CONNECTION_COUNT_INSTRUMENT =
64+
public static final LongUpDownCounterMetricInstrument CONNECTION_COUNT_INSTRUMENT =
6165
MetricInstrumentRegistry
62-
.getDefaultRegistry()
63-
.registerLongUpDownCounter(
64-
"grpc.tcp.connection_count",
65-
"The current number of active TCP connections.",
66-
"{connection}",
67-
Collections.emptyList(),
68-
OPTIONAL_LABELS,
69-
false
70-
);
66+
.getDefaultRegistry()
67+
.registerLongUpDownCounter(
68+
"grpc.tcp.connection_count",
69+
"The current number of active TCP connections.",
70+
"{connection}",
71+
Collections.emptyList(),
72+
OPTIONAL_LABELS,
73+
false);
7174

72-
public static final LongCounterMetricInstrument PACKETS_RETRANSMITTED_INSTRUMENT =
75+
public static final LongCounterMetricInstrument PACKETS_RETRANSMITTED_INSTRUMENT =
7376
MetricInstrumentRegistry
74-
.getDefaultRegistry()
75-
.registerLongCounter(
76-
"grpc.tcp.packets_retransmitted",
77-
"The total number of packets retransmitted for all TCP connections.",
78-
"{packet}",
79-
Collections.emptyList(),
80-
OPTIONAL_LABELS,
81-
false
82-
);
77+
.getDefaultRegistry()
78+
.registerLongCounter(
79+
"grpc.tcp.packets_retransmitted",
80+
"The total number of packets retransmitted for all TCP connections.",
81+
"{packet}",
82+
Collections.emptyList(),
83+
OPTIONAL_LABELS,
84+
false);
8385

84-
public static final LongCounterMetricInstrument RECURRING_RETRANSMITS_INSTRUMENT =
86+
public static final LongCounterMetricInstrument RECURRING_RETRANSMITS_INSTRUMENT =
8587
MetricInstrumentRegistry
86-
.getDefaultRegistry()
87-
.registerLongCounter(
88-
"grpc.tcp.recurring_retransmits",
89-
"The total number of times the retransmit timer popped for all TCP"
90-
+ " connections.",
91-
"{timeout}",
92-
Collections.emptyList(),
93-
OPTIONAL_LABELS,
94-
false
95-
);
88+
.getDefaultRegistry()
89+
.registerLongCounter(
90+
"grpc.tcp.recurring_retransmits",
91+
"The total number of times the retransmit timer "
92+
+ "popped for all TCP connections.",
93+
"{timeout}",
94+
Collections.emptyList(),
95+
OPTIONAL_LABELS,
96+
false);
9697

97-
private static List<Double> getMinRttBuckets() {
98-
List<Double> buckets = new ArrayList<>(100);
99-
for (int i = 1; i <= 100; i++) {
100-
buckets.add(1e-6 * Math.pow(2.0, i * 0.24));
101-
}
102-
return Collections.unmodifiableList(buckets);
103-
}
10498
}

api/src/main/java/io/grpc/ServerBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,9 @@ public T setBinaryLog(BinaryLog binaryLog) {
441441
* @param metricSink the metric sink to add.
442442
* @return this
443443
*/
444+
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/12693")
444445
public T addMetricSink(MetricSink metricSink) {
445-
throw new UnsupportedOperationException();
446+
return thisT();
446447
}
447448

448449
/**

netty/src/main/java/io/grpc/netty/NettyServer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static io.netty.channel.ChannelOption.ALLOCATOR;
2222
import static io.netty.channel.ChannelOption.SO_KEEPALIVE;
2323

24-
import com.google.common.annotations.VisibleForTesting;
2524
import com.google.common.base.MoreObjects;
2625
import com.google.common.base.Preconditions;
2726
import com.google.common.util.concurrent.ListenableFuture;
@@ -179,10 +178,6 @@ class NettyServer implements InternalServer, InternalWithLogId {
179178
String.valueOf(addresses));
180179
}
181180

182-
@VisibleForTesting
183-
MetricRecorder getMetricRecorder() {
184-
return metricRecorder;
185-
}
186181

187182
@Override
188183
public SocketAddress getListenSocketAddress() {

0 commit comments

Comments
 (0)