From 072121c33ad4ba87db87d8291042ac4526934bc6 Mon Sep 17 00:00:00 2001 From: edeleon Date: Tue, 4 Jun 2024 14:30:31 -0700 Subject: [PATCH 1/4] added hostname property to daemonconfig --- .../com/newrelic/agent/jfr/JfrService.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java b/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java index d8b12778c6..e6761c8055 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java @@ -21,6 +21,7 @@ import com.newrelic.jfr.daemon.*; import com.newrelic.telemetry.Attributes; +import java.net.InetAddress; import java.net.URI; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -120,6 +121,21 @@ boolean coreApisExist() { @VisibleForTesting DaemonConfig buildDaemonConfig() { + + String host; + String appPort = ServiceFactory + .getEnvironmentService() + .getEnvironment() + .getAgentIdentity() + .getServerPort() + .toString(); + try { + host = InetAddress.getLocalHost().getHostName(); + } catch (Throwable t) { + logger.error(t.getMessage()); + host = InetAddress.getLoopbackAddress().getHostAddress(); + } + String hostname = String.format("%s:%s", host, appPort); DaemonConfig.Builder builder = DaemonConfig.builder() .daemonVersion(VersionFinder.getVersion()) .useLicenseKey(jfrConfig.useLicenseKey()) @@ -132,7 +148,8 @@ DaemonConfig buildDaemonConfig() { .proxyScheme(defaultAgentConfig.getProxyScheme()) .proxyPort(defaultAgentConfig.getProxyPort()) .proxyUser(defaultAgentConfig.getProxyUser()) - .proxyPassword(defaultAgentConfig.getProxyPassword()); + .proxyPassword(defaultAgentConfig.getProxyPassword()) + .hostname(hostname); return builder.build(); } From 5e4311a254703294a7189f8c01913a0d72b36310 Mon Sep 17 00:00:00 2001 From: edeleon Date: Fri, 7 Jun 2024 01:52:35 -0700 Subject: [PATCH 2/4] reverted config changes and added getHostname method --- .../com/newrelic/agent/jfr/JfrService.java | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java b/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java index e6761c8055..9039d3eb40 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java @@ -28,6 +28,7 @@ import java.util.logging.Level; import static com.newrelic.jfr.daemon.AttributeNames.ENTITY_GUID; +import static com.newrelic.jfr.daemon.AttributeNames.HOSTNAME; import static com.newrelic.jfr.daemon.SetupUtils.buildCommonAttributes; import static com.newrelic.jfr.daemon.SetupUtils.buildUploader; @@ -57,7 +58,8 @@ protected void doStart() { final String entityGuid = ServiceFactory.getRPMService().getEntityGuid(); Agent.LOG.log(Level.INFO, "JFR Monitor obtained entity guid from agent: " + entityGuid); commonAttrs.put(ENTITY_GUID, entityGuid); - + final String hostname = getHostname(); + commonAttrs.put(HOSTNAME, hostname); final JFRUploader uploader = buildUploader(daemonConfig); String pattern = defaultAgentConfig.getValue(ThreadService.NAME_PATTERN_CFG_KEY, ThreadNameNormalizer.DEFAULT_PATTERN); uploader.readyToSend(new EventConverter(commonAttrs, pattern)); @@ -65,14 +67,14 @@ protected void doStart() { ExecutorService jfrMonitorService = Executors.newSingleThreadExecutor(); jfrMonitorService.submit( - () -> { - try { - startJfrLoop(); - } catch (JfrRecorderException e) { - Agent.LOG.log(Level.INFO, "Error in JFR Monitor, shutting down", e); - jfrController.shutdown(); - } - }); + () -> { + try { + startJfrLoop(); + } catch (JfrRecorderException e) { + Agent.LOG.log(Level.INFO, "Error in JFR Monitor, shutting down", e); + jfrController.shutdown(); + } + }); } catch (Throwable t) { Agent.LOG.log(Level.INFO, "Unable to attach JFR Monitor", t); } @@ -119,9 +121,7 @@ boolean coreApisExist() { return true; } - @VisibleForTesting - DaemonConfig buildDaemonConfig() { - + private String getHostname() { String host; String appPort = ServiceFactory .getEnvironmentService() @@ -131,25 +131,28 @@ DaemonConfig buildDaemonConfig() { .toString(); try { host = InetAddress.getLocalHost().getHostName(); - } catch (Throwable t) { - logger.error(t.getMessage()); + } catch (Exception e) { + logger.error(e.getMessage()); host = InetAddress.getLoopbackAddress().getHostAddress(); } - String hostname = String.format("%s:%s", host, appPort); + return String.format("%s:%s", host, appPort); + } + + @VisibleForTesting + DaemonConfig buildDaemonConfig() { DaemonConfig.Builder builder = DaemonConfig.builder() - .daemonVersion(VersionFinder.getVersion()) - .useLicenseKey(jfrConfig.useLicenseKey()) - .apiKey(defaultAgentConfig.getLicenseKey()) - .monitoredAppName(defaultAgentConfig.getApplicationName()) - .auditLogging(jfrConfig.auditLoggingEnabled()) - .metricsUri(URI.create(defaultAgentConfig.getMetricIngestUri())) - .eventsUri(URI.create(defaultAgentConfig.getEventIngestUri())) - .proxyHost(defaultAgentConfig.getProxyHost()) - .proxyScheme(defaultAgentConfig.getProxyScheme()) - .proxyPort(defaultAgentConfig.getProxyPort()) - .proxyUser(defaultAgentConfig.getProxyUser()) - .proxyPassword(defaultAgentConfig.getProxyPassword()) - .hostname(hostname); + .daemonVersion(VersionFinder.getVersion()) + .useLicenseKey(jfrConfig.useLicenseKey()) + .apiKey(defaultAgentConfig.getLicenseKey()) + .monitoredAppName(defaultAgentConfig.getApplicationName()) + .auditLogging(jfrConfig.auditLoggingEnabled()) + .metricsUri(URI.create(defaultAgentConfig.getMetricIngestUri())) + .eventsUri(URI.create(defaultAgentConfig.getEventIngestUri())) + .proxyHost(defaultAgentConfig.getProxyHost()) + .proxyScheme(defaultAgentConfig.getProxyScheme()) + .proxyPort(defaultAgentConfig.getProxyPort()) + .proxyUser(defaultAgentConfig.getProxyUser()) + .proxyPassword(defaultAgentConfig.getProxyPassword()); return builder.build(); } From 8f8a78b5936ee9293fb281fa04923bdd3025b057 Mon Sep 17 00:00:00 2001 From: Enriqueta De Leon Date: Fri, 7 Jun 2024 10:40:28 -0700 Subject: [PATCH 3/4] Update jfr-daemon version --- newrelic-agent/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/newrelic-agent/build.gradle b/newrelic-agent/build.gradle index 4cf969a536..78ad1dc268 100644 --- a/newrelic-agent/build.gradle +++ b/newrelic-agent/build.gradle @@ -74,7 +74,7 @@ dependencies { transitive = false } shadowIntoJar("com.newrelic.agent.java:newrelic-module-util-java:2.1") - shadowIntoJar("com.newrelic:jfr-daemon:1.11.1") + shadowIntoJar("com.newrelic:jfr-daemon:1.12.0") shadowIntoJar "org.ow2.asm:asm:$asmVersion" shadowIntoJar "org.ow2.asm:asm-tree:$asmVersion" shadowIntoJar "org.ow2.asm:asm-commons:$asmVersion" From 907ab2148e58865a9b4441d42273ba5994dee3dc Mon Sep 17 00:00:00 2001 From: edeleon Date: Fri, 7 Jun 2024 14:11:58 -0700 Subject: [PATCH 4/4] update appPort type in getHostname --- .../src/main/java/com/newrelic/agent/jfr/JfrService.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java b/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java index 9039d3eb40..68afb686ff 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java @@ -123,12 +123,11 @@ boolean coreApisExist() { private String getHostname() { String host; - String appPort = ServiceFactory + Integer appPort = ServiceFactory .getEnvironmentService() .getEnvironment() .getAgentIdentity() - .getServerPort() - .toString(); + .getServerPort(); try { host = InetAddress.getLocalHost().getHostName(); } catch (Exception e) {