Skip to content

Commit

Permalink
Undo previous changes, and just respect whatever the timeout is
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedell-newrelic committed Dec 20, 2024
1 parent a2588d9 commit 6047b85
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,6 @@ void setOwningTransactionIsIgnored(boolean newState) {
* @param tracer
*/
public Tracer tracerStarted(Tracer tracer) {
Agent.LOG.log(Level.INFO, "JGB tracerStarted: ", tracer);
StackTraceElement[] elems = Thread.currentThread().getStackTrace();
if (elems != null) {
for (int i = 0; i < elems.length && i < 3; i++) {
Agent.LOG.log(Level.INFO, "JGB -> "+elems[i].getClassName() + "." + elems[i].getMethodName());
}
}
Tracer tr = addTracerToStack(tracer);
if (tr != null && getTransaction() != null && tr.isTransactionSegment()) {
getTransaction().getTransactionCounts().addTracer();
Expand All @@ -331,7 +324,7 @@ public Tracer tracerStarted(Tracer tracer) {
*/
public Tracer addTracerToStack(Tracer tracer) {
if (isTracerStartLocked()) {
Agent.LOG.log(Level.INFO, "JGB tracerStarted ignored: tracerStartLock is already active");
Agent.LOG.log(Level.FINER, "tracerStarted ignored: tracerStartLock is already active");
return null;
}

Expand Down Expand Up @@ -503,7 +496,6 @@ public void addTracer(Tracer tracer) {
private void setRootTracer(Tracer tracer) {
rootTracer = tracer;
lastTracer = tracer;
Agent.LOG.log(Level.INFO, "JGB Tracer Debug: called setRootTracer, lastTracer (pointer to top of stack) and rootTracer set to {0}", tracer);
if (Agent.isDebugEnabled() && Agent.LOG.isFinestEnabled()) {
Agent.LOG.log(Level.FINEST, "Tracer Debug: called setRootTracer, lastTracer (pointer to top of stack) and rootTracer set to {0}", tracer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,8 @@ private SpanEventsConfig initSpanEventsConfig(boolean dtEnabled) {
private int initTokenTimeout() {
if (getProperty(ASYNC_TIMEOUT) != null) {
Agent.LOG.log(Level.INFO, "The property async_timeout is deprecated. Change to token_timeout");
System.out.println("Getting async_timeout: "+getProperty("async_timeout", 180));
return getProperty("async_timeout", 180);
}
System.out.println("Getting token_timeout: "+getProperty("token_timeout", 180));

return getProperty("token_timeout", 180);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ public void onRemoval(Object key, Token transaction, RemovalCause cause) {
// The implementation class is threadsafe.
private static final Cache<Object, Token> makeCache(RemovalListener<Object, Token> removalListener) {
// default set to 3 minutes (180), must match the behavior in TimedTokenSet: expireAfterAccess with same timeout
System.out.println("JGB making cache");
long timeoutSec = ServiceFactory.getConfigService().getDefaultAgentConfig().getTokenTimeoutInSec();
System.out.println("JGB cache timeout secs: "+timeoutSec);
long timeOutMilli = TimeConversion.convertToMilliWithLowerBound(timeoutSec, TimeUnit.SECONDS, 250L);
System.out.println("JGB cache timeout millis: "+timeOutMilli);

return Caffeine.newBuilder()
.expireAfterWrite(timeOutMilli, TimeUnit.MILLISECONDS)
Expand All @@ -85,10 +82,7 @@ private static final Cache<Object, Token> makeCache(RemovalListener<Object, Toke

protected void cleanUpPendingTransactions() {
PENDING_ACTIVITIES.cleanUp();
Agent.LOG.log(Level.INFO, "Cleaning up the pending activities cache,\r\n" +
" timeout millis: "+PENDING_ACTIVITIES.policy().expireAfterWrite().get().getExpiresAfter(TimeUnit.MILLISECONDS)+"\r\n" +
" cache: "+PENDING_ACTIVITIES+"\r\n" +
" age of myFirstKey millis: "+PENDING_ACTIVITIES.policy().expireAfterWrite().get().ageOf("myFirstKey", TimeUnit.MILLISECONDS).orElse(-1));
Agent.LOG.log(Level.INFO, "Cleaning up the pending activities cache, timeout: "+PENDING_ACTIVITIES.policy().expireAfterWrite().get().getExpiresAfter(TimeUnit.MILLISECONDS));
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public BasicRequestRootTracer(Transaction transaction, ClassMethodSignature sig,

Tracer rootTracer = transaction.getTransactionActivity().getRootTracer();
if (rootTracer != null) {
System.out.println("JGB rootTracer: "+rootTracer);
System.out.println("JGB MetricName: "+rootTracer.getMetricName());
throw new SkipTracerException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.math.BigDecimal;
import java.math.BigInteger;
Expand All @@ -35,17 +33,11 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

@RunWith(Parameterized.class)
public class AgentAttributeSenderTest {

private static final String APP_NAME = "NAME";
private MockServiceManager manager;

@Parameterized.Parameters
public static Object[][] data() {
return new Object[1000][0]; // run X times, where [X][]
}

@Before
public void setup() {
try {
Expand Down Expand Up @@ -104,9 +96,6 @@ public void testCustomAttributesInTransaction() {
Set<String> expected = Sets.newHashSet("abc.thread", "request.many", "message.many", "key1", "key2", "key4", "message.bool");

verifyOutput(t.getUserAttributes(), expected);
} catch (Exception e) {
System.out.println("JGB Exception in testCustomAttributesInTransaction: "+e);
System.out.println("JGB e.message: "+e.getMessage());

} finally {
Transaction.clearTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@

import static org.junit.Assert.*;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class AsyncTransactionServiceTest {

@Test(timeout = 90000)
public void testAsyncTransactionServiceNoTimeout() throws Exception {
public void testAsyncTransactionService() throws Exception {
System.out.println("JGB AsyncTxServiceA: "+ServiceFactory.getAsyncTxService());
TransactionAsyncUtility.createServiceManager(createConfigMap(90000));
System.out.println("JGB AsyncTxServiceB: "+ServiceFactory.getAsyncTxService());
Expand All @@ -46,11 +45,8 @@ public void testAsyncTransactionServiceNoTimeout() throws Exception {
}

@Test(timeout = 90000)
public void testAsyncTransactionServiceForceTimeout() throws Exception {
System.out.println("JGB AsyncTxService1: "+ServiceFactory.getAsyncTxService());
public void testAsyncTransactionServiceTimeout() throws Exception {
TransactionAsyncUtility.createServiceManager(createConfigMap(1));
System.out.println("JGB AsyncTxService2: "+ServiceFactory.getAsyncTxService());
System.out.println("JGB timeout in test secs: "+ServiceFactory.getConfigService().getDefaultAgentConfig().getTokenTimeoutInSec());

assertEquals(0, ServiceFactory.getAsyncTxService().cacheSizeForTesting());
ServiceFactory.getAsyncTxService().beforeHarvest("test", null);
Expand All @@ -63,17 +59,13 @@ public void testAsyncTransactionServiceForceTimeout() throws Exception {
assertFalse(ServiceFactory.getAsyncTxService().putIfAbsent("mySecondKey", token));
assertEquals(2, ServiceFactory.getAsyncTxService().cacheSizeForTesting());

Thread.sleep(5000);
ServiceFactory.getAsyncTxService().cleanUpPendingTransactions();
// wait for the timeout
long tokenTimeoutMillis = ServiceFactory.getConfigService().getDefaultAgentConfig().getTokenTimeoutInSec();
Thread.sleep(tokenTimeoutMillis + 5000);

for (int i=0;i<25;i++) {
System.out.println("JGB cache size: "+ServiceFactory.getAsyncTxService().cacheSizeForTesting());
if (0 == ServiceFactory.getAsyncTxService().cacheSizeForTesting()) break;
try { Thread.sleep(1000); } catch (Exception e) {}
ServiceFactory.getAsyncTxService().cleanUpPendingTransactions();
}
ServiceFactory.getAsyncTxService().cleanUpPendingTransactions();

assertEquals("Cache should be empty", 0, ServiceFactory.getAsyncTxService().cacheSizeForTesting());
assertEquals(0, ServiceFactory.getAsyncTxService().cacheSizeForTesting());
assertNull(ServiceFactory.getAsyncTxService().extractIfPresent("myFirstKey"));
assertNull(ServiceFactory.getAsyncTxService().extractIfPresent("mySecondKey"));

Expand Down

0 comments on commit 6047b85

Please sign in to comment.