Skip to content

Commit

Permalink
Merge pull request #2156 from newrelic/sa-log-fix
Browse files Browse the repository at this point in the history
Only log if superagent is enabled
  • Loading branch information
jtduffy authored Nov 26, 2024
2 parents 4431da3 + 0437e5d commit 6a2de60
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,21 +27,22 @@ public class SuperAgentIntegrationConfigImpl extends BaseConfig implements Super
public SuperAgentIntegrationConfigImpl(Map<String, Object> 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() {
Map<String, Object> healthProps = getProperty(SuperAgentIntegrationHealthConfig.ROOT, Collections.emptyMap());
SuperAgentIntegrationHealthConfig superAgentIntegrationHealthConfig;

superAgentIntegrationHealthConfig = new SuperAgentIntegrationHealthConfig(healthProps, SYSTEM_PROPERTY_ROOT);

if (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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -355,14 +356,17 @@ private InfiniteTracing buildInfiniteTracing(ConfigService configService) {
}

private SuperAgentIntegrationService buildSuperAgentIntegrationService(AgentConfig config) {
SuperAgentIntegrationHealthClient healthClient =
SuperAgentIntegrationClientFactory.createHealthClient(config.getSuperAgentIntegrationConfig());

ArrayList<HealthDataProducer> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a2de60

Please sign in to comment.