Search in sources :

Example 1 with SpanEventsConfig

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;
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) SpanEventsConfig(com.newrelic.agent.config.SpanEventsConfig)

Example 2 with SpanEventsConfig

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());
}
Also used : SpanEventsConfig(com.newrelic.agent.config.SpanEventsConfig) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with SpanEventsConfig

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);
}
Also used : SpanEventsConfig(com.newrelic.agent.config.SpanEventsConfig)

Example 4 with SpanEventsConfig

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;
}
Also used : SpanEventsConfig(com.newrelic.agent.config.SpanEventsConfig) SpanEvent(com.newrelic.agent.model.SpanEvent) HttpError(com.newrelic.agent.transport.HttpError)

Example 5 with SpanEventsConfig

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);
}
Also used : SpanEventsConfig(com.newrelic.agent.config.SpanEventsConfig) DistributedSamplingPriorityQueue(com.newrelic.agent.service.analytics.DistributedSamplingPriorityQueue)

Aggregations

SpanEventsConfig (com.newrelic.agent.config.SpanEventsConfig)9 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 AgentConfig (com.newrelic.agent.config.AgentConfig)1 ConfigService (com.newrelic.agent.config.ConfigService)1 SpanEvent (com.newrelic.agent.model.SpanEvent)1 DistributedSamplingPriorityQueue (com.newrelic.agent.service.analytics.DistributedSamplingPriorityQueue)1 HttpError (com.newrelic.agent.transport.HttpError)1