Skip to content

Commit

Permalink
Making sure that Transaction Log reservoir is no bigger than it needs (
Browse files Browse the repository at this point in the history
  • Loading branch information
meiao authored Feb 9, 2024
1 parent c33e6c6 commit ec31620
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void recordLogEvent(Map<LogAttributeKey, ?> attributes) {
}

@Override
public Logs getTransactionLogs(AgentConfig config) {
public Logs getTransactionLogs() {
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,7 @@ public Insights getInsightsData() {
public Logs getLogEventData() {
Logs logEventData = logEvents.get();
if (logEventData == null) {
AgentConfig defaultConfig = ServiceFactory.getConfigService().getDefaultAgentConfig();
logEvents.compareAndSet(null, ServiceFactory.getServiceManager().getLogSenderService().getTransactionLogs(defaultConfig));
logEvents.compareAndSet(null, ServiceFactory.getServiceManager().getLogSenderService().getTransactionLogs());
logEventData = logEvents.get();
}
return logEventData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface LogSenderService extends EventService, Logs {
* Returns an insights instance used to track events created during a transaction. The events will be reported to
* the Transaction's application, or to the default application if not in a transaction.
*/
Logs getTransactionLogs(AgentConfig config);
Logs getTransactionLogs();

/**
* Store event into Reservoir following usual sampling using the given appName. Preference should be given to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,8 @@ protected Map<String, Object> getAttributeMap() {
}

@Override
public Logs getTransactionLogs(AgentConfig config) {
return new TransactionLogs(config, contextDataKeyFilter);
public Logs getTransactionLogs() {
return new TransactionLogs(maxSamplesStored, contextDataKeyFilter);
}

/**
Expand All @@ -589,8 +589,7 @@ public static final class TransactionLogs implements Logs {
private final LinkedBlockingQueue<LogEvent> events;
private final ExcludeIncludeFilter contextDataKeyFilter;

TransactionLogs(AgentConfig config, ExcludeIncludeFilter contextDataKeyFilter) {
int maxSamplesStored = config.getApplicationLoggingConfig().getMaxSamplesStored();
TransactionLogs(int maxSamplesStored, ExcludeIncludeFilter contextDataKeyFilter) {
events = new LinkedBlockingQueue<>(maxSamplesStored);
this.contextDataKeyFilter = contextDataKeyFilter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class LogSenderServiceImplTest {
private static final HarvestService harvestService = Mockito.mock(HarvestService.class);
private static final TransactionService txService = Mockito.mock(TransactionService.class);
private static final StatsService statsService = Mockito.mock(StatsService.class);
private static final int LOG_FORWARDING_MAX_SAMPLES_STORED = 100; // should be enough for testing

private static LogSenderServiceImpl createService() throws Exception {
return createService(createConfig());
Expand Down Expand Up @@ -89,7 +90,7 @@ public void testHighSecurity() throws Exception {
when(ServiceFactory.getTransactionService().getTransaction(false)).thenReturn(transaction);

LogSenderServiceImpl.TransactionLogs logs = new LogSenderServiceImpl.TransactionLogs(
AgentConfigImpl.createAgentConfig(Collections.emptyMap()), allowAllFilter());
LOG_FORWARDING_MAX_SAMPLES_STORED, allowAllFilter());
when(transaction.getLogEventData()).thenReturn(logs);
when(transaction.getApplicationName()).thenReturn(appName);
when(transaction.isInProgress()).thenReturn(true);
Expand Down Expand Up @@ -145,7 +146,7 @@ public void testWithTransaction() throws Exception {
when(ServiceFactory.getTransactionService().getTransaction(false)).thenReturn(transaction);

LogSenderServiceImpl.TransactionLogs logs = new LogSenderServiceImpl.TransactionLogs(
AgentConfigImpl.createAgentConfig(Collections.emptyMap()), allowAllFilter());
LOG_FORWARDING_MAX_SAMPLES_STORED, allowAllFilter());
when(transaction.getLogEventData()).thenReturn(logs);
when(transaction.getApplicationName()).thenReturn(appName);
when(transaction.isInProgress()).thenReturn(true);
Expand Down Expand Up @@ -173,7 +174,7 @@ public void testTransactionHarvest() throws Exception {
when(ServiceFactory.getTransactionService().getTransaction(false)).thenReturn(transaction);

LogSenderServiceImpl.TransactionLogs logs = new LogSenderServiceImpl.TransactionLogs(
AgentConfigImpl.createAgentConfig(Collections.emptyMap()), allowAllFilter());
LOG_FORWARDING_MAX_SAMPLES_STORED, allowAllFilter());
when(transaction.getLogEventData()).thenReturn(logs);
when(transaction.getApplicationName()).thenReturn(appName);
when(transaction.isInProgress()).thenReturn(true);
Expand Down

0 comments on commit ec31620

Please sign in to comment.