Skip to content

Commit a9503ac

Browse files
Merge pull request #2625 from newrelic/disable-jfr-reporting-for-serverless
Serverless POC: Disable JFR when serverless mode is enabled
2 parents cb5ad15 + aafb900 commit a9503ac

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

newrelic-agent/src/main/java/com/newrelic/agent/jfr/JfrService.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,15 @@ void startJfrLoop() throws JfrRecorderException {
9797
public final boolean isEnabled() {
9898
final boolean enabled = jfrConfig.isEnabled();
9999
boolean isHighSecurity = defaultAgentConfig.isHighSecurity();
100+
boolean isServerless = defaultAgentConfig.getServerlessConfig().isEnabled();
100101
if (!enabled) {
101102
Agent.LOG.log(Level.INFO, "New Relic JFR Monitor is disabled: JFR config has not been enabled in the Java agent.");
102103
} else if (isHighSecurity) {
103104
Agent.LOG.log(Level.INFO, "New Relic JFR Monitor is enabled but High Security mode is also enabled; JFR will not be activated.");
105+
} else if (isServerless) {
106+
Agent.LOG.log(Level.INFO, "New Relic JFR Monitor is enabled but Serverless mode is also enabled; JFR will not be activated.");
104107
}
105-
return enabled && !isHighSecurity;
108+
return enabled && !isHighSecurity && !isServerless;
106109
}
107110

108111
@Override

newrelic-agent/src/test/java/com/newrelic/agent/jfr/JfrServiceTest.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
import com.newrelic.agent.RPMServiceManager;
66
import com.newrelic.agent.ThreadService;
77
import com.newrelic.agent.config.AgentConfig;
8-
import com.newrelic.agent.config.ConfigService;
98
import com.newrelic.agent.config.JfrConfig;
9+
import com.newrelic.agent.config.ServerlessConfig;
1010
import com.newrelic.agent.service.ServiceFactory;
11-
import com.newrelic.agent.service.ServiceManager;
12-
import com.newrelic.agent.service.ServiceManagerImpl;
1311
import com.newrelic.jfr.ThreadNameNormalizer;
1412
import com.newrelic.jfr.daemon.DaemonConfig;
1513
import com.newrelic.jfr.daemon.JfrRecorderException;
@@ -18,7 +16,6 @@
1816
import org.junit.Test;
1917
import org.junit.experimental.categories.Category;
2018
import org.mockito.Mock;
21-
import org.mockito.MockedStatic;
2219
import org.mockito.MockitoAnnotations;
2320

2421
import static com.newrelic.agent.config.AgentConfigImpl.DEFAULT_EVENT_INGEST_URI;
@@ -30,7 +27,6 @@
3027
import static org.mockito.Mockito.any;
3128
import static org.mockito.Mockito.eq;
3229
import static org.mockito.Mockito.mock;
33-
import static org.mockito.Mockito.mockStatic;
3430
import static org.mockito.Mockito.spy;
3531
import static org.mockito.Mockito.timeout;
3632
import static org.mockito.Mockito.times;
@@ -45,6 +41,9 @@ public class JfrServiceTest {
4541
@Mock
4642
AgentConfig agentConfig;
4743

44+
@Mock
45+
ServerlessConfig serverlessConfig;
46+
4847
@Before
4948
public void before() {
5049
MockitoAnnotations.openMocks(this);
@@ -62,6 +61,8 @@ public void before() {
6261
when(agentConfig.getProxyScheme()).thenReturn("http");
6362
when(agentConfig.getValue(eq(ThreadService.NAME_PATTERN_CFG_KEY), any(String.class)))
6463
.thenReturn(ThreadNameNormalizer.DEFAULT_PATTERN);
64+
when(agentConfig.getServerlessConfig()).thenReturn(serverlessConfig);
65+
when(serverlessConfig.isEnabled()).thenReturn(false);
6566
}
6667

6768
@Test
@@ -126,6 +127,20 @@ public void jfrLoopDoesNotStartWhenIsEnabledIsTrueAndHighSecurityIsTrue() throws
126127
verify(spyJfr, times(0)).startJfrLoop();
127128
}
128129

130+
@Test
131+
public void jfrLoopDoesNotStartWhenIsEnabledIsTrueAndServerlessModeIsTrue() throws JfrRecorderException {
132+
JfrService jfrService = new JfrService(jfrConfig, agentConfig);
133+
JfrService spyJfr = spy(jfrService);
134+
when(serverlessConfig.isEnabled()).thenReturn(true);
135+
when(jfrConfig.isEnabled()).thenReturn(true);
136+
when(spyJfr.coreApisExist()).thenReturn(true);
137+
138+
spyJfr.doStart();
139+
140+
assertFalse(spyJfr.isEnabled());
141+
verify(spyJfr, times(0)).startJfrLoop();
142+
}
143+
129144
@Category( IBMJ9IncompatibleTest.class )
130145
@Test
131146
public void jfrLoopDoesStart() {

0 commit comments

Comments
 (0)