Skip to content

Commit

Permalink
Refactor super agent name out of the agent
Browse files Browse the repository at this point in the history
  • Loading branch information
jtduffy committed Dec 18, 2024
1 parent 2180493 commit 1ab03e1
Show file tree
Hide file tree
Showing 38 changed files with 258 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.newrelic.agent.InstrumentationProxy;
import com.newrelic.agent.core.CoreService;
import com.newrelic.agent.service.AbstractService;
import com.newrelic.agent.superagent.HealthDataChangeListener;
import com.newrelic.agent.superagent.HealthDataProducer;
import com.newrelic.agent.agentcontrol.HealthDataChangeListener;
import com.newrelic.agent.agentcontrol.HealthDataProducer;

class IntrospectorCoreService extends AbstractService implements CoreService, HealthDataProducer {
private InstrumentationProxy instrumentation = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.newrelic.agent.service.module.JarData;
import com.newrelic.agent.sql.SqlTrace;
import com.newrelic.agent.stats.StatsEngine;
import com.newrelic.agent.superagent.HealthDataProducer;
import com.newrelic.agent.agentcontrol.HealthDataProducer;
import com.newrelic.agent.trace.TransactionTrace;
import com.newrelic.agent.transaction.TransactionNamingScheme;

Expand Down
8 changes: 4 additions & 4 deletions newrelic-agent/src/main/java/com/newrelic/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import com.newrelic.agent.service.ServiceManagerImpl;
import com.newrelic.agent.stats.StatsService;
import com.newrelic.agent.stats.StatsWorks;
import com.newrelic.agent.superagent.AgentHealth;
import com.newrelic.agent.superagent.SuperAgentIntegrationUtils;
import com.newrelic.agent.agentcontrol.AgentHealth;
import com.newrelic.agent.agentcontrol.AgentControlIntegrationUtils;
import com.newrelic.agent.util.UnwindableInstrumentation;
import com.newrelic.agent.util.UnwindableInstrumentationImpl;
import com.newrelic.agent.util.asm.ClassStructure;
Expand Down Expand Up @@ -294,13 +294,13 @@ private static boolean tryToInitializeServiceManager(Instrumentation inst) {

AgentConfig agentConfig = serviceManager.getConfigService().getDefaultAgentConfig();
if (isLicenseKeyEmpty(agentConfig.getLicenseKey())) {
SuperAgentIntegrationUtils.reportUnhealthyStatusPriorToServiceStart(agentConfig, AgentHealth.Status.MISSING_LICENSE);
AgentControlIntegrationUtils.reportUnhealthyStatusPriorToServiceStart(agentConfig, AgentHealth.Status.MISSING_LICENSE);
LOG.error("license_key is empty in the config. Not starting New Relic Agent.");
return false;
}

if (!serviceManager.getConfigService().getDefaultAgentConfig().isAgentEnabled()) {
SuperAgentIntegrationUtils.reportUnhealthyStatusPriorToServiceStart(agentConfig, AgentHealth.Status.AGENT_DISABLED);
AgentControlIntegrationUtils.reportUnhealthyStatusPriorToServiceStart(agentConfig, AgentHealth.Status.AGENT_DISABLED);
LOG.warning("agent_enabled is false in the config. Not starting New Relic Agent.");
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.newrelic.agent.service.module.JarData;
import com.newrelic.agent.sql.SqlTrace;
import com.newrelic.agent.stats.StatsEngine;
import com.newrelic.agent.superagent.HealthDataProducer;
import com.newrelic.agent.agentcontrol.HealthDataProducer;
import com.newrelic.agent.trace.TransactionTrace;
import com.newrelic.agent.transaction.TransactionNamingScheme;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public class MetricNames {
public static final String SUPPORTABILITY_AI_MONITORING_TOKEN_COUNT_CALLBACK_SET = "Supportability/AiMonitoringTokenCountCallback/Set";

// Super Agent Integration
public static final String SUPPORTABILITY_SUPERAGENT_HEALTH_REPORTING_ENABLED = "Supportability/SuperAgent/Health/enabled";
public static final String SUPPORTABILITY_AGENT_CONTROL_HEALTH_REPORTING_ENABLED = "Supportability/AgentControl/Health/enabled";

/**
* Utility method for adding supportability metrics to APIs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
import com.newrelic.agent.service.module.JarData;
import com.newrelic.agent.sql.SqlTrace;
import com.newrelic.agent.stats.StatsEngine;
import com.newrelic.agent.superagent.AgentHealth;
import com.newrelic.agent.superagent.HealthDataChangeListener;
import com.newrelic.agent.superagent.HealthDataProducer;
import com.newrelic.agent.agentcontrol.HealthDataProducer;
import com.newrelic.agent.trace.TransactionTrace;
import com.newrelic.agent.transaction.TransactionNamingScheme;
import com.newrelic.agent.transport.ConnectionResponse;
Expand All @@ -61,7 +59,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.superagent;
package com.newrelic.agent.agentcontrol;

import com.newrelic.agent.Agent;
import com.newrelic.agent.config.SuperAgentIntegrationConfig;
import com.newrelic.agent.config.AgentControlIntegrationConfig;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;

Expand All @@ -20,12 +20,12 @@
import java.util.UUID;
import java.util.logging.Level;

public class SuperAgentIntegrationHealthFileBasedClient implements SuperAgentIntegrationHealthClient {
public class AgentControlControlIntegrationHealthFileBasedClient implements AgentControlIntegrationHealthClient {
private Yaml yamlWriter;
private File healthFile = null;
private boolean isValid = false;

public SuperAgentIntegrationHealthFileBasedClient(SuperAgentIntegrationConfig config) {
public AgentControlControlIntegrationHealthFileBasedClient(AgentControlIntegrationConfig config) {
URI locationFromConfig = config.getHealthDeliveryLocation();

File fileFolder = createHealthFileFolderInstance(locationFromConfig);
Expand All @@ -49,10 +49,10 @@ public void sendHealthMessage(AgentHealth agentHealth) {
fw.close();

if (Agent.LOG.isFinestEnabled() && Agent.isDebugEnabled()) {
Agent.LOG.log(Level.FINEST, "Wrote SA health file: {0}", healthFile.getAbsolutePath());
Agent.LOG.log(Level.FINEST, "Wrote agent control health file: {0}", healthFile.getAbsolutePath());
}
} catch (IOException e) {
Agent.LOG.log(Level.WARNING, "Error writing health message to file: {0}", e.getMessage());
Agent.LOG.log(Level.WARNING, "Error writing agent control health message to file: {0}", e.getMessage());
}
}
}
Expand All @@ -68,7 +68,7 @@ private Map<String, Object> createHeathMessageMap(AgentHealth agentHealth) {
healthMap.put("healthy", agentHealth.isHealthy());
healthMap.put("status", agentHealth.getCurrentStatus());
healthMap.put("start_time_unix_nano", agentHealth.getStartTimeNanos());
healthMap.put("status_time_unix_nano", SuperAgentIntegrationUtils.getPseudoCurrentTimeNanos());
healthMap.put("status_time_unix_nano", AgentControlIntegrationUtils.getPseudoCurrentTimeNanos());
if (!agentHealth.isHealthy()) {
healthMap.put("last_error", agentHealth.getLastError());
}
Expand All @@ -81,7 +81,7 @@ private File createHealthFileFolderInstance(URI location) {
if (location != null) {
fileFolder = new File(location);
if (!(fileFolder.isDirectory() && fileFolder.canWrite())) {
Agent.LOG.log(Level.WARNING, "superagent.health.delivery_location is not a valid folder. " +
Agent.LOG.log(Level.WARNING, "agent_control.health.delivery_location is not a valid folder. " +
"Health messages will not be generated. Configured location: {0} isFolder: {1} canWrite: {2}",
fileFolder.getAbsolutePath(), fileFolder.isDirectory(), fileFolder.canWrite());
fileFolder = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.superagent;
package com.newrelic.agent.agentcontrol;

public class SuperAgentHealthNoOpClient implements SuperAgentIntegrationHealthClient {
public class AgentControlHealthNoOpClientControl implements AgentControlIntegrationHealthClient {
@Override
public void sendHealthMessage(AgentHealth agentHealth) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.superagent;
package com.newrelic.agent.agentcontrol;

import com.newrelic.agent.Agent;
import com.newrelic.agent.config.SuperAgentIntegrationConfig;
import com.newrelic.agent.config.AgentControlIntegrationConfig;

import java.util.logging.Level;

public class SuperAgentIntegrationClientFactory {
private static final SuperAgentIntegrationHealthClient NO_OP_INSTANCE = new SuperAgentHealthNoOpClient();
public class AgentControlIntegrationClientFactory {
private static final AgentControlIntegrationHealthClient NO_OP_INSTANCE = new AgentControlHealthNoOpClientControl();

public enum HealthClientType {
noop,
file,
}
public static SuperAgentIntegrationHealthClient createHealthClient(SuperAgentIntegrationConfig config) {
SuperAgentIntegrationHealthClient client;
public static AgentControlIntegrationHealthClient createHealthClient(AgentControlIntegrationConfig config) {
AgentControlIntegrationHealthClient client;

try {
HealthClientType healthClientType = HealthClientType.valueOf(config.getHealthClientType());
Agent.LOG.log(Level.INFO, "Generating SuperAgent Health Client type: {0}", healthClientType);
Agent.LOG.log(Level.INFO, "Generating Agent Control Health Client type: {0}", healthClientType);

switch (healthClientType) {
case file:
client = new SuperAgentIntegrationHealthFileBasedClient(config);
client = new AgentControlControlIntegrationHealthFileBasedClient(config);
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.superagent;
package com.newrelic.agent.agentcontrol;

public interface SuperAgentIntegrationHealthClient {
public interface AgentControlIntegrationHealthClient {
void sendHealthMessage(AgentHealth agentHealth);

boolean isValid();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.superagent;
package com.newrelic.agent.agentcontrol;

import com.newrelic.agent.Agent;
import com.newrelic.agent.MetricNames;
Expand All @@ -18,20 +18,20 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

public class SuperAgentIntegrationService extends AbstractService implements HealthDataChangeListener {
public class AgentControlIntegrationService extends AbstractService implements HealthDataChangeListener {
private final AgentConfig agentConfig;
private final SuperAgentIntegrationHealthClient client;
private final AgentControlIntegrationHealthClient client;
private final AgentHealth agentHealth;

private ScheduledExecutorService scheduler;

public SuperAgentIntegrationService(SuperAgentIntegrationHealthClient client, AgentConfig agentConfig,
public AgentControlIntegrationService(AgentControlIntegrationHealthClient client, AgentConfig agentConfig,
HealthDataProducer... healthProducers) {
super(SuperAgentIntegrationService.class.getSimpleName());
super(AgentControlIntegrationService.class.getSimpleName());

this.agentConfig = agentConfig;
this.client = client;
this.agentHealth = new AgentHealth(SuperAgentIntegrationUtils.getPseudoCurrentTimeNanos());
this.agentHealth = new AgentHealth(AgentControlIntegrationUtils.getPseudoCurrentTimeNanos());

for (HealthDataProducer healthProducer : healthProducers) {
healthProducer.registerHealthDataChangeListener(this);
Expand All @@ -41,15 +41,15 @@ public SuperAgentIntegrationService(SuperAgentIntegrationHealthClient client, Ag
@Override
protected void doStart() throws Exception {
if (isEnabled()) {
Agent.LOG.log(Level.INFO, "SuperAgentIntegrationService starting: Health file location: {0} Frequency: {1} Scheme: {2}",
agentConfig.getSuperAgentIntegrationConfig().getHealthDeliveryLocation(),
agentConfig.getSuperAgentIntegrationConfig().getHealthReportingFrequency(),
agentConfig.getSuperAgentIntegrationConfig().getHealthClientType());
NewRelic.getAgent().getMetricAggregator().incrementCounter(MetricNames.SUPPORTABILITY_SUPERAGENT_HEALTH_REPORTING_ENABLED);
Agent.LOG.log(Level.INFO, "AgentControlIntegrationService starting: Health file location: {0} Frequency: {1} Scheme: {2}",
agentConfig.getAgentControlIntegrationConfig().getHealthDeliveryLocation(),
agentConfig.getAgentControlIntegrationConfig().getHealthReportingFrequency(),
agentConfig.getAgentControlIntegrationConfig().getHealthClientType());
NewRelic.getAgent().getMetricAggregator().incrementCounter(MetricNames.SUPPORTABILITY_AGENT_CONTROL_HEALTH_REPORTING_ENABLED);

int messageSendFrequency = agentConfig.getSuperAgentIntegrationConfig().getHealthReportingFrequency(); //Used for both repeat frequency and initial delay
int messageSendFrequency = agentConfig.getAgentControlIntegrationConfig().getHealthReportingFrequency(); //Used for both repeat frequency and initial delay

this.scheduler = Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory("New Relic Super Agent Integration Service", true));
this.scheduler = Executors.newSingleThreadScheduledExecutor(new DefaultThreadFactory("New Relic Agent Control Integration Service", true));
this.scheduler.scheduleWithFixedDelay(() -> client.sendHealthMessage(agentHealth), messageSendFrequency, messageSendFrequency, TimeUnit.SECONDS);
}
}
Expand All @@ -65,7 +65,7 @@ protected void doStop() throws Exception {

@Override
public boolean isEnabled() {
return agentConfig.getSuperAgentIntegrationConfig().isEnabled() && client != null && client.isValid();
return agentConfig.getAgentControlIntegrationConfig().isEnabled() && client != null && client.isValid();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.superagent;
package com.newrelic.agent.agentcontrol;

import com.newrelic.agent.config.AgentConfig;
import com.newrelic.agent.config.SuperAgentIntegrationConfig;
import com.newrelic.agent.config.AgentControlIntegrationConfig;

import java.util.List;

public class SuperAgentIntegrationUtils {
public class AgentControlIntegrationUtils {
public static long getPseudoCurrentTimeNanos() {
// The message expects the time in nanoseconds. Since this is a practical impossibility on most hardware,
// simply get the current ms and multiply.
Expand All @@ -32,9 +32,9 @@ public static void reportHealthyStatus(List<HealthDataChangeListener> healthData
}

public static void reportUnhealthyStatusPriorToServiceStart(AgentConfig config, AgentHealth.Status status) {
SuperAgentIntegrationConfig superAgentIntegrationConfig = config.getSuperAgentIntegrationConfig();
if (superAgentIntegrationConfig.isEnabled()) {
SuperAgentIntegrationHealthClient client = SuperAgentIntegrationClientFactory.createHealthClient(superAgentIntegrationConfig);
AgentControlIntegrationConfig agentControlIntegrationConfig = config.getAgentControlIntegrationConfig();
if (agentControlIntegrationConfig.isEnabled()) {
AgentControlIntegrationHealthClient client = AgentControlIntegrationClientFactory.createHealthClient(agentControlIntegrationConfig);
AgentHealth agentHealth = new AgentHealth(getPseudoCurrentTimeNanos());
agentHealth.setUnhealthyStatus(status);
client.sendHealthMessage(agentHealth);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.superagent;
package com.newrelic.agent.agentcontrol;

public class AgentHealth {
public enum Category {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.superagent;
package com.newrelic.agent.agentcontrol;

public interface HealthDataChangeListener {
void onUnhealthyStatus(AgentHealth.Status newStatus, String... additionalInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.superagent;
package com.newrelic.agent.agentcontrol;

public interface HealthDataProducer {
void registerHealthDataChangeListener(HealthDataChangeListener listener);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import com.newrelic.agent.service.AbstractService;
import com.newrelic.agent.service.ServiceFactory;
import com.newrelic.agent.stats.StatsEngine;
import com.newrelic.agent.superagent.AgentHealth;
import com.newrelic.agent.superagent.HealthDataChangeListener;
import com.newrelic.agent.superagent.HealthDataProducer;
import com.newrelic.agent.superagent.SuperAgentIntegrationUtils;
import com.newrelic.agent.agentcontrol.AgentHealth;
import com.newrelic.agent.agentcontrol.HealthDataChangeListener;
import com.newrelic.agent.agentcontrol.HealthDataProducer;
import com.newrelic.agent.agentcontrol.AgentControlIntegrationUtils;

import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
Expand Down Expand Up @@ -187,7 +187,7 @@ private boolean shouldTrip() {
Agent.LOG.log(Level.WARNING, "Circuit breaker tripped at memory {0}% GC CPU time {1}%", percentageFreeMemory,
gcCpuTimePercentage);

SuperAgentIntegrationUtils.reportUnhealthyStatus(healthDataChangeListeners, AgentHealth.Status.GC_CIRCUIT_BREAKER,
AgentControlIntegrationUtils.reportUnhealthyStatus(healthDataChangeListeners, AgentHealth.Status.GC_CIRCUIT_BREAKER,
String.valueOf(percentageFreeMemory), String.valueOf(gcCpuTimePercentage));

return true;
Expand Down Expand Up @@ -232,7 +232,7 @@ private void trip() {
public void reset() {
tripped = 0;
Agent.LOG.log(Level.FINE, "Circuit breaker reset");
SuperAgentIntegrationUtils.reportHealthyStatus(healthDataChangeListeners, AgentHealth.Category.CIRCUIT_BREAKER);
AgentControlIntegrationUtils.reportHealthyStatus(healthDataChangeListeners, AgentHealth.Category.CIRCUIT_BREAKER);
logWarning.set(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,6 @@ public interface AgentConfig extends com.newrelic.api.agent.Config, DataSenderCo

SlowTransactionsConfig getSlowTransactionsConfig();

SuperAgentIntegrationConfig getSuperAgentIntegrationConfig();
AgentControlIntegrationConfig getAgentControlIntegrationConfig();

}
Loading

0 comments on commit 1ab03e1

Please sign in to comment.