Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhigarg92 committed Feb 7, 2024
1 parent 5ae1152 commit 92fbf0b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.Collections;
import java.util.Map;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -63,12 +64,16 @@ public final class BatchClientImplTest {

private BatchClient client;

@BeforeClass
public static void setupOpenTelemetry() {
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryTraces();
}

@SuppressWarnings("unchecked")
@Before
public void setUp() {
initMocks(this);
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryTraces();
DatabaseId db = DatabaseId.of(DB_NAME);
when(spannerOptions.getNumChannels()).thenReturn(4);
when(spannerOptions.getDatabaseRole()).thenReturn("role");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ public class OpenTelemetrySpanTest {
"CloudSpanner.ReadWriteTransaction",
"SessionPool.WaitForSession");

@BeforeClass
public static void setupOpenTelemetry() {
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryTraces();
}

@BeforeClass
public static void startStaticServer() throws Exception {
// Incorporating OpenCensus tracer to ensure that OpenTraces traces are utilized if enabled,
Expand All @@ -231,8 +237,6 @@ public static void startStaticServer() throws Exception {
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(null, failOnOverkillTraceComponent);

// OpenTelemetry Configuration

mockSpanner = new MockSpannerServiceImpl();
mockSpanner.setAbortProbability(0.0D); // We don't want any unpredictable aborted transactions.
mockSpanner.putStatementResult(StatementResult.query(SELECT1, SELECT1_RESULTSET));
Expand All @@ -259,8 +263,6 @@ public static void stopServer() throws InterruptedException {

@Before
public void setUp() throws Exception {
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryTraces();
spanExporter = InMemorySpanExporter.create();

SdkTracerProvider tracerProvider =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -79,12 +80,16 @@ public class SessionImplTest {
@Captor private ArgumentCaptor<Map<SpannerRpc.Option, Object>> optionsCaptor;
private Map<SpannerRpc.Option, Object> options;

@BeforeClass
public static void setupOpenTelemetry() {
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryTraces();
}

@SuppressWarnings("unchecked")
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryTraces();
when(spannerOptions.getNumChannels()).thenReturn(4);
when(spannerOptions.getPrefetchChunks()).thenReturn(1);
when(spannerOptions.getDatabaseRole()).thenReturn("role");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,7 @@ public void testOpenCensusMetricsDisable() {

@Test
public void testOpenTelemetrySessionMetrics() throws Exception {
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryMetrics();
// Create a session pool with max 2 session and a low timeout for waiting for a session.
if (minSessions == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,14 @@ public static void stopServer() throws InterruptedException {
}
}

@Before
public void setUp() throws Exception {
@BeforeClass
public static void setupOpenTelemetry() {
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenCensusTraces();
}

@Before
public void setUp() throws Exception {
// Incorporating OpenTelemetry configuration to ensure that OpenCensus traces are utilized by
// default,
// regardless of the presence of OpenTelemetry configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -58,11 +59,15 @@ public class SpannerImplTest {

@Captor ArgumentCaptor<Map<SpannerRpc.Option, Object>> options;

@BeforeClass
public static void setupOpenTelemetry() {
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryTraces();
}

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryTraces();
when(spannerOptions.getNumChannels()).thenReturn(4);
when(spannerOptions.getDatabaseRole()).thenReturn("role");
when(spannerOptions.getPrefetchChunks()).thenReturn(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -78,11 +79,15 @@ public void release(ScheduledExecutorService exec) {
@Mock TransactionRunnerImpl.TransactionContextImpl txn;
private TransactionManagerImpl manager;

@BeforeClass
public static void setupOpenTelemetry() {
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryTraces();
}

@Before
public void setUp() {
initMocks(this);
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryTraces();
manager =
new TransactionManagerImpl(
session,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down Expand Up @@ -102,11 +103,15 @@ public void release(ScheduledExecutorService exec) {
private TraceWrapper tracer;
private ISpan span;

@BeforeClass
public static void setupOpenTelemetry() {
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryTraces();
}

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
SpannerOptions.resetActiveTracingFramework();
SpannerOptions.enableOpenTelemetryTraces();
tracer = new TraceWrapper(Tracing.getTracer(), OpenTelemetry.noop().getTracer(""));
firstRun = true;
when(session.newTransaction(Options.fromTransactionOptions())).thenReturn(txn);
Expand Down

0 comments on commit 92fbf0b

Please sign in to comment.