1919import com .google .bigtable .v2 .PeerInfo ;
2020import com .google .bigtable .v2 .PeerInfo .TransportType ;
2121import com .google .bigtable .v2 .ResponseParams ;
22+ import com .google .common .annotations .VisibleForTesting ;
2223import java .util .Locale ;
2324import java .util .Optional ;
2425import javax .annotation .Nullable ;
@@ -42,17 +43,48 @@ public static String formatTransportType(@Nullable PeerInfo peerInfo) {
4243 }
4344
4445 public static String transportTypeToString (TransportType transportType ) {
45- if (transportType == TransportType .TRANSPORT_TYPE_UNKNOWN ) {
46- return "none" ;
46+ String label = transportTypeToStringWithoutFallback (transportType );
47+ if (label != null ) {
48+ return label ;
4749 }
48- if (transportType == TransportType .UNRECOGNIZED ) {
49- return "unrecognized" ;
50+ // In case the client is running with a newer version of protos
51+ if (transportType .name ().startsWith (TRANSPORT_TYPE_PREFIX )) {
52+ return transportType
53+ .name ()
54+ .substring (TRANSPORT_TYPE_PREFIX .length ())
55+ .toLowerCase (Locale .ENGLISH );
56+ } else {
57+ return transportType .name ();
5058 }
59+ }
5160
52- return transportType
53- .name ()
54- .substring (TRANSPORT_TYPE_PREFIX .length ())
55- .toLowerCase (Locale .ENGLISH );
61+ @ VisibleForTesting
62+ static String transportTypeToStringWithoutFallback (TransportType transportType ) {
63+ if (transportType == null ) {
64+ return "null" ;
65+ }
66+ switch (transportType ) {
67+ case TRANSPORT_TYPE_UNKNOWN :
68+ return "unknown" ;
69+ case TRANSPORT_TYPE_EXTERNAL :
70+ return "external" ;
71+ case TRANSPORT_TYPE_CLOUD_PATH :
72+ return "cloudpath" ;
73+ case TRANSPORT_TYPE_DIRECT_ACCESS :
74+ return "directpath" ;
75+ case TRANSPORT_TYPE_SESSION_UNKNOWN :
76+ return "session_unknown" ;
77+ case TRANSPORT_TYPE_SESSION_EXTERNAL :
78+ return "session_external" ;
79+ case TRANSPORT_TYPE_SESSION_CLOUD_PATH :
80+ return "session_cloudpath" ;
81+ case TRANSPORT_TYPE_SESSION_DIRECT_ACCESS :
82+ return "session_directpath" ;
83+ case UNRECOGNIZED :
84+ return "unrecognized" ;
85+ default :
86+ return null ;
87+ }
5688 }
5789
5890 public static String formatClusterIdMetricLabel (@ Nullable ResponseParams clusterInfo ) {
0 commit comments