diff --git a/google-cloud-spanner/pom.xml b/google-cloud-spanner/pom.xml index 447fee147f3..04c8e2f8962 100644 --- a/google-cloud-spanner/pom.xml +++ b/google-cloud-spanner/pom.xml @@ -16,6 +16,7 @@ google-cloud-spanner 0.31.1 + 1.34.1 com.google.cloud.spanner.GceTestEnvConfig projects/gcloud-devel/instances/spanner-testing-east1 gcloud-devel @@ -418,21 +419,25 @@ io.opentelemetry opentelemetry-sdk + ${opentelemetry.version} test io.opentelemetry opentelemetry-sdk-metrics + ${opentelemetry.version} test io.opentelemetry opentelemetry-sdk-trace + ${opentelemetry.version} test io.opentelemetry opentelemetry-sdk-testing + ${opentelemetry.version} test diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java index 956607e0231..7152486c458 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetrySpanTest.java @@ -54,6 +54,7 @@ import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.threeten.bp.Duration; @Category(TracerTest.class) @RunWith(JUnit4.class) @@ -103,11 +104,11 @@ public class OpenTelemetrySpanTest { Statement.of("UPDATE NON_EXISTENT_TABLE SET BAR=1 WHERE BAZ=2"); private List expectedBatchCreateSessionsRequestEvents = - ImmutableList.of("Requesting 25 sessions", "Request for 25 sessions returned 25 sessions"); + ImmutableList.of("Requesting 2 sessions", "Request for 2 sessions returned 2 sessions"); private int expectedBatchCreateSessionsRequestEventsCount = 2; - private List expectedBatchCreateSessionsEvents = ImmutableList.of("Creating 25 sessions"); + private List expectedBatchCreateSessionsEvents = ImmutableList.of("Creating 2 sessions"); private int expectedBatchCreateSessionsEventsCount = 1; @@ -117,58 +118,45 @@ public class OpenTelemetrySpanTest { private int expectedExecuteStreamingQueryEventsCount = 1; private List expectedReadOnlyTransactionSingleUseEvents = - ImmutableList.of( - "Acquiring session", - "No session available", - "Creating sessions", - "Waiting for a session to come available", - "Using Session"); + ImmutableList.of("Acquiring session", "Acquired session", "Using Session"); - private int expectedReadOnlyTransactionSingleUseEventsCount = 5; + private int expectedReadOnlyTransactionSingleUseEventsCount = 3; private List expectedReadOnlyTransactionMultiUseEvents = ImmutableList.of( "Acquiring session", - "No session available", - "Creating sessions", - "Waiting for a session to come available", + "Acquired session", "Using Session", "Creating Transaction", "Transaction Creation Done"); - private int expectedReadOnlyTransactionMultiUseEventsCount = 7; + private int expectedReadOnlyTransactionMultiUseEventsCount = 5; private List expectedReadWriteTransactionErrorEvents = ImmutableList.of( "Acquiring session", - "No session available", - "Creating sessions", - "Waiting for a session to come available", + "Acquired session", "Using Session", "Starting Transaction Attempt", "Transaction Attempt Failed in user operation", "exception"); - private int expectedReadWriteTransactionErrorEventsCount = 8; + private int expectedReadWriteTransactionErrorEventsCount = 6; private List expectedReadWriteTransactionEvents = ImmutableList.of( "Acquiring session", - "No session available", - "Creating sessions", - "Waiting for a session to come available", + "Acquired session", "Using Session", "Starting Transaction Attempt", "Starting Commit", "Commit Done", "Transaction Attempt Succeeded"); - private int expectedReadWriteTransactionCount = 9; + private int expectedReadWriteTransactionCount = 7; private List expectedReadWriteTransactionErrorWithBeginTransactionEvents = ImmutableList.of( "Acquiring session", - "No session available", - "Creating sessions", - "Waiting for a session to come available", + "Acquired session", "Using Session", "Starting Transaction Attempt", "Transaction Attempt Aborted in user operation. Retrying", @@ -178,29 +166,26 @@ public class OpenTelemetrySpanTest { "Commit Done", "Transaction Attempt Succeeded"); - private int expectedReadWriteTransactionErrorWithBeginTransactionEventsCount = 13; + private int expectedReadWriteTransactionErrorWithBeginTransactionEventsCount = 11; private List expectedReadOnlyTransactionSpans = ImmutableList.of( "CloudSpannerOperation.BatchCreateSessionsRequest", "CloudSpannerOperation.ExecuteStreamingQuery", "CloudSpannerOperation.BatchCreateSessions", - "CloudSpanner.ReadOnlyTransaction", - "SessionPool.WaitForSession"); + "CloudSpanner.ReadOnlyTransaction"); private List expectedReadWriteTransactionWithCommitSpans = ImmutableList.of( "CloudSpannerOperation.BatchCreateSessionsRequest", "CloudSpannerOperation.Commit", "CloudSpannerOperation.BatchCreateSessions", - "CloudSpanner.ReadWriteTransaction", - "SessionPool.WaitForSession"); + "CloudSpanner.ReadWriteTransaction"); private List expectedReadWriteTransactionSpans = ImmutableList.of( "CloudSpannerOperation.BatchCreateSessionsRequest", "CloudSpannerOperation.BatchCreateSessions", - "CloudSpanner.ReadWriteTransaction", - "SessionPool.WaitForSession"); + "CloudSpanner.ReadWriteTransaction"); private List expectedReadWriteTransactionWithCommitAndBeginTransactionSpans = ImmutableList.of( @@ -208,8 +193,7 @@ public class OpenTelemetrySpanTest { "CloudSpannerOperation.BatchCreateSessionsRequest", "CloudSpannerOperation.Commit", "CloudSpannerOperation.BatchCreateSessions", - "CloudSpanner.ReadWriteTransaction", - "SessionPool.WaitForSession"); + "CloudSpanner.ReadWriteTransaction"); @BeforeClass public static void setupOpenTelemetry() { @@ -282,7 +266,11 @@ public void setUp() throws Exception { .setChannelProvider(channelProvider) .setOpenTelemetry(openTelemetry) .setCredentials(NoCredentials.getInstance()) - .setSessionPoolOption(SessionPoolOptions.newBuilder().setMinSessions(0).build()); + .setSessionPoolOption( + SessionPoolOptions.newBuilder() + .setMinSessions(2) + .setWaitForMinSessions(Duration.ofSeconds(5)) + .build()); spanner = builder.build().getService(); @@ -339,9 +327,6 @@ public void singleUse() { expectedReadOnlyTransactionSingleUseEvents, expectedReadOnlyTransactionSingleUseEventsCount); break; - case "SessionPool.WaitForSession": - assertEquals(0, spanItem.getEvents().size()); - break; default: assert false; } @@ -385,9 +370,6 @@ public void multiUse() { expectedExecuteStreamingQueryEvents, expectedExecuteStreamingQueryEventsCount); break; - case "SessionPool.WaitForSession": - assertEquals(0, spanItem.getEvents().size()); - break; case "CloudSpanner.ReadOnlyTransaction": verifyRequestEvents( spanItem, @@ -406,7 +388,6 @@ public void multiUse() { public void transactionRunner() { TransactionRunner runner = client.readWriteTransaction(); runner.run(transaction -> transaction.executeUpdate(UPDATE_STATEMENT)); - List actualSpanItems = new ArrayList<>(); spanExporter .getFinishedSpanItems() @@ -426,7 +407,6 @@ public void transactionRunner() { expectedBatchCreateSessionsEvents, expectedBatchCreateSessionsEventsCount); break; - case "SessionPool.WaitForSession": case "CloudSpannerOperation.Commit": assertEquals(0, spanItem.getEvents().size()); break; @@ -472,9 +452,6 @@ public void transactionRunnerWithError() { expectedBatchCreateSessionsEvents, expectedBatchCreateSessionsEventsCount); break; - case "SessionPool.WaitForSession": - assertEquals(0, spanItem.getEvents().size()); - break; case "CloudSpanner.ReadWriteTransaction": verifyRequestEvents( spanItem, @@ -527,7 +504,6 @@ public void transactionRunnerWithFailedAndBeginTransaction() { expectedBatchCreateSessionsEvents, expectedBatchCreateSessionsEventsCount); break; - case "SessionPool.WaitForSession": case "CloudSpannerOperation.Commit": case "CloudSpannerOperation.BeginTransaction": assertEquals(0, spanItem.getEvents().size()); @@ -551,13 +527,13 @@ private void verifyRequestEvents(SpanData spanItem, List expectedEvents, spanItem.getEvents().stream().map(EventData::getName).collect(Collectors.toList()); assertEquals(eventCount, spanItem.getEvents().size()); assertEquals( - eventNames.stream().distinct().sorted().collect(Collectors.toList()), - expectedEvents.stream().sorted().collect(Collectors.toList())); + expectedEvents.stream().sorted().collect(Collectors.toList()), + eventNames.stream().distinct().sorted().collect(Collectors.toList())); } private static void verifySpans(List actualSpanItems, List expectedSpansItems) { assertEquals( - actualSpanItems.stream().distinct().sorted().collect(Collectors.toList()), - expectedSpansItems.stream().sorted().collect(Collectors.toList())); + expectedSpansItems.stream().sorted().collect(Collectors.toList()), + actualSpanItems.stream().distinct().sorted().collect(Collectors.toList())); } } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanTest.java index 672827318d1..11361b6cd24 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/SpanTest.java @@ -174,6 +174,8 @@ public static void setupOpenTelemetry() { @Before public void setUp() throws Exception { + failOnOverkillTraceComponent.clearSpans(); + failOnOverkillTraceComponent.clearAnnotations(); // Incorporating OpenTelemetry configuration to ensure that OpenCensus traces are utilized by // default, // regardless of the presence of OpenTelemetry configuration. @@ -196,7 +198,11 @@ public void setUp() throws Exception { .setChannelProvider(channelProvider) .setCredentials(NoCredentials.getInstance()) .setOpenTelemetry(openTelemetry) - .setSessionPoolOption(SessionPoolOptions.newBuilder().setMinSessions(0).build()); + .setSessionPoolOption( + SessionPoolOptions.newBuilder() + .setMinSessions(2) + .setWaitForMinSessions(Duration.ofSeconds(5)) + .build()); spanner = builder.build().getService(); @@ -241,9 +247,6 @@ public void setUp() throws Exception { clientWithTimeout = spannerWithTimeout.getDatabaseClient( DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE)); - - failOnOverkillTraceComponent.clearSpans(); - failOnOverkillTraceComponent.clearAnnotations(); } @After @@ -286,22 +289,23 @@ public void singleUse() { Map spans = failOnOverkillTraceComponent.getSpans(); assertThat(spans).containsEntry("CloudSpanner.ReadOnlyTransaction", true); assertThat(spans).containsEntry("CloudSpannerOperation.BatchCreateSessions", true); - assertThat(spans).containsEntry("SessionPool.WaitForSession", true); assertThat(spans).containsEntry("CloudSpannerOperation.BatchCreateSessionsRequest", true); assertThat(spans).containsEntry("CloudSpannerOperation.ExecuteStreamingQuery", true); List expectedAnnotations = ImmutableList.of( - "Requesting 25 sessions", - "Request for 25 sessions returned 25 sessions", - "Creating 25 sessions", + "Requesting 2 sessions", + "Request for 2 sessions returned 2 sessions", + "Creating 2 sessions", "Acquiring session", - "No session available", - "Creating sessions", - "Waiting for a session to come available", + "Acquired session", "Using Session", "Starting/Resuming stream"); - verifyAnnotations(failOnOverkillTraceComponent.getAnnotations(), expectedAnnotations); + verifyAnnotations( + failOnOverkillTraceComponent.getAnnotations().stream() + .distinct() + .collect(Collectors.toList()), + expectedAnnotations); } @Test @@ -317,24 +321,25 @@ public void multiUse() { Map spans = failOnOverkillTraceComponent.getSpans(); assertThat(spans).containsEntry("CloudSpanner.ReadOnlyTransaction", true); assertThat(spans).containsEntry("CloudSpannerOperation.BatchCreateSessions", true); - assertThat(spans).containsEntry("SessionPool.WaitForSession", true); assertThat(spans).containsEntry("CloudSpannerOperation.BatchCreateSessionsRequest", true); assertThat(spans).containsEntry("CloudSpannerOperation.ExecuteStreamingQuery", true); List expectedAnnotations = ImmutableList.of( - "Requesting 25 sessions", - "Request for 25 sessions returned 25 sessions", - "Creating 25 sessions", + "Requesting 2 sessions", + "Request for 2 sessions returned 2 sessions", + "Creating 2 sessions", "Acquiring session", - "No session available", - "Creating sessions", - "Waiting for a session to come available", + "Acquired session", "Using Session", "Starting/Resuming stream", "Creating Transaction", "Transaction Creation Done"); - verifyAnnotations(failOnOverkillTraceComponent.getAnnotations(), expectedAnnotations); + verifyAnnotations( + failOnOverkillTraceComponent.getAnnotations().stream() + .distinct() + .collect(Collectors.toList()), + expectedAnnotations); } @Test @@ -344,25 +349,26 @@ public void transactionRunner() { Map spans = failOnOverkillTraceComponent.getSpans(); assertThat(spans).containsEntry("CloudSpanner.ReadWriteTransaction", true); assertThat(spans).containsEntry("CloudSpannerOperation.BatchCreateSessions", true); - assertThat(spans).containsEntry("SessionPool.WaitForSession", true); assertThat(spans).containsEntry("CloudSpannerOperation.BatchCreateSessionsRequest", true); assertThat(spans).containsEntry("CloudSpannerOperation.Commit", true); List expectedAnnotations = ImmutableList.of( "Acquiring session", - "No session available", - "Creating sessions", - "Waiting for a session to come available", + "Acquired session", "Using Session", "Starting Transaction Attempt", "Starting Commit", "Commit Done", "Transaction Attempt Succeeded", - "Requesting 25 sessions", - "Request for 25 sessions returned 25 sessions", - "Creating 25 sessions"); - verifyAnnotations(expectedAnnotations, failOnOverkillTraceComponent.getAnnotations()); + "Requesting 2 sessions", + "Request for 2 sessions returned 2 sessions", + "Creating 2 sessions"); + verifyAnnotations( + failOnOverkillTraceComponent.getAnnotations().stream() + .distinct() + .collect(Collectors.toList()), + expectedAnnotations); } @Test @@ -375,26 +381,27 @@ public void transactionRunnerWithError() { assertEquals(ErrorCode.INVALID_ARGUMENT, e.getErrorCode()); Map spans = failOnOverkillTraceComponent.getSpans(); - assertThat(spans.size()).isEqualTo(4); + assertThat(spans.size()).isEqualTo(3); assertThat(spans).containsEntry("CloudSpanner.ReadWriteTransaction", true); assertThat(spans).containsEntry("CloudSpannerOperation.BatchCreateSessions", true); - assertThat(spans).containsEntry("SessionPool.WaitForSession", true); assertThat(spans).containsEntry("CloudSpannerOperation.BatchCreateSessionsRequest", true); List expectedAnnotations = ImmutableList.of( "Acquiring session", - "No session available", - "Creating sessions", - "Waiting for a session to come available", + "Acquired session", "Using Session", "Starting Transaction Attempt", "Transaction Attempt Failed in user operation", - "Requesting 25 sessions", - "Request for 25 sessions returned 25 sessions", - "Creating 25 sessions"); - - verifyAnnotations(expectedAnnotations, failOnOverkillTraceComponent.getAnnotations()); + "Requesting 2 sessions", + "Request for 2 sessions returned 2 sessions", + "Creating 2 sessions"); + + verifyAnnotations( + failOnOverkillTraceComponent.getAnnotations().stream() + .distinct() + .collect(Collectors.toList()), + expectedAnnotations); } private void verifyAnnotations(List actualAnnotations, List expectedAnnotations) { diff --git a/pom.xml b/pom.xml index 740f3e3c593..8a4ba126187 100644 --- a/pom.xml +++ b/pom.xml @@ -104,14 +104,6 @@ 6.59.1-SNAPSHOT - - io.opentelemetry - opentelemetry-bom - 1.34.1 - pom - import - - com.google.cloud google-cloud-shared-dependencies