Skip to content

Commit a206cda

Browse files
committed
Change Attributes.Key debug strings to reference the API of the key
Users appear to be doing `attributes.toString()` to find keys they are interested in and then unable to find the name of the Key in our API. They workaround the problem by scanning through `attributes.keys()` looking for the key of interest. This is an abuse of the keys() API and unnecessary user friction. They'd happily use the API if they just knew where to find it. I added internal to some strings to make it clear that you shouldn't go looking to use it. There were many strings I didn't change. I focused on keys most likely to be seen by users, which meant keys in grpc-api and keys that are available via transport attributes. See grpc#1764 (comment)
1 parent 1b62084 commit a206cda

File tree

8 files changed

+17
-15
lines changed

8 files changed

+17
-15
lines changed

alts/src/main/java/io/grpc/alts/internal/AltsProtocolNegotiator.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ public final class AltsProtocolNegotiator {
5858
private static final AsyncSemaphore handshakeSemaphore = new AsyncSemaphore(32);
5959

6060
@Grpc.TransportAttr
61-
public static final Attributes.Key<TsiPeer> TSI_PEER_KEY = Attributes.Key.create("TSI_PEER");
61+
public static final Attributes.Key<TsiPeer> TSI_PEER_KEY =
62+
Attributes.Key.create("internal:TSI_PEER");
6263
@Grpc.TransportAttr
6364
public static final Attributes.Key<Object> AUTH_CONTEXT_KEY =
64-
Attributes.Key.create("AUTH_CONTEXT_KEY");
65+
Attributes.Key.create("internal:AUTH_CONTEXT_KEY");
6566

6667
private static final AsciiString SCHEME = AsciiString.of("https");
6768

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class EquivalentAddressGroup {
4444
@Attr
4545
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/6138")
4646
public static final Attributes.Key<String> ATTR_AUTHORITY_OVERRIDE =
47-
Attributes.Key.create("io.grpc.EquivalentAddressGroup.authorityOverride");
47+
Attributes.Key.create("io.grpc.EquivalentAddressGroup.ATTR_AUTHORITY_OVERRIDE");
4848
private final List<SocketAddress> addrs;
4949
private final Attributes attrs;
5050

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ private Grpc() {
3838
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1710")
3939
@TransportAttr
4040
public static final Attributes.Key<SocketAddress> TRANSPORT_ATTR_REMOTE_ADDR =
41-
Attributes.Key.create("remote-addr");
41+
Attributes.Key.create("io.grpc.Grpc.TRANSPORT_ATTR_REMOTE_ADDR");
4242

4343
/**
4444
* Attribute key for the local address of a transport.
4545
*/
4646
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1710")
4747
@TransportAttr
4848
public static final Attributes.Key<SocketAddress> TRANSPORT_ATTR_LOCAL_ADDR =
49-
Attributes.Key.create("local-addr");
49+
Attributes.Key.create("io.grpc.Grpc.TRANSPORT_ATTR_LOCAL_ADDR");
5050

5151
/**
5252
* Attribute key for SSL session of a transport.
5353
*/
5454
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1710")
5555
@TransportAttr
5656
public static final Attributes.Key<SSLSession> TRANSPORT_ATTR_SSL_SESSION =
57-
Attributes.Key.create("ssl-session");
57+
Attributes.Key.create("io.grpc.Grpc.TRANSPORT_ATTR_SSL_SESSION");
5858

5959
/**
6060
* Annotation for transport attributes. It follows the annotation semantics defined

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
public abstract class InternalConfigSelector {
3333
@NameResolver.ResolutionResultAttr
3434
public static final Attributes.Key<io.grpc.InternalConfigSelector> KEY
35-
= Attributes.Key.create("io.grpc.config-selector");
35+
= Attributes.Key.create("internal:io.grpc.config-selector");
3636

3737
// Use PickSubchannelArgs for SelectConfigArgs for now. May change over time.
3838
/** Selects the config for an PRC. */

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public abstract class LoadBalancer {
114114
@Internal
115115
@NameResolver.ResolutionResultAttr
116116
public static final Attributes.Key<Map<String, ?>> ATTR_HEALTH_CHECKING_CONFIG =
117-
Attributes.Key.create("health-checking-config");
117+
Attributes.Key.create("internal:health-checking-config");
118118
private int recursionCount;
119119

120120
/**

binder/src/main/java/io/grpc/binder/internal/BinderTransport.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,18 @@ public abstract class BinderTransport
109109
* active transport.
110110
*/
111111
@Internal
112-
public static final Attributes.Key<Integer> REMOTE_UID = Attributes.Key.create("remote-uid");
112+
public static final Attributes.Key<Integer> REMOTE_UID =
113+
Attributes.Key.create("internal:remote-uid");
113114

114115
/** The authority of the server. */
115116
@Internal
116117
public static final Attributes.Key<String> SERVER_AUTHORITY =
117-
Attributes.Key.create("server-authority");
118+
Attributes.Key.create("internal:server-authority");
118119

119120
/** A transport attribute to hold the {@link InboundParcelablePolicy}. */
120121
@Internal
121122
public static final Attributes.Key<InboundParcelablePolicy> INBOUND_PARCELABLE_POLICY =
122-
Attributes.Key.create("inbound-parcelable-policy");
123+
Attributes.Key.create("internal:inbound-parcelable-policy");
123124

124125
/**
125126
* Version code for this wire format.

binder/src/main/java/io/grpc/binder/internal/BinderTransportSecurity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
public final class BinderTransportSecurity {
4141

4242
private static final Attributes.Key<TransportAuthorizationState> TRANSPORT_AUTHORIZATION_STATE =
43-
Attributes.Key.create("transport-authorization-state");
43+
Attributes.Key.create("internal:transport-authorization-state");
4444

4545
private BinderTransportSecurity() {}
4646

grpclb/src/main/java/io/grpc/grpclb/GrpclbConstants.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,23 @@ public final class GrpclbConstants {
4646
* Attribute key for gRPC LB server addresses.
4747
*/
4848
public static final Attributes.Key<List<EquivalentAddressGroup>> ATTR_LB_ADDRS =
49-
Attributes.Key.create("io.grpc.grpclb.lbAddrs");
49+
Attributes.Key.create("io.grpc.grpclb.GrpclbConstants.ATTR_LB_ADDRS");
5050

5151
/**
5252
* The naming authority of a gRPC LB server address. It is an address-group-level attribute,
5353
* present when the address group is a LoadBalancer.
5454
*/
5555
@EquivalentAddressGroup.Attr
5656
public static final Attributes.Key<String> ATTR_LB_ADDR_AUTHORITY =
57-
Attributes.Key.create("io.grpc.grpclb.lbAddrAuthority");
57+
Attributes.Key.create("io.grpc.grpclb.GrpclbConstants.ATTR_LB_ADDR_AUTHORITY");
5858

5959
/**
6060
* Whether this EquivalentAddressGroup was provided by a GRPCLB server. It would be rare for this
6161
* value to be {@code false}; generally it would be better to not have the key present at all.
6262
*/
6363
@EquivalentAddressGroup.Attr
6464
public static final Attributes.Key<Boolean> ATTR_LB_PROVIDED_BACKEND =
65-
Attributes.Key.create("io.grpc.grpclb.lbProvidedBackend");
65+
Attributes.Key.create("io.grpc.grpclb.GrpclbConstants.ATTR_LB_PROVIDED_BACKEND");
6666

6767
private GrpclbConstants() { }
6868
}

0 commit comments

Comments
 (0)