From e930b84f6325e35995be7f7488b5b32ed3ae9d6d Mon Sep 17 00:00:00 2001 From: Jerry Duffy Date: Tue, 15 Oct 2024 09:39:49 -0400 Subject: [PATCH] PR comments --- .../config/SuperAgentIntegrationConfig.java | 10 ++++++++++ .../SuperAgentIntegrationConfigImpl.java | 18 ++++++++++++------ .../SuperAgentIntegrationHealthConfig.java | 11 +++++++---- .../superagent/HealthDataChangeListener.java | 6 ++++++ .../agent/superagent/HealthDataProducer.java | 6 ++++++ .../SuperAgentIntegrationService.java | 2 +- .../superagent/SuperAgentIntegrationUtils.java | 2 +- .../agent/transport/DataSenderImpl.java | 8 ++++++++ .../java/com/newrelic/agent/AgentTest.java | 6 ++++++ .../SuperAgentHealthUnitTestClient.java | 3 +-- 10 files changed, 58 insertions(+), 14 deletions(-) diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationConfig.java b/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationConfig.java index a6e2efd14e..dd2a2d8025 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationConfig.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationConfig.java @@ -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(); } 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 a65364c51d..071e0a0639 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 @@ -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; @@ -32,13 +38,13 @@ private SuperAgentIntegrationHealthConfig createHealthConfig() { Map 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; } diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationHealthConfig.java b/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationHealthConfig.java index 24123d7757..1ac2276cd4 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationHealthConfig.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/config/SuperAgentIntegrationHealthConfig.java @@ -1,12 +1,15 @@ +/* + * + * * 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"; @@ -14,7 +17,7 @@ public class SuperAgentIntegrationHealthConfig extends BaseConfig { 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; diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/superagent/HealthDataChangeListener.java b/newrelic-agent/src/main/java/com/newrelic/agent/superagent/HealthDataChangeListener.java index 4aa81228e8..d5554bc974 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/superagent/HealthDataChangeListener.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/superagent/HealthDataChangeListener.java @@ -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 { diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/superagent/HealthDataProducer.java b/newrelic-agent/src/main/java/com/newrelic/agent/superagent/HealthDataProducer.java index c766331a7a..a2329cbfa7 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/superagent/HealthDataProducer.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/superagent/HealthDataProducer.java @@ -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 { 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 59cac55506..b890737f4b 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 @@ -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()); diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/superagent/SuperAgentIntegrationUtils.java b/newrelic-agent/src/main/java/com/newrelic/agent/superagent/SuperAgentIntegrationUtils.java index 7038c6ff10..fff9516526 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/superagent/SuperAgentIntegrationUtils.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/superagent/SuperAgentIntegrationUtils.java @@ -31,7 +31,7 @@ public static void reportHealthyStatus(List 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); diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/transport/DataSenderImpl.java b/newrelic-agent/src/main/java/com/newrelic/agent/transport/DataSenderImpl.java index 386e51e371..76a55ac87e 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/transport/DataSenderImpl.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/transport/DataSenderImpl.java @@ -130,6 +130,7 @@ public class DataSenderImpl implements DataSender, HealthDataProducer { private volatile Map requestMetadata; private volatile Map metadata; private final List healthDataChangeListeners = new CopyOnWriteArrayList<>(); + private final boolean isSuperAgentEnabled; public DataSenderImpl( DataSenderConfig config, @@ -162,6 +163,7 @@ public DataSenderImpl( } this.httpClientWrapper = httpClientWrapper; + this.isSuperAgentEnabled = configService.getDefaultAgentConfig().getSuperAgentIntegrationConfig().isEnabled(); } private void checkAuditMode() { @@ -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(); diff --git a/newrelic-agent/src/test/java/com/newrelic/agent/AgentTest.java b/newrelic-agent/src/test/java/com/newrelic/agent/AgentTest.java index 2fe6f89106..6c332735b0 100644 --- a/newrelic-agent/src/test/java/com/newrelic/agent/AgentTest.java +++ b/newrelic-agent/src/test/java/com/newrelic/agent/AgentTest.java @@ -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; diff --git a/newrelic-agent/src/test/java/com/newrelic/agent/superagent/SuperAgentHealthUnitTestClient.java b/newrelic-agent/src/test/java/com/newrelic/agent/superagent/SuperAgentHealthUnitTestClient.java index cca9f629ab..babf71451e 100644 --- a/newrelic-agent/src/test/java/com/newrelic/agent/superagent/SuperAgentHealthUnitTestClient.java +++ b/newrelic-agent/src/test/java/com/newrelic/agent/superagent/SuperAgentHealthUnitTestClient.java @@ -6,8 +6,7 @@ */ package com.newrelic.agent.superagent; -public class -SuperAgentHealthUnitTestClient implements SuperAgentIntegrationHealthClient { +public class SuperAgentHealthUnitTestClient implements SuperAgentIntegrationHealthClient { private AgentHealth agentHealth;