Skip to content
Open
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 pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.redhat.insights</groupId>
<artifactId>runtimes-agent</artifactId>
<version>1.0.4</version>
<version>1.0.5-SNAPSHOT</version>

<name>Red Hat Insights Java Agent</name>
<description>Red Hat Insights Java Agent</description>
Expand Down
29 changes: 28 additions & 1 deletion src/main/java/com/redhat/insights/agent/AgentBasicReport.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* Copyright (C) Red Hat 2023-2024 */
/* Copyright (C) Red Hat 2023-2025 */
package com.redhat.insights.agent;

import com.redhat.insights.agent.api.SubreportProvider;
import com.redhat.insights.config.InsightsConfiguration;
import com.redhat.insights.jars.ClasspathJarInfoSubreport;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.AbstractTopLevelReportBase;
import com.redhat.insights.reports.InsightsSubreport;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;

public class AgentBasicReport extends AbstractTopLevelReportBase {
private static final InsightsLogger logger = AgentLogger.getLogger();
Expand All @@ -22,9 +24,34 @@ public static AgentBasicReport of(AgentConfiguration configuration) {
ClasspathJarInfoSubreport jarsReport = new ClasspathJarInfoSubreport(logger);
reports.put("jars", jarsReport);
reports.put("details", AgentSubreport.of(jarsReport, configuration));
addExtensionReports(reports, configuration);
return new AgentBasicReport(configuration, reports);
}

private static void addExtensionReports(
Map<String, InsightsSubreport> reports, AgentConfiguration configuration) {
// Load the agent SubreportProvider if available
ServiceLoader<SubreportProvider> loader = ServiceLoader.load(SubreportProvider.class);
for (SubreportProvider provider : loader) {
Map<String, InsightsSubreport> subs = provider.provideSubreports(configuration, logger);
// add any provided subreports to main agent report
// ensure there is no name conflict, fail if there is
for (String name : subs.keySet()) {
if (reports.containsKey(name)) {
throw new RuntimeException(
"The key provided by the subreport provider ('"
+ name
+ "': "
+ subs.get(name)
+ ") exists already! ("
+ reports.get(name)
+ ")");
}
reports.put(name, subs.get(name));
}
}
}

@Override
protected long getProcessPID() {
return Long.parseLong(
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/redhat/insights/agent/AgentMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ private AgentMain(AgentConfiguration configuration, BlockingQueue<JarInfo> jarsT

public static void premain(String agentArgs, Instrumentation instrumentation) {
startAgent(agentArgs, instrumentation);

// There seems to be some kind of race condition between premain() and java main class main()
// which results in JVM intermittently exiting with status 1 after return from premain() and
// before invoking main class main()
// Observed on macOS with OpenJDK 17 using -shaded.jar
// The next lines make the problem go away
try {
Thread.sleep(1);
} catch (InterruptedException e) {
}
}

public static void agentmain(String agentArgs, Instrumentation instrumentation) {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/redhat/insights/agent/api/SubreportProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Copyright (C) Red Hat 2025 */
package com.redhat.insights.agent.api;

import com.redhat.insights.agent.AgentConfiguration;
import com.redhat.insights.logging.InsightsLogger;
import com.redhat.insights.reports.InsightsSubreport;
import java.util.Map;

public interface SubreportProvider {

Map<String, InsightsSubreport> provideSubreports(
AgentConfiguration configuration, InsightsLogger logger);
}