Skip to content

Commit

Permalink
fix: fix attempt status tag for metrics (#1477)
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Oct 25, 2022
1 parent 331dcfb commit e54cf7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Expand Up @@ -17,6 +17,7 @@

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

import com.google.api.gax.retrying.ServerStreamingAttemptException;
import com.google.api.gax.tracing.SpanName;
import com.google.cloud.bigtable.stats.StatsRecorderWrapper;
import com.google.common.annotations.VisibleForTesting;
Expand Down Expand Up @@ -256,6 +257,14 @@ private void recordAttemptCompletion(@Nullable Throwable status) {
serverLatencyTimerIsRunning = false;
}
}

// Patch the status until it's fixed in gax. When an attempt failed,
// it'll throw a ServerStreamingAttemptException. Unwrap the exception
// so it could get processed by extractStatus
if (status instanceof ServerStreamingAttemptException) {
status = status.getCause();
}

recorder.putAttemptLatencies(attemptTimer.elapsed(TimeUnit.MILLISECONDS));
recorder.recordAttempt(Util.extractStatus(status), tableId, zone, cluster);
}
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package com.google.cloud.bigtable.data.v2.stub.metrics;

import com.google.api.gax.retrying.ServerStreamingAttemptException;
import com.google.api.gax.tracing.ApiTracerFactory.OperationType;
import com.google.api.gax.tracing.SpanName;
import com.google.common.base.Stopwatch;
Expand Down Expand Up @@ -166,6 +167,13 @@ private void recordAttemptCompletion(@Nullable Throwable throwable) {
RpcMeasureConstants.BIGTABLE_ATTEMPT_LATENCY,
attemptTimer.elapsed(TimeUnit.MILLISECONDS));

// Patch the throwable until it's fixed in gax. When an attempt failed,
// it'll throw a ServerStreamingAttemptException. Unwrap the exception
// so it could get processed by extractStatus
if (throwable instanceof ServerStreamingAttemptException) {
throwable = throwable.getCause();
}

TagContextBuilder tagCtx =
newTagCtxBuilder()
.putLocal(
Expand Down

0 comments on commit e54cf7d

Please sign in to comment.