Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Sep 9, 2021
1 parent 73cecdd commit ec37f18
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
Expand Up @@ -31,7 +31,7 @@
*/
class BigtableTracer extends BaseApiTracer {
private final List<ApiTracer> children;
private int attempt = 0;
private volatile int attempt = 0;

BigtableTracer(List<ApiTracer> children) {
this.children = ImmutableList.copyOf(children);
Expand Down
Expand Up @@ -36,9 +36,9 @@
/** Utilities to help integrating with OpenCensus. */
class Util {
static final Metadata.Key<String> ATTEMPT_HEADER_KEY =
Metadata.Key.of("attempt", Metadata.ASCII_STRING_MARSHALLER);
static final Metadata.Key<String> TIMESTAMP_HEADER_KEY =
Metadata.Key.of("client-timing", Metadata.ASCII_STRING_MARSHALLER);
Metadata.Key.of("x-bigtable-attempt", Metadata.ASCII_STRING_MARSHALLER);
static final Metadata.Key<String> ATTEMPT_EPOCH_KEY =
Metadata.Key.of("x-bigtable-client-attempt-epoch", Metadata.ASCII_STRING_MARSHALLER);

private static final TagValue OK_STATUS = TagValue.create(StatusCode.Code.OK.toString());

Expand Down Expand Up @@ -88,16 +88,14 @@ static TagValue extractStatus(Future<?> future) {
* number starts from 0.
*/
static Map<String, List<String>> createExtraHeaders(ApiCallContext apiCallContext) {
int attemptCount = -1;
if (apiCallContext.getTracer() instanceof BigtableTracer) {
attemptCount = ((BigtableTracer) apiCallContext.getTracer()).getAttempt();
}
ImmutableMap.Builder headers = ImmutableMap.<String, List<String>>builder();
if (attemptCount != -1) {
headers.put(
ATTEMPT_EPOCH_KEY.name(), Arrays.asList(String.valueOf(System.currentTimeMillis())));

if (apiCallContext.getTracer() instanceof BigtableTracer) {
int attemptCount = ((BigtableTracer) apiCallContext.getTracer()).getAttempt();
headers.put(ATTEMPT_HEADER_KEY.name(), Arrays.asList(String.valueOf(attemptCount)));
}
headers.put(
TIMESTAMP_HEADER_KEY.name(), Arrays.asList(String.valueOf(System.currentTimeMillis())));
return headers.build();
}
}
Expand Up @@ -167,7 +167,9 @@ public Void call() {

// attemptStared should be called at the very start of the operation. This will initialize
// variables in ApiTracer and avoid exceptions when the tracer marks the attempt as finished
callContext.getTracer().attemptStarted(externalFuture.getAttemptSettings().getAttemptCount());
callContext
.getTracer()
.attemptStarted(externalFuture.getAttemptSettings().getOverallAttemptCount());

Preconditions.checkState(
currentRequest.getEntriesCount() > 0, "Request doesn't have any mutations to send");
Expand Down
Expand Up @@ -264,7 +264,7 @@ private void verifyHeaders(int expectedAttemptCounts, long startTimestamp) throw
assertThat(attemptCount).isNotNull();
assertThat(Integer.valueOf(attemptCount)).isEqualTo(i);

String clientTimeStr = headers.get(Util.TIMESTAMP_HEADER_KEY);
String clientTimeStr = headers.get(Util.ATTEMPT_EPOCH_KEY);
assertThat(clientTimeStr).isNotNull();
long clientTime = Long.valueOf(clientTimeStr);
assertThat(clientTime).isAtLeast(timestamp);
Expand Down

0 comments on commit ec37f18

Please sign in to comment.