Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit 94c190e

Browse files
chore: align transport type with previous labels
Change-Id: Ia98cb0f3987472d5a1751591ecb2df848348b63b
1 parent ed4ad83 commit 94c190e

2 files changed

Lines changed: 45 additions & 10 deletions

File tree

  • google-cloud-bigtable/src
    • main/java/com/google/cloud/bigtable/data/v2/internal/csm/attributes
    • test/java/com/google/cloud/bigtable/data/v2/internal/csm/attributes

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/csm/attributes/Util.java

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.bigtable.v2.PeerInfo;
2020
import com.google.bigtable.v2.PeerInfo.TransportType;
2121
import com.google.bigtable.v2.ResponseParams;
22+
import com.google.common.annotations.VisibleForTesting;
2223
import java.util.Locale;
2324
import java.util.Optional;
2425
import 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) {

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/csm/attributes/UtilTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,18 @@
1616

1717
package com.google.cloud.bigtable.data.v2.internal.csm.attributes;
1818

19+
import static com.google.common.truth.Truth.assertWithMessage;
20+
1921
import com.google.bigtable.v2.PeerInfo.TransportType;
2022
import org.junit.jupiter.api.Test;
2123

2224
class UtilTest {
2325
@Test
2426
void ensureAllTransportTypeHaveExpectedPrefix() {
2527
for (TransportType type : TransportType.values()) {
26-
// Ensure that no variant throws an error
27-
Util.transportTypeToString(type);
28+
assertWithMessage("%s should have a mapping", type)
29+
.that(Util.transportTypeToStringWithoutFallback(type))
30+
.isNotNull();
2831
}
2932
}
3033
}

0 commit comments

Comments
 (0)