Skip to content

Commit e54cf7d

Browse files
authored
fix: fix attempt status tag for metrics (#1477)
1 parent 331dcfb commit e54cf7d

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

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

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

1818
import static com.google.api.gax.tracing.ApiTracerFactory.OperationType;
1919

20+
import com.google.api.gax.retrying.ServerStreamingAttemptException;
2021
import com.google.api.gax.tracing.SpanName;
2122
import com.google.cloud.bigtable.stats.StatsRecorderWrapper;
2223
import com.google.common.annotations.VisibleForTesting;
@@ -256,6 +257,14 @@ private void recordAttemptCompletion(@Nullable Throwable status) {
256257
serverLatencyTimerIsRunning = false;
257258
}
258259
}
260+
261+
// Patch the status until it's fixed in gax. When an attempt failed,
262+
// it'll throw a ServerStreamingAttemptException. Unwrap the exception
263+
// so it could get processed by extractStatus
264+
if (status instanceof ServerStreamingAttemptException) {
265+
status = status.getCause();
266+
}
267+
259268
recorder.putAttemptLatencies(attemptTimer.elapsed(TimeUnit.MILLISECONDS));
260269
recorder.recordAttempt(Util.extractStatus(status), tableId, zone, cluster);
261270
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.cloud.bigtable.data.v2.stub.metrics;
1717

18+
import com.google.api.gax.retrying.ServerStreamingAttemptException;
1819
import com.google.api.gax.tracing.ApiTracerFactory.OperationType;
1920
import com.google.api.gax.tracing.SpanName;
2021
import com.google.common.base.Stopwatch;
@@ -166,6 +167,13 @@ private void recordAttemptCompletion(@Nullable Throwable throwable) {
166167
RpcMeasureConstants.BIGTABLE_ATTEMPT_LATENCY,
167168
attemptTimer.elapsed(TimeUnit.MILLISECONDS));
168169

170+
// Patch the throwable until it's fixed in gax. When an attempt failed,
171+
// it'll throw a ServerStreamingAttemptException. Unwrap the exception
172+
// so it could get processed by extractStatus
173+
if (throwable instanceof ServerStreamingAttemptException) {
174+
throwable = throwable.getCause();
175+
}
176+
169177
TagContextBuilder tagCtx =
170178
newTagCtxBuilder()
171179
.putLocal(

0 commit comments

Comments
 (0)