use of com.newrelic.agent.config.SpanEventsConfig in project newrelic-java-agent by newrelic.
the class CollectorSpanEventReservoirManagerTest method mock21Samples.
public ConfigService mock21Samples() {
ConfigService mockConfigService = Mockito.mock(ConfigService.class);
AgentConfig mockConfig = Mockito.mock(AgentConfig.class);
SpanEventsConfig mockSpanEventsConfig = Mockito.mock(SpanEventsConfig.class);
when(mockConfigService.getDefaultAgentConfig()).thenReturn(mockConfig);
when(mockConfigService.getAgentConfig(anyString())).thenReturn(mockConfig);
when(mockConfig.getSpanEventsConfig()).thenReturn(mockSpanEventsConfig);
when(mockSpanEventsConfig.getMaxSamplesStored()).thenReturn(21);
return mockConfigService;
}
use of com.newrelic.agent.config.SpanEventsConfig in project newrelic-java-agent by newrelic.
the class SpanEventsConfigTest method maxSamplesStoredOverrideBySystemProperty.
@Test
public void maxSamplesStoredOverrideBySystemProperty() {
// given
int customMaxSamples = 1000;
setMaxSamplesViaSystemProp(customMaxSamples);
Map<String, Object> localSettings = new HashMap<>();
// when
SpanEventsConfig config = new SpanEventsConfig(localSettings, true);
// then
assertEquals("Max samples stored should be " + customMaxSamples, customMaxSamples, config.getMaxSamplesStored());
}
use of com.newrelic.agent.config.SpanEventsConfig in project newrelic-java-agent by newrelic.
the class CollectorSpanEventReservoirManager method createDistributedSamplingReservoir.
private SamplingPriorityQueue<SpanEvent> createDistributedSamplingReservoir(String appName, int decidedLast) {
SpanEventsConfig spanEventsConfig = configService.getDefaultAgentConfig().getSpanEventsConfig();
int target = spanEventsConfig.getTargetSamplesStored();
return new DistributedSamplingPriorityQueue<>(appName, "Span Event Service", maxSamplesStored, decidedLast, target, SPAN_EVENT_COMPARATOR);
}
use of com.newrelic.agent.config.SpanEventsConfig in project newrelic-java-agent by newrelic.
the class CollectorSpanEventReservoirManager method attemptToSendReservoir.
@Override
public HarvestResult attemptToSendReservoir(final String appName, EventSender<SpanEvent> eventSender, Logger logger) {
if (getMaxSamplesStored() <= 0) {
clearReservoir();
return null;
}
SpanEventsConfig config = configService.getAgentConfig(appName).getSpanEventsConfig();
int decidedLast = AdaptiveSampling.decidedLast(spanReservoirsForApp.get(appName), config.getTargetSamplesStored());
// save a reference to the old reservoir to finish harvesting, and create a new one
final SamplingPriorityQueue<SpanEvent> toSend = spanReservoirsForApp.get(appName);
spanReservoirsForApp.put(appName, createDistributedSamplingReservoir(appName, decidedLast));
if (toSend == null || toSend.size() <= 0) {
return null;
}
try {
eventSender.sendEvents(appName, config.getMaxSamplesStored(), toSend.getNumberOfTries(), Collections.unmodifiableList(toSend.asList()));
if (toSend.size() < toSend.getNumberOfTries()) {
int dropped = toSend.getNumberOfTries() - toSend.size();
logger.log(Level.FINE, "Dropped {0} span events out of {1}.", dropped, toSend.getNumberOfTries());
}
return new HarvestResult(toSend.getNumberOfTries(), toSend.size());
} catch (HttpError e) {
if (!e.discardHarvestData()) {
logger.log(Level.FINE, "Unable to send span events. Unsent events will be included in the next harvest.", e);
// Save unsent data by merging it with toSend data using reservoir algorithm
spanReservoirsForApp.get(appName).retryAll(toSend);
} else {
// discard harvest data
toSend.clear();
logger.log(Level.FINE, "Unable to send span events. Unsent events will be dropped.", e);
}
} catch (Exception e) {
// discard harvest data
toSend.clear();
logger.log(Level.FINE, "Unable to send span events. Unsent events will be dropped.", e);
}
return null;
}
use of com.newrelic.agent.config.SpanEventsConfig in project newrelic-java-agent by newrelic.
the class MockSpanEventReservoirManager method createDistributedSamplingReservoir.
private SamplingPriorityQueue<SpanEvent> createDistributedSamplingReservoir(String appName, int decidedLast) {
SpanEventsConfig spanEventsConfig = configService.getDefaultAgentConfig().getSpanEventsConfig();
int target = spanEventsConfig.getTargetSamplesStored();
return new DistributedSamplingPriorityQueue<>(appName, "Span Event Service", maxSamplesStored, decidedLast, target, SPAN_EVENT_COMPARATOR);
}
Aggregations