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

Commit 0255504

Browse files
fix null handling of sideband data formating and remove stale code
Change-Id: Icf1b8ed5d020c9bf5386173b817a89f1679369b4
1 parent a1cc2f8 commit 0255504

3 files changed

Lines changed: 24 additions & 38 deletions

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/MetadataExtractorInterceptor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import com.google.api.core.InternalApi;
1919
import com.google.api.gax.grpc.GrpcCallContext;
20-
import com.google.api.gax.grpc.GrpcTransportChannel;
2120
import com.google.bigtable.v2.PeerInfo;
2221
import com.google.bigtable.v2.ResponseParams;
2322
import com.google.common.base.Strings;

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/BuiltinMetricsTracer.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,17 @@
3434
import com.google.api.core.ObsoleteApi;
3535
import com.google.api.gax.retrying.ServerStreamingAttemptException;
3636
import com.google.api.gax.tracing.SpanName;
37-
import com.google.auto.value.AutoValue;
3837
import com.google.bigtable.v2.PeerInfo;
3938
import com.google.cloud.bigtable.Version;
4039
import com.google.cloud.bigtable.data.v2.stub.MetadataExtractorInterceptor;
4140
import com.google.common.base.Stopwatch;
4241
import com.google.common.math.IntMath;
43-
import com.google.gson.reflect.TypeToken;
4442
import io.grpc.Deadline;
4543
import io.opentelemetry.api.common.Attributes;
4644
import io.opentelemetry.api.metrics.DoubleGauge;
4745
import io.opentelemetry.api.metrics.DoubleHistogram;
4846
import io.opentelemetry.api.metrics.LongCounter;
4947
import java.time.Duration;
50-
import java.util.Map;
5148
import java.util.Optional;
5249
import java.util.concurrent.CancellationException;
5350
import java.util.concurrent.TimeUnit;
@@ -61,22 +58,6 @@
6158
* bigtable.googleapis.com/client namespace
6259
*/
6360
class BuiltinMetricsTracer extends BigtableTracer {
64-
@AutoValue
65-
abstract static class TransportAttrs {
66-
@Nullable
67-
abstract String getLocality();
68-
69-
@Nullable
70-
abstract String getBackendService();
71-
72-
static TransportAttrs create(@Nullable String locality, @Nullable String backendService) {
73-
return new AutoValue_BuiltinMetricsTracer_TransportAttrs(locality, backendService);
74-
}
75-
}
76-
77-
private static final TypeToken<Map<String, String>> LOCALITY_TYPE =
78-
new TypeToken<Map<String, String>>() {};
79-
8061
private static final String NAME = "java-bigtable/" + Version.VERSION;
8162
private final OperationType operationType;
8263
private final SpanName spanName;
@@ -370,8 +351,8 @@ private void recordOperationCompletion(@Nullable Throwable status) {
370351
Attributes attributes =
371352
baseAttributes.toBuilder()
372353
.put(TABLE_ID_KEY, tableId)
373-
.put(CLUSTER_ID_KEY, Util.formatClusterIdMetricLabel(sidebandData.getResponseParams()))
374-
.put(ZONE_ID_KEY, Util.formatZoneIdMetricLabel(sidebandData.getResponseParams()))
354+
.put(CLUSTER_ID_KEY, Util.formatClusterIdMetricLabel(sidebandData))
355+
.put(ZONE_ID_KEY, Util.formatZoneIdMetricLabel(sidebandData))
375356
.put(METHOD_KEY, spanName.toString())
376357
.put(CLIENT_NAME_KEY, NAME)
377358
.put(STREAMING_KEY, isStreaming)
@@ -425,8 +406,8 @@ private void recordAttemptCompletion(@Nullable Throwable status) {
425406
Attributes attributes =
426407
baseAttributes.toBuilder()
427408
.put(TABLE_ID_KEY, tableId)
428-
.put(CLUSTER_ID_KEY, Util.formatClusterIdMetricLabel(sidebandData.getResponseParams()))
429-
.put(ZONE_ID_KEY, Util.formatZoneIdMetricLabel(sidebandData.getResponseParams()))
409+
.put(CLUSTER_ID_KEY, Util.formatClusterIdMetricLabel(sidebandData))
410+
.put(ZONE_ID_KEY, Util.formatZoneIdMetricLabel(sidebandData))
430411
.put(METHOD_KEY, spanName.toString())
431412
.put(CLIENT_NAME_KEY, NAME)
432413
.put(STREAMING_KEY, isStreaming)
@@ -445,7 +426,7 @@ private void recordAttemptCompletion(@Nullable Throwable status) {
445426
String transportSubzone = "";
446427

447428
if (sidebandData != null) {
448-
transportTypeStr = Util.formatTransportTypeMetricLabel(sidebandData.getPeerInfo());
429+
transportTypeStr = Util.formatTransportTypeMetricLabel(sidebandData);
449430
transportZone =
450431
Optional.ofNullable(sidebandData.getPeerInfo())
451432
.map(PeerInfo::getApplicationFrontendZone)

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/Util.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.google.bigtable.v2.SampleRowKeysRequest;
3636
import com.google.bigtable.v2.TableName;
3737
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings;
38-
import com.google.common.base.Strings;
38+
import com.google.cloud.bigtable.data.v2.stub.MetadataExtractorInterceptor;
3939
import com.google.common.base.Suppliers;
4040
import com.google.common.collect.ImmutableMap;
4141
import io.grpc.Metadata;
@@ -177,26 +177,32 @@ public static OpenTelemetrySdk newInternalOpentelemetry(
177177
return OpenTelemetrySdk.builder().setMeterProvider(meterProviderBuilder.build()).build();
178178
}
179179

180-
public static String formatTransportTypeMetricLabel(PeerInfo peerInfo) {
181-
return Optional.ofNullable(peerInfo)
180+
public static String formatTransportTypeMetricLabel(
181+
MetadataExtractorInterceptor.SidebandData sidebandData) {
182+
return Optional.ofNullable(sidebandData)
183+
.flatMap(s -> Optional.ofNullable(s.getPeerInfo()))
182184
.map(PeerInfo::getTransportType)
183185
.orElse(PeerInfo.TransportType.TRANSPORT_TYPE_UNKNOWN)
184186
.name()
185187
.replace("TRANSPORT_TYPE_", "")
186188
.toLowerCase(Locale.ENGLISH);
187189
}
188190

189-
public static String formatClusterIdMetricLabel(ResponseParams params) {
190-
if (params == null || Strings.isNullOrEmpty(params.getClusterId())) {
191-
return "<unspecified>";
192-
}
193-
return params.getClusterId();
191+
public static String formatClusterIdMetricLabel(
192+
@Nullable MetadataExtractorInterceptor.SidebandData sidebandData) {
193+
return Optional.ofNullable(sidebandData)
194+
.flatMap(d -> Optional.ofNullable(d.getResponseParams()))
195+
.map(ResponseParams::getClusterId)
196+
.filter(s -> !s.isEmpty())
197+
.orElse("<unspecified>");
194198
}
195199

196-
public static String formatZoneIdMetricLabel(ResponseParams params) {
197-
if (params == null || Strings.isNullOrEmpty(params.getZoneId())) {
198-
return "global";
199-
}
200-
return params.getZoneId();
200+
public static String formatZoneIdMetricLabel(
201+
@Nullable MetadataExtractorInterceptor.SidebandData sidebandData) {
202+
return Optional.ofNullable(sidebandData)
203+
.flatMap(d -> Optional.ofNullable(d.getResponseParams()))
204+
.map(ResponseParams::getZoneId)
205+
.filter(s -> !s.isEmpty())
206+
.orElse("global");
201207
}
202208
}

0 commit comments

Comments
 (0)