Skip to content

Commit

Permalink
update calculation and test
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Nov 13, 2024
1 parent 23195da commit 0bd58d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ public void grpcMessageSent() {
public void setTotalTimeoutDuration(java.time.Duration totalTimeoutDuration) {
// This method is called by BigtableTracerStreamingCallable and
// BigtableTracerUnaryCallable which is called per attempt. We only set
// the operationDeadline on the first attempt.
if (operationDeadline == null) {
// the operationDeadline on the first attempt and when totalTimeout is set.
if (operationDeadline == null && !totalTimeoutDuration.isZero()) {
this.operationDeadline =
Deadline.after(totalTimeoutDuration.toMillis(), TimeUnit.MILLISECONDS);
this.remainingDeadlineAtAttemptStart = totalTimeoutDuration.toMillis();
Expand Down Expand Up @@ -405,11 +405,10 @@ private void recordAttemptCompletion(@Nullable Throwable status) {
attemptLatenciesHistogram.record(
convertToMs(attemptTimer.elapsed(TimeUnit.NANOSECONDS)), attributes);

// Total timeout is set to 0 when there's no timeout. In this case remaining deadline will be
// <= 0. Skip recording the value because it doesn't represent how much time is left to
// retry the request.
if (remainingDeadlineAtAttemptStart > 0) {
remainingDeadlineHistogram.record(remainingDeadlineAtAttemptStart, attributes);
// When operationDeadline is set, it's possible that the deadline is passed by the time we send
// a new attempt. In this case we'll record 0.
if (operationDeadline != null) {
remainingDeadlineHistogram.record(Math.max(0, remainingDeadlineAtAttemptStart), attributes);
}

if (serverLatencies != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public class BuiltinMetricsTracerTest {
private static final long APPLICATION_LATENCY = 200;
private static final long SLEEP_VARIABILITY = 15;
private static final String CLIENT_NAME = "java-bigtable/" + Version.VERSION;
private static final long READ_ROWS_TOTAL_TIMEOUT = 1000;

private static final long CHANNEL_BLOCKING_LATENCY = 200;

Expand Down Expand Up @@ -220,10 +221,10 @@ public void sendHeaders(Metadata headers) {
stubSettingsBuilder
.readRowsSettings()
.retrySettings()
.setTotalTimeoutDuration(Duration.ofMillis(9000))
.setMaxRpcTimeoutDuration(Duration.ofMillis(6000))
.setTotalTimeoutDuration(Duration.ofMillis(READ_ROWS_TOTAL_TIMEOUT))
.setMaxRpcTimeoutDuration(Duration.ofMillis(READ_ROWS_TOTAL_TIMEOUT))
.setRpcTimeoutMultiplier(1)
.setInitialRpcTimeoutDuration(Duration.ofMillis(6000))
.setInitialRpcTimeoutDuration(Duration.ofMillis(800))
.setInitialRetryDelayDuration(Duration.ofMillis(10))
.setRetryDelayMultiplier(1)
.setMaxRetryDelayDuration(Duration.ofMillis(10));
Expand Down Expand Up @@ -789,7 +790,7 @@ public void testRemainingDeadline() {

double retryRemainingDeadline = retryHistogramPointData.getSum();
// The retry remaining deadline should be equivalent to the original timeout.
assertThat(retryRemainingDeadline).isEqualTo(9000);
assertThat(retryRemainingDeadline).isEqualTo((double) READ_ROWS_TOTAL_TIMEOUT);

Attributes okAttributes =
baseAttributes
Expand All @@ -809,7 +810,9 @@ public void testRemainingDeadline() {
.get(0);

double okRemainingDeadline = okHistogramPointData.getSum();
assertThat(okRemainingDeadline).isWithin(200).of(8500);
// first attempt latency + retry delay
double expected = READ_ROWS_TOTAL_TIMEOUT - SERVER_LATENCY - CHANNEL_BLOCKING_LATENCY - 10;
assertThat(okRemainingDeadline).isWithin(10).of(expected);
}

private static class FakeService extends BigtableGrpc.BigtableImplBase {
Expand Down

0 comments on commit 0bd58d4

Please sign in to comment.