Skip to content

Commit

Permalink
Merge pull request #1764 from newrelic/jfr-with-hsm
Browse files Browse the repository at this point in the history
Disallow JFR when HSM is enabled
  • Loading branch information
jtduffy authored Feb 27, 2024
2 parents ae03a7c + 3bb83a3 commit ba1bd5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,13 @@ void startJfrLoop() throws JfrRecorderException {
@Override
public final boolean isEnabled() {
final boolean enabled = jfrConfig.isEnabled();
boolean isHighSecurity = defaultAgentConfig.isHighSecurity();
if (!enabled) {
Agent.LOG.log(Level.INFO, "New Relic JFR Monitor is disabled: JFR config has not been enabled in the Java agent.");
} else if (isHighSecurity) {
Agent.LOG.log(Level.INFO, "New Relic JFR Monitor is enabled but High Security mode is also enabled; JFR will not be activated.");
}
return enabled;
return enabled && !isHighSecurity;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ public void jfrLoopDoesNotStartWhenIsEnabledIsFalse() throws JfrRecorderExceptio
assertFalse(spyJfr.isEnabled());
verify(spyJfr, times(0)).startJfrLoop();
}

@Test
public void jfrLoopDoesNotStartWhenIsEnabledIsTrueAndHighSecurityIsTrue() throws JfrRecorderException {
JfrService jfrService = new JfrService(jfrConfig, agentConfig);
JfrService spyJfr = spy(jfrService);
when(agentConfig.isHighSecurity()).thenReturn(true);
when(jfrConfig.isEnabled()).thenReturn(true);
when(spyJfr.coreApisExist()).thenReturn(true);

spyJfr.doStart();

assertFalse(spyJfr.isEnabled());
verify(spyJfr, times(0)).startJfrLoop();
}

@Category( IBMJ9IncompatibleTest.class )
@Test
public void jfrLoopDoesStart() {
Expand Down

0 comments on commit ba1bd5b

Please sign in to comment.