From 36e0d05b30da97ca59fc629bccc585f1980d78d7 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 19 Nov 2024 15:07:51 -0500 Subject: [PATCH 1/5] feat: introduce `java.time` variables and methods --- .../google/cloud/firestore/FirestoreImpl.java | 14 +++++-- .../cloud/firestore/FirestoreRpcContext.java | 12 +++++- .../cloud/firestore/StreamableQuery.java | 4 +- .../telemetry/CompositeApiTracer.java | 7 ++-- .../firestore/telemetry/EnabledTraceUtil.java | 8 +++- .../cloud/firestore/LocalFirestoreHelper.java | 6 +-- .../cloud/firestore/QueryCountTest.java | 4 +- .../com/google/cloud/firestore/QueryTest.java | 6 +-- .../cloud/firestore/it/ITSystemTest.java | 8 ++-- .../telemetry/EnabledTraceUtilTest.java | 42 +++++++++---------- 10 files changed, 67 insertions(+), 44 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java index 5c7217141..4d532b459 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java @@ -16,11 +16,13 @@ package com.google.cloud.firestore; +import static com.google.api.gax.util.TimeConversionUtils.toThreetenDuration; import static com.google.cloud.firestore.telemetry.TraceUtil.*; import com.google.api.core.ApiClock; import com.google.api.core.ApiFuture; import com.google.api.core.NanoClock; +import com.google.api.core.ObsoleteApi; import com.google.api.core.SettableApiFuture; import com.google.api.gax.rpc.ApiStreamObserver; import com.google.api.gax.rpc.BidiStreamObserver; @@ -52,7 +54,6 @@ import java.util.Random; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * Main implementation of the Firestore client. This is the entry point for all Firestore @@ -500,9 +501,16 @@ public FirestoreRpc getClient() { return firestoreClient; } + /** This method is obsolete. Use {@link #getTotalRequestTimeoutDuration()} instead. */ + @ObsoleteApi("Use getTotalRequestTimeoutDuration() instead") @Override - public Duration getTotalRequestTimeout() { - return firestoreOptions.getRetrySettings().getTotalTimeout(); + public org.threeten.bp.Duration getTotalRequestTimeout() { + return toThreetenDuration(getTotalRequestTimeoutDuration()); + } + + @Override + public java.time.Duration getTotalRequestTimeoutDuration() { + return firestoreOptions.getRetrySettings().getTotalTimeoutDuration(); } @Override diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreRpcContext.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreRpcContext.java index 5207bd770..e25b47a43 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreRpcContext.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreRpcContext.java @@ -16,10 +16,13 @@ package com.google.cloud.firestore; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.ApiClock; import com.google.api.core.ApiFuture; import com.google.api.core.InternalApi; import com.google.api.core.InternalExtensionOnly; +import com.google.api.core.ObsoleteApi; import com.google.api.gax.rpc.BidiStreamObserver; import com.google.api.gax.rpc.BidiStreamingCallable; import com.google.api.gax.rpc.ClientStream; @@ -27,7 +30,6 @@ import com.google.api.gax.rpc.ServerStreamingCallable; import com.google.api.gax.rpc.UnaryCallable; import com.google.cloud.firestore.spi.v1.FirestoreRpc; -import org.threeten.bp.Duration; @InternalApi @InternalExtensionOnly @@ -41,7 +43,13 @@ interface FirestoreRpcContext { FirestoreRpc getClient(); - Duration getTotalRequestTimeout(); + /** This method is obsolete. Use {@link #getTotalRequestTimeoutDuration()} instead. */ + @ObsoleteApi("Use getTotalRequestTimeoutDuration() instead") + org.threeten.bp.Duration getTotalRequestTimeout(); + + default java.time.Duration getTotalRequestTimeoutDuration() { + return toJavaTimeDuration(getTotalRequestTimeout()); + } ApiClock getClock(); diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/StreamableQuery.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/StreamableQuery.java index a959f9a15..6c6503aa4 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/StreamableQuery.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/StreamableQuery.java @@ -39,6 +39,7 @@ import com.google.firestore.v1.RunQueryResponse; import com.google.protobuf.ByteString; import io.grpc.Status; +import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -46,7 +47,6 @@ import java.util.concurrent.atomic.AtomicReference; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.threeten.bp.Duration; /** * Represents a query whose results can be streamed. If the stream fails with a retryable error, @@ -452,7 +452,7 @@ boolean shouldRetryQuery( } Duration duration = Duration.ofNanos(rpcContext.getClock().nanoTime() - startTimeNanos); - return duration.compareTo(rpcContext.getTotalRequestTimeout()) < 0; + return duration.compareTo(rpcContext.getTotalRequestTimeoutDuration()) < 0; } /** Verifies whether the given exception is retryable based on the RunQuery configuration. */ diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/CompositeApiTracer.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/CompositeApiTracer.java index 31dbddbbf..695b7c287 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/CompositeApiTracer.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/CompositeApiTracer.java @@ -16,13 +16,14 @@ package com.google.cloud.firestore.telemetry; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.gax.tracing.ApiTracer; import com.google.api.gax.tracing.BaseApiTracer; import com.google.common.collect.ImmutableList; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -import org.threeten.bp.Duration; /** Combines multiple {@link ApiTracer}s into a single {@link ApiTracer}. */ class CompositeApiTracer extends BaseApiTracer { @@ -83,8 +84,8 @@ public void attemptCancelled() { } @Override - public void attemptFailed(Throwable error, Duration delay) { - children.forEach(child -> child.attemptFailed(error, delay)); + public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) { + attemptFailedDuration(error, toJavaTimeDuration(delay)); } @Override diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java index b0eeeca21..d068718f0 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java @@ -16,6 +16,8 @@ package com.google.cloud.firestore.telemetry; +import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; + import com.google.api.core.ApiFunction; import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutureCallback; @@ -94,12 +96,16 @@ public ApiFunction getChannelConfi return new OpenTelemetryGrpcChannelConfigurator(); } + String durationString(org.threeten.bp.Duration duration) { + return durationStringDuration(toJavaTimeDuration(duration)); + } + // Returns a JSON String representation of the given duration. The JSON representation for a // Duration is a String that // ends in `s` to indicate seconds and is preceded by the number of seconds, with nanoseconds // expressed as fractional // seconds. - String durationString(org.threeten.bp.Duration duration) { + String durationStringDuration(java.time.Duration duration) { int nanos = duration.getNano(); long seconds = duration.getSeconds(); int numLeadingZeros = 9; diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java index 5ccd9f163..500e35ff9 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/LocalFirestoreHelper.java @@ -71,6 +71,7 @@ import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.time.Duration; import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; @@ -88,14 +89,13 @@ import org.mockito.ArgumentMatchers; import org.mockito.stubbing.Answer; import org.mockito.stubbing.Stubber; -import org.threeten.bp.Duration; public final class LocalFirestoreHelper { protected static RetrySettings IMMEDIATE_RETRY_SETTINGS = RetrySettings.newBuilder() - .setInitialRetryDelay(Duration.ZERO) - .setMaxRetryDelay(Duration.ZERO) + .setInitialRetryDelayDuration(Duration.ZERO) + .setMaxRetryDelayDuration(Duration.ZERO) .setRetryDelayMultiplier(1) .setJittered(false) .build(); diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryCountTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryCountTest.java index 78222ecfa..be30e7f6e 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryCountTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryCountTest.java @@ -41,6 +41,7 @@ import com.google.firestore.v1.RunAggregationQueryResponse; import com.google.firestore.v1.StructuredQuery; import io.grpc.Status; +import java.time.Duration; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.junit.Before; @@ -50,7 +51,6 @@ import org.mockito.Captor; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; -import org.threeten.bp.Duration; @RunWith(MockitoJUnitRunner.class) public class QueryCountTest { @@ -70,7 +70,7 @@ public class QueryCountTest { @Before public void before() { - doReturn(Duration.ZERO).when(firestoreMock).getTotalRequestTimeout(); + doReturn(Duration.ZERO).when(firestoreMock).getTotalRequestTimeoutDuration(); query = firestoreMock.collection(COLLECTION_ID); } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java index 280c6e02a..78591cdda 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryTest.java @@ -67,6 +67,7 @@ import io.grpc.Status; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -82,7 +83,6 @@ import org.mockito.Mockito; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; -import org.threeten.bp.Duration; @RunWith(MockitoJUnitRunner.class) public class QueryTest { @@ -123,7 +123,7 @@ public long millisTime() { public void before() { clock = new MockClock(); doReturn(clock).when(firestoreMock).getClock(); - doReturn(Duration.ZERO).when(firestoreMock).getTotalRequestTimeout(); + doReturn(Duration.ZERO).when(firestoreMock).getTotalRequestTimeoutDuration(); query = firestoreMock.collection(COLLECTION_ID); } @@ -1130,7 +1130,7 @@ public void retriesWithoutTimeout() throws Exception { @Test public void doesNotRetryWithTimeout() { - doReturn(Duration.ofMinutes(1)).when(firestoreMock).getTotalRequestTimeout(); + doReturn(Duration.ofMinutes(1)).when(firestoreMock).getTotalRequestTimeoutDuration(); doAnswer( invocation -> { diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java index c84d00a19..0281f58a9 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/it/ITSystemTest.java @@ -84,6 +84,7 @@ import io.grpc.Status; import io.grpc.Status.Code; import io.grpc.StatusRuntimeException; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -106,7 +107,6 @@ import org.junit.rules.TestName; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import org.threeten.bp.Duration; @RunWith(JUnit4.class) public class ITSystemTest extends ITBaseTest { @@ -2281,9 +2281,9 @@ public void testEnforcesTimeouts() { FirestoreOptions.newBuilder() .setRetrySettings( RetrySettings.newBuilder() - .setMaxRpcTimeout(Duration.ofMillis(1)) - .setTotalTimeout(Duration.ofMillis(1)) - .setInitialRpcTimeout(Duration.ofMillis(1)) + .setMaxRpcTimeoutDuration(Duration.ofMillis(1)) + .setTotalTimeoutDuration(Duration.ofMillis(1)) + .setInitialRpcTimeoutDuration(Duration.ofMillis(1)) .build()) .build(); firestore = firestoreOptions.getService(); diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/telemetry/EnabledTraceUtilTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/telemetry/EnabledTraceUtilTest.java index 22e835f19..87baf57c5 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/telemetry/EnabledTraceUtilTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/telemetry/EnabledTraceUtilTest.java @@ -22,9 +22,9 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.trace.TracerProvider; import io.opentelemetry.sdk.OpenTelemetrySdk; +import java.time.Duration; import org.junit.Before; import org.junit.Test; -import org.threeten.bp.Duration; public class EnabledTraceUtilTest { @Before @@ -138,63 +138,63 @@ public void usesEnabledScope() { public void durationString() { EnabledTraceUtil traceUtil = defaultEnabledTraceUtil(); Duration duration = Duration.ofSeconds(2, 9); - assertThat(traceUtil.durationString(duration)).isEqualTo("2.000000009s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("2.000000009s"); duration = Duration.ofSeconds(3, 98); - assertThat(traceUtil.durationString(duration)).isEqualTo("3.000000098s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("3.000000098s"); duration = Duration.ofSeconds(4, 987); - assertThat(traceUtil.durationString(duration)).isEqualTo("4.000000987s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("4.000000987s"); duration = Duration.ofSeconds(5, 9876); - assertThat(traceUtil.durationString(duration)).isEqualTo("5.000009876s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("5.000009876s"); duration = Duration.ofSeconds(6, 98765); - assertThat(traceUtil.durationString(duration)).isEqualTo("6.000098765s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("6.000098765s"); duration = Duration.ofSeconds(7, 987654); - assertThat(traceUtil.durationString(duration)).isEqualTo("7.000987654s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("7.000987654s"); duration = Duration.ofSeconds(8, 9876543); - assertThat(traceUtil.durationString(duration)).isEqualTo("8.009876543s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("8.009876543s"); duration = Duration.ofSeconds(9, 98765432); - assertThat(traceUtil.durationString(duration)).isEqualTo("9.098765432s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("9.098765432s"); duration = Duration.ofSeconds(10, 987654321); - assertThat(traceUtil.durationString(duration)).isEqualTo("10.987654321s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("10.987654321s"); duration = Duration.ofSeconds(1, 0); - assertThat(traceUtil.durationString(duration)).isEqualTo("1.0s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.0s"); duration = Duration.ofSeconds(1, 1); - assertThat(traceUtil.durationString(duration)).isEqualTo("1.000000001s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.000000001s"); duration = Duration.ofSeconds(1, 10); - assertThat(traceUtil.durationString(duration)).isEqualTo("1.00000001s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.00000001s"); duration = Duration.ofSeconds(1, 100); - assertThat(traceUtil.durationString(duration)).isEqualTo("1.0000001s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.0000001s"); duration = Duration.ofSeconds(1, 1_000); - assertThat(traceUtil.durationString(duration)).isEqualTo("1.000001s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.000001s"); duration = Duration.ofSeconds(1, 10_000); - assertThat(traceUtil.durationString(duration)).isEqualTo("1.00001s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.00001s"); duration = Duration.ofSeconds(1, 100_000); - assertThat(traceUtil.durationString(duration)).isEqualTo("1.0001s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.0001s"); duration = Duration.ofSeconds(1, 1_000_000); - assertThat(traceUtil.durationString(duration)).isEqualTo("1.001s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.001s"); duration = Duration.ofSeconds(1, 10_000_000); - assertThat(traceUtil.durationString(duration)).isEqualTo("1.01s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.01s"); duration = Duration.ofSeconds(1, 100_000_000); - assertThat(traceUtil.durationString(duration)).isEqualTo("1.1s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.1s"); duration = Duration.ofSeconds(1, 100_000_001); - assertThat(traceUtil.durationString(duration)).isEqualTo("1.100000001s"); + assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.100000001s"); } } From d072d5df41d0898b82da9f5c80df519401299a7d Mon Sep 17 00:00:00 2001 From: cloud-java-bot Date: Tue, 19 Nov 2024 22:29:37 +0000 Subject: [PATCH 2/5] chore: generate libraries at Tue Nov 19 22:27:50 UTC 2024 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1e5ed6035..96122305f 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ If you are using Maven without the BOM, add this to your dependencies: com.google.cloud google-cloud-firestore - 3.29.0 + 3.29.1 ``` From 2a5eedcb993a858419199e51298da38bfff26576 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Tue, 19 Nov 2024 17:43:29 -0500 Subject: [PATCH 3/5] fix tests --- .../java/com/google/cloud/firestore/QueryCountTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryCountTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryCountTest.java index be30e7f6e..b6e91c291 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryCountTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/QueryCountTest.java @@ -230,7 +230,7 @@ public void shouldNotRetryIfExceptionIsFirestoreExceptionWithNonRetryableStatus( public void shouldRetryIfExceptionIsFirestoreExceptionWithRetryableStatusWithInfiniteTimeoutWindow() throws Exception { - doReturn(Duration.ZERO).when(firestoreMock).getTotalRequestTimeout(); + doReturn(Duration.ZERO).when(firestoreMock).getTotalRequestTimeoutDuration(); doAnswer(countQueryResponse(new FirestoreException("reason", Status.INTERNAL))) .doAnswer(countQueryResponse(42)) .when(firestoreMock) @@ -245,7 +245,7 @@ public void shouldNotRetryIfExceptionIsFirestoreExceptionWithNonRetryableStatus( @Test public void shouldRetryIfExceptionIsFirestoreExceptionWithRetryableStatusWithinTimeoutWindow() throws Exception { - doReturn(Duration.ofDays(999)).when(firestoreMock).getTotalRequestTimeout(); + doReturn(Duration.ofDays(999)).when(firestoreMock).getTotalRequestTimeoutDuration(); doAnswer(countQueryResponse(new FirestoreException("reason", Status.INTERNAL))) .doAnswer(countQueryResponse(42)) .when(firestoreMock) @@ -267,7 +267,7 @@ public void shouldRetryIfExceptionIsFirestoreExceptionWithRetryableStatusWithinT .doReturn(TimeUnit.SECONDS.toNanos(30)) .when(clockMock) .nanoTime(); - doReturn(Duration.ofSeconds(5)).when(firestoreMock).getTotalRequestTimeout(); + doReturn(Duration.ofSeconds(5)).when(firestoreMock).getTotalRequestTimeoutDuration(); doAnswer(countQueryResponse(new FirestoreException("reason", Status.INTERNAL))) .doAnswer(countQueryResponse(42)) .when(firestoreMock) From 60643fedbc3ad587f647c64b92ca1d33ff220af7 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 20 Nov 2024 15:17:23 -0500 Subject: [PATCH 4/5] remove overload for package private method --- .../firestore/telemetry/EnabledTraceUtil.java | 21 +++++----- .../telemetry/EnabledTraceUtilTest.java | 40 +++++++++---------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java index d068718f0..37ebc4366 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java @@ -16,7 +16,6 @@ package com.google.cloud.firestore.telemetry; -import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration; import com.google.api.core.ApiFunction; import com.google.api.core.ApiFuture; @@ -96,16 +95,12 @@ public ApiFunction getChannelConfi return new OpenTelemetryGrpcChannelConfigurator(); } - String durationString(org.threeten.bp.Duration duration) { - return durationStringDuration(toJavaTimeDuration(duration)); - } - // Returns a JSON String representation of the given duration. The JSON representation for a // Duration is a String that // ends in `s` to indicate seconds and is preceded by the number of seconds, with nanoseconds // expressed as fractional // seconds. - String durationStringDuration(java.time.Duration duration) { + String durationString(java.time.Duration duration) { int nanos = duration.getNano(); long seconds = duration.getSeconds(); int numLeadingZeros = 9; @@ -336,10 +331,12 @@ private SpanBuilder addSettingsAttributesToCurrentSpan(SpanBuilder spanBuilder) Attributes.builder() .put( ATTRIBUTE_SERVICE_PREFIX + "settings.retry_settings.initial_retry_delay", - durationString(firestoreOptions.getRetrySettings().getInitialRetryDelay())) + durationString( + firestoreOptions.getRetrySettings().getInitialRetryDelayDuration())) .put( ATTRIBUTE_SERVICE_PREFIX + "settings.retry_settings.max_retry_delay", - durationString(firestoreOptions.getRetrySettings().getMaxRetryDelay())) + durationString( + firestoreOptions.getRetrySettings().getMaxRetryDelayDuration())) .put( ATTRIBUTE_SERVICE_PREFIX + "settings.retry_settings.retry_delay_multiplier", String.valueOf(firestoreOptions.getRetrySettings().getRetryDelayMultiplier())) @@ -348,16 +345,18 @@ private SpanBuilder addSettingsAttributesToCurrentSpan(SpanBuilder spanBuilder) String.valueOf(firestoreOptions.getRetrySettings().getMaxAttempts())) .put( ATTRIBUTE_SERVICE_PREFIX + "settings.retry_settings.initial_rpc_timeout", - durationString(firestoreOptions.getRetrySettings().getInitialRpcTimeout())) + durationString( + firestoreOptions.getRetrySettings().getInitialRpcTimeoutDuration())) .put( ATTRIBUTE_SERVICE_PREFIX + "settings.retry_settings.max_rpc_timeout", - durationString(firestoreOptions.getRetrySettings().getMaxRpcTimeout())) + durationString( + firestoreOptions.getRetrySettings().getMaxRpcTimeoutDuration())) .put( ATTRIBUTE_SERVICE_PREFIX + "settings.retry_settings.rpc_timeout_multiplier", String.valueOf(firestoreOptions.getRetrySettings().getRpcTimeoutMultiplier())) .put( ATTRIBUTE_SERVICE_PREFIX + "settings.retry_settings.total_timeout", - durationString(firestoreOptions.getRetrySettings().getTotalTimeout())) + durationString(firestoreOptions.getRetrySettings().getTotalTimeoutDuration())) .build()); } diff --git a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/telemetry/EnabledTraceUtilTest.java b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/telemetry/EnabledTraceUtilTest.java index 87baf57c5..d3fb7e216 100644 --- a/google-cloud-firestore/src/test/java/com/google/cloud/firestore/telemetry/EnabledTraceUtilTest.java +++ b/google-cloud-firestore/src/test/java/com/google/cloud/firestore/telemetry/EnabledTraceUtilTest.java @@ -138,63 +138,63 @@ public void usesEnabledScope() { public void durationString() { EnabledTraceUtil traceUtil = defaultEnabledTraceUtil(); Duration duration = Duration.ofSeconds(2, 9); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("2.000000009s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("2.000000009s"); duration = Duration.ofSeconds(3, 98); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("3.000000098s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("3.000000098s"); duration = Duration.ofSeconds(4, 987); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("4.000000987s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("4.000000987s"); duration = Duration.ofSeconds(5, 9876); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("5.000009876s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("5.000009876s"); duration = Duration.ofSeconds(6, 98765); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("6.000098765s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("6.000098765s"); duration = Duration.ofSeconds(7, 987654); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("7.000987654s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("7.000987654s"); duration = Duration.ofSeconds(8, 9876543); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("8.009876543s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("8.009876543s"); duration = Duration.ofSeconds(9, 98765432); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("9.098765432s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("9.098765432s"); duration = Duration.ofSeconds(10, 987654321); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("10.987654321s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("10.987654321s"); duration = Duration.ofSeconds(1, 0); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.0s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("1.0s"); duration = Duration.ofSeconds(1, 1); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.000000001s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("1.000000001s"); duration = Duration.ofSeconds(1, 10); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.00000001s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("1.00000001s"); duration = Duration.ofSeconds(1, 100); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.0000001s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("1.0000001s"); duration = Duration.ofSeconds(1, 1_000); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.000001s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("1.000001s"); duration = Duration.ofSeconds(1, 10_000); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.00001s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("1.00001s"); duration = Duration.ofSeconds(1, 100_000); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.0001s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("1.0001s"); duration = Duration.ofSeconds(1, 1_000_000); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.001s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("1.001s"); duration = Duration.ofSeconds(1, 10_000_000); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.01s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("1.01s"); duration = Duration.ofSeconds(1, 100_000_000); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.1s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("1.1s"); duration = Duration.ofSeconds(1, 100_000_001); - assertThat(traceUtil.durationStringDuration(duration)).isEqualTo("1.100000001s"); + assertThat(traceUtil.durationString(duration)).isEqualTo("1.100000001s"); } } From cc3e9392a888b6067351d840b99b22ebf85de41d Mon Sep 17 00:00:00 2001 From: cloud-java-bot Date: Wed, 20 Nov 2024 20:20:24 +0000 Subject: [PATCH 5/5] chore: generate libraries at Wed Nov 20 20:18:13 UTC 2024 --- .../com/google/cloud/firestore/telemetry/EnabledTraceUtil.java | 1 - 1 file changed, 1 deletion(-) diff --git a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java index 37ebc4366..334bdfffb 100644 --- a/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java +++ b/google-cloud-firestore/src/main/java/com/google/cloud/firestore/telemetry/EnabledTraceUtil.java @@ -16,7 +16,6 @@ package com.google.cloud.firestore.telemetry; - import com.google.api.core.ApiFunction; import com.google.api.core.ApiFuture; import com.google.api.core.ApiFutureCallback;