Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jtduffy committed Oct 15, 2024
1 parent 40dffff commit e930b84
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,17 @@ public interface SuperAgentIntegrationConfig {
*/
int getHealthReportingFrequency();

/**
* Return the fleet id assigned by the super agent
*
* @return the fleet id, if available
*/
String getFleetId();

/**
* Return the health client type ("file" or "noop" for example)
*
* @return the client type
*/
String getHealthClientType();
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
*
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.config;

import com.newrelic.agent.Agent;
Expand Down Expand Up @@ -32,13 +38,13 @@ private SuperAgentIntegrationHealthConfig createHealthConfig() {
Map<String, Object> healthProps = getProperty(SuperAgentIntegrationHealthConfig.ROOT, Collections.emptyMap());
SuperAgentIntegrationHealthConfig superAgentIntegrationHealthConfig;

superAgentIntegrationHealthConfig = new SuperAgentIntegrationHealthConfig(healthProps, SYSTEM_PROPERTY_ROOT);
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;
}
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
@@ -1,20 +1,23 @@
/*
*
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.config;

import com.newrelic.agent.Agent;
import org.apache.commons.lang3.StringUtils;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.logging.Level;

public class SuperAgentIntegrationHealthConfig extends BaseConfig {
public static final String ROOT = "health";
public static final String FREQUENCY = "frequency";
public static final int FREQUENCY_DEFAULT = 5; // In seconds
public static final String LOCATION = "delivery_location"; //URI Format; ex: file://opt/tmp/health.yml

private final int frequency;;
private final int frequency;
private URI deliveryLocation;
private String healthClientType;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
*
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.superagent;

public interface HealthDataChangeListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
*
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent.superagent;

public interface HealthDataProducer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ 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}",
Agent.LOG.log(Level.INFO, "SuperAgentIntegrationService starting: Health file location: {0} Frequency: {1} Scheme: {2}",
agentConfig.getSuperAgentIntegrationConfig().getHealthDeliveryLocation(),
agentConfig.getSuperAgentIntegrationConfig().getHealthReportingFrequency(),
agentConfig.getSuperAgentIntegrationConfig().getHealthClientType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void reportHealthyStatus(List<HealthDataChangeListener> healthData
}
}

public static void reportUnhealthyStatusPriorToServiceStart(AgentConfig config, AgentHealth.Status status) {
public static void reportUnhealthyStatusPriorToServiceStart(AgentConfig config, AgentHealth.Status status) {
SuperAgentIntegrationConfig superAgentIntegrationConfig = config.getSuperAgentIntegrationConfig();
if (superAgentIntegrationConfig.isEnabled()) {
SuperAgentIntegrationHealthClient client = SuperAgentIntegrationClientFactory.createHealthClient(superAgentIntegrationConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public class DataSenderImpl implements DataSender, HealthDataProducer {
private volatile Map<String, String> requestMetadata;
private volatile Map<String, String> metadata;
private final List<HealthDataChangeListener> healthDataChangeListeners = new CopyOnWriteArrayList<>();
private final boolean isSuperAgentEnabled;

public DataSenderImpl(
DataSenderConfig config,
Expand Down Expand Up @@ -162,6 +163,7 @@ public DataSenderImpl(
}

this.httpClientWrapper = httpClientWrapper;
this.isSuperAgentEnabled = configService.getDefaultAgentConfig().getSuperAgentIntegrationConfig().isEnabled();
}

private void checkAuditMode() {
Expand Down Expand Up @@ -698,6 +700,12 @@ private void throwExceptionFromStatusCode(String method, ReadResult result, byte
}
}

private void reportUnhealthyStatusToSuperAgent(AgentHealth.Status status, String ... additionalInfo) {
if (isSuperAgentEnabled) {
SuperAgentIntegrationUtils.reportUnhealthyStatus(healthDataChangeListeners, status, additionalInfo);
}
}

private String parseExceptionMessage(String responseBody) {
try {
JSONParser parser = new JSONParser();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
*
* * Copyright 2024 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
package com.newrelic.agent;

import com.newrelic.agent.config.AgentConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
*/
package com.newrelic.agent.superagent;

public class
SuperAgentHealthUnitTestClient implements SuperAgentIntegrationHealthClient {
public class SuperAgentHealthUnitTestClient implements SuperAgentIntegrationHealthClient {

private AgentHealth agentHealth;

Expand Down

0 comments on commit e930b84

Please sign in to comment.