Search in sources :

Example 66 with ConfigService

use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.

the class CollectorSpanEventReservoirManagerTest method httpErrorTriggerDiscard.

@Test
public void httpErrorTriggerDiscard() {
    ConfigService mockConfigService = mock21Samples();
    CollectorSpanEventReservoirManager target = initWith25Tries(mockConfigService);
    ReservoirManager.HarvestResult harvestResult = target.attemptToSendReservoir(APP_NAME, (appName, reservoirSize, eventsSeen, events) -> {
        throw new HttpError("message", 0, 0) {

            @Override
            public boolean discardHarvestData() {
                return true;
            }
        };
    }, mock(Logger.class));
    assertNull(harvestResult);
    assertEquals(0, target.getOrCreateReservoir(APP_NAME).size());
    assertEquals(0, target.getOrCreateReservoir(APP_NAME).getNumberOfTries());
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) ReservoirManager(com.newrelic.agent.interfaces.ReservoirManager) HttpError(com.newrelic.agent.transport.HttpError) Logger(com.newrelic.api.agent.Logger) Test(org.junit.Test)

Example 67 with ConfigService

use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.

the class CollectorSpanEventReservoirManagerTest method getOrCreateReturnsSameReservoir.

@Test
public void getOrCreateReturnsSameReservoir() {
    ConfigService mockConfigService = mock21Samples();
    CollectorSpanEventReservoirManager target = initWith25Tries(mockConfigService);
    assertEquals(21, target.getOrCreateReservoir(APP_NAME).size());
    assertTrue(target.getOrCreateReservoir(APP_NAME).isFull());
}
Also used : ConfigService(com.newrelic.agent.config.ConfigService) Test(org.junit.Test)

Example 68 with ConfigService

use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.

the class CoreServiceImpl method doStart.

@Override
protected void doStart() {
    ConfigService configService = ServiceFactory.getConfigService();
    AgentConfig config = configService.getDefaultAgentConfig();
    AgentLogManager.configureLogger(config);
    logHostIp();
    Agent.LOG.info(MessageFormat.format("New Relic Agent v{0} is initializing...", Agent.getVersion()));
    enabled = config.isAgentEnabled();
    if (!enabled) {
        Agent.LOG.info("New Relic agent is disabled.");
    }
    if (config.liteMode()) {
        Agent.LOG.info("New Relic agent is running in lite mode. All instrumentation modules are disabled");
        StatsService statsService = ServiceFactory.getServiceManager().getStatsService();
        statsService.getMetricAggregator().incrementCounter(MetricNames.SUPPORTABILITY_LITE_MODE);
    }
    instrumentationProxy = InstrumentationProxy.getInstrumentationProxy(instrumentation);
    initializeBridgeApis();
    final long startTime = System.currentTimeMillis();
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            jvmShutdown(startTime);
        }
    };
    Thread shutdownThread = new Thread(runnable, "New Relic JVM Shutdown");
    Runtime.getRuntime().addShutdownHook(shutdownThread);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) StatsService(com.newrelic.agent.stats.StatsService)

Example 69 with ConfigService

use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.

the class HeadersUtilTest method createDTHeadersSetsSpanIdEvenIfTxNotSampled.

@Test
public void createDTHeadersSetsSpanIdEvenIfTxNotSampled() {
    ConfigService mockConfigService = new MockConfigService(AgentConfigImpl.createAgentConfig(ImmutableMap.of(AgentConfigImpl.APP_NAME, "Unit Test", AgentConfigImpl.DISTRIBUTED_TRACING, Collections.singletonMap(DistributedTracingConfig.ENABLED, true), AgentConfigImpl.SPAN_EVENTS, ImmutableMap.of(SpanEventsConfig.ENABLED, true, SpanEventsConfig.COLLECT_SPAN_EVENTS, true))));
    MockServiceManager mockServiceManager = new MockServiceManager(mockConfigService);
    mockServiceManager.setDistributedTraceService(new MockDistributedTraceService());
    ServiceFactory.setServiceManager(mockServiceManager);
    Transaction tx = Transaction.getTransaction();
    tx.setPriorityIfNotNull(0F);
    tx.startTransactionIfBeginning(new MockDispatcherTracer(tx));
    Tracer mockTracer = new DefaultTracer(tx, new ClassMethodSignature(getClass().getName(), "tracerMethod", "()V"), this);
    OutboundHeadersMap map = new OutboundHeadersMap(HeaderType.HTTP);
    assertTrue("DT headers should have been set", HeadersUtil.createAndSetDistributedTraceHeaders(tx, mockTracer, map));
    assertFalse(tx.sampled());
    assertTrue("map should contain newrelic header", map.containsKey("newrelic"));
    String decodedHeader = new String(Base64.decodeBase64(map.get("newrelic")), StandardCharsets.UTF_8);
    JsonObject jsonObject = new Gson().fromJson(decodedHeader, JsonObject.class);
    assertFalse("d.sa should be false because tx is not sampled", jsonObject.getAsJsonObject("d").get("sa").getAsBoolean());
    assertEquals("d.pr should be zero", 0f, jsonObject.getAsJsonObject("d").get("pr").getAsFloat(), 0.0001);
    assertNotNull("d.id should not be null", jsonObject.getAsJsonObject("d").get("id"));
    assertEquals("d.id should be the span id.", mockTracer.getGuid(), jsonObject.getAsJsonObject("d").get("id").getAsString());
    String traceParent = map.get("traceparent");
    assertEquals("traceparent parentId field should match span id.", mockTracer.getGuid(), traceParent.split("-")[2]);
    String traceState = map.get("tracestate");
    assertEquals("tracestate spanId field should match span id.", mockTracer.getGuid(), traceState.split("-")[4]);
    assertEquals("tracestate txId field should match tx id.", tx.getGuid(), traceState.split("-")[5]);
}
Also used : Tracer(com.newrelic.agent.tracers.Tracer) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) MockDistributedTraceService(com.newrelic.agent.util.MockDistributedTraceService) ConfigService(com.newrelic.agent.config.ConfigService) DefaultTracer(com.newrelic.agent.tracers.DefaultTracer) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) Test(org.junit.Test)

Example 70 with ConfigService

use of com.newrelic.agent.config.ConfigService in project newrelic-java-agent by newrelic.

the class AgentImplTest method createServiceManager.

private static void createServiceManager(Map<String, Object> map) throws Exception {
    MockServiceManager serviceManager = new MockServiceManager();
    ServiceFactory.setServiceManager(serviceManager);
    serviceManager.start();
    AgentConfig agentConfig = AgentHelper.createAgentConfig(true, map, Collections.<String, Object>emptyMap());
    ConfigService configService = ConfigServiceFactory.createConfigService(agentConfig, map);
    serviceManager.setConfigService(configService);
    TransactionTraceService transactionTraceService = new TransactionTraceService();
    serviceManager.setTransactionTraceService(transactionTraceService);
}
Also used : AgentConfig(com.newrelic.agent.config.AgentConfig) ConfigService(com.newrelic.agent.config.ConfigService) TransactionTraceService(com.newrelic.agent.trace.TransactionTraceService)

Aggregations

ConfigService (com.newrelic.agent.config.ConfigService)95 MockServiceManager (com.newrelic.agent.MockServiceManager)57 TransactionService (com.newrelic.agent.TransactionService)36 AgentConfig (com.newrelic.agent.config.AgentConfig)36 TransactionTraceService (com.newrelic.agent.trace.TransactionTraceService)32 ThreadService (com.newrelic.agent.ThreadService)31 AttributesService (com.newrelic.agent.attributes.AttributesService)30 MockRPMServiceManager (com.newrelic.agent.MockRPMServiceManager)29 HarvestService (com.newrelic.agent.HarvestService)24 MockHarvestService (com.newrelic.agent.MockHarvestService)23 HashMap (java.util.HashMap)23 StatsService (com.newrelic.agent.stats.StatsService)21 MockCoreService (com.newrelic.agent.MockCoreService)20 MockRPMService (com.newrelic.agent.MockRPMService)20 SqlTraceServiceImpl (com.newrelic.agent.sql.SqlTraceServiceImpl)20 StatsServiceImpl (com.newrelic.agent.stats.StatsServiceImpl)20 SqlTraceService (com.newrelic.agent.sql.SqlTraceService)19 ErrorServiceImpl (com.newrelic.agent.errors.ErrorServiceImpl)17 Test (org.junit.Test)15 EnvironmentService (com.newrelic.agent.environment.EnvironmentService)14