From 8b296a6d623bc0245a961cdc7179b6f825c2664b Mon Sep 17 00:00:00 2001 From: Jerry Duffy Date: Mon, 25 Nov 2024 15:57:19 -0500 Subject: [PATCH 1/2] Only log if superagent is enabled --- .../SuperAgentIntegrationConfigImpl.java | 2 +- .../agent/service/ServiceManagerImpl.java | 18 +++++++++++------- .../SuperAgentIntegrationService.java | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationConfigImpl.java b/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationConfigImpl.java index 87d2c83eff..4dc166a26c 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationConfigImpl.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationConfigImpl.java @@ -35,7 +35,7 @@ private SuperAgentIntegrationHealthConfig createHealthConfig() { superAgentIntegrationHealthConfig = new SuperAgentIntegrationHealthConfig(healthProps, SYSTEM_PROPERTY_ROOT); - if (superAgentIntegrationHealthConfig.getHealthDeliveryLocation() == null) { + if (isEnabled() && superAgentIntegrationHealthConfig.getHealthDeliveryLocation() == null) { Agent.LOG.log(Level.WARNING, "Configured Super Agent health delivery location is not a valid URI; " + "SuperAgent integration service will not be started"); superAgentIntegrationHealthConfig = null; diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/service/ServiceManagerImpl.java b/newrelic-agent/src/main/java/com/newrelic/agent/service/ServiceManagerImpl.java index 105f76ed20..392ff6a546 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/service/ServiceManagerImpl.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/service/ServiceManagerImpl.java @@ -91,6 +91,7 @@ import com.newrelic.api.agent.Logger; import com.newrelic.api.agent.MetricAggregator; import com.newrelic.api.agent.NewRelic; +import org.apache.commons.lang3.StringUtils; import java.net.URL; import java.util.ArrayList; @@ -355,14 +356,17 @@ private InfiniteTracing buildInfiniteTracing(ConfigService configService) { } private SuperAgentIntegrationService buildSuperAgentIntegrationService(AgentConfig config) { - SuperAgentIntegrationHealthClient healthClient = - SuperAgentIntegrationClientFactory.createHealthClient(config.getSuperAgentIntegrationConfig()); - ArrayList healthDataProducers = new ArrayList<>(); - healthDataProducers.add(circuitBreakerService); - healthDataProducers.add((HealthDataProducer) coreService); - for (IRPMService service : ServiceFactory.getRPMServiceManager().getRPMServices()) { - healthDataProducers.add(service.getHttpDataSenderAsHealthDataProducer()); + SuperAgentIntegrationHealthClient healthClient = null; + + if (config.getSuperAgentIntegrationConfig() != null && StringUtils.isNotEmpty(config.getSuperAgentIntegrationConfig().getFleetId())) { + healthClient = SuperAgentIntegrationClientFactory.createHealthClient(config.getSuperAgentIntegrationConfig()); + + healthDataProducers.add(circuitBreakerService); + healthDataProducers.add((HealthDataProducer) coreService); + for (IRPMService service : ServiceFactory.getRPMServiceManager().getRPMServices()) { + healthDataProducers.add(service.getHttpDataSenderAsHealthDataProducer()); + } } return new SuperAgentIntegrationService(healthClient, config, diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/superagent/SuperAgentIntegrationService.java b/newrelic-agent/src/main/java/com/newrelic/agent/superagent/SuperAgentIntegrationService.java index 847937715e..4971d4124a 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/superagent/SuperAgentIntegrationService.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/superagent/SuperAgentIntegrationService.java @@ -65,7 +65,7 @@ protected void doStop() throws Exception { @Override public boolean isEnabled() { - return agentConfig.getSuperAgentIntegrationConfig().isEnabled() && client.isValid(); + return agentConfig.getSuperAgentIntegrationConfig().isEnabled() && client != null && client.isValid(); } @Override From 0437e5d1efca424ff688199df3f953baaa9f0c68 Mon Sep 17 00:00:00 2001 From: Jerry Duffy Date: Tue, 26 Nov 2024 09:29:44 -0500 Subject: [PATCH 2/2] Correct unit test --- .../SuperAgentIntegrationConfigImpl.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationConfigImpl.java b/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationConfigImpl.java index 4dc166a26c..274d871158 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationConfigImpl.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationConfigImpl.java @@ -7,6 +7,7 @@ package com.newrelic.agent.config; import com.newrelic.agent.Agent; +import org.apache.commons.lang3.StringUtils; import java.net.URI; import java.net.URISyntaxException; @@ -26,7 +27,15 @@ public class SuperAgentIntegrationConfigImpl extends BaseConfig implements Super public SuperAgentIntegrationConfigImpl(Map configProps) { super(configProps, SYSTEM_PROPERTY_ROOT); superAgentIntegrationHealthConfig = createHealthConfig(); - fleetId = superAgentIntegrationHealthConfig == null ? null : getProperty(FLEET_ID); + String tmpFleetId = getProperty(FLEET_ID); + + if (StringUtils.isNotEmpty(tmpFleetId) && superAgentIntegrationHealthConfig.getHealthDeliveryLocation() == null) { + Agent.LOG.log(Level.WARNING, "Configured Super Agent health delivery location is not a valid URI; " + + "SuperAgent integration service will not be started"); + fleetId = null; + } else { + fleetId = tmpFleetId; + } } private SuperAgentIntegrationHealthConfig createHealthConfig() { @@ -34,13 +43,6 @@ private SuperAgentIntegrationHealthConfig createHealthConfig() { SuperAgentIntegrationHealthConfig superAgentIntegrationHealthConfig; superAgentIntegrationHealthConfig = new SuperAgentIntegrationHealthConfig(healthProps, SYSTEM_PROPERTY_ROOT); - - if (isEnabled() && superAgentIntegrationHealthConfig.getHealthDeliveryLocation() == null) { - Agent.LOG.log(Level.WARNING, "Configured Super Agent health delivery location is not a valid URI; " + - "SuperAgent integration service will not be started"); - superAgentIntegrationHealthConfig = null; - } - return superAgentIntegrationHealthConfig; }