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..5a27386beed 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(10L)) + .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, @@ -403,10 +385,9 @@ public void multiUse() { } @Test - public void transactionRunner() { + public void transactionRunner() throws InterruptedException { 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/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