Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Realtime Profiling Instance Naming #1928

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion newrelic-agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
61 changes: 40 additions & 21 deletions newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
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;
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;

Expand Down Expand Up @@ -56,22 +58,23 @@ 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));
jfrController = SetupUtils.buildJfrController(daemonConfig, uploader);

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);
}
Expand Down Expand Up @@ -118,21 +121,37 @@ boolean coreApisExist() {
return true;
}

private String getHostname() {
String host;
Integer appPort = ServiceFactory
.getEnvironmentService()
.getEnvironment()
.getAgentIdentity()
.getServerPort();
try {
host = InetAddress.getLocalHost().getHostName();
} catch (Exception e) {
logger.error(e.getMessage());
host = InetAddress.getLoopbackAddress().getHostAddress();
}
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());
.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();
}

Expand Down
Loading