Skip to content

Commit

Permalink
feat(insights): add config parameter to opt out of Insights (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebaron authored Nov 27, 2023
1 parent af27ccc commit 13033dc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ and how it advertises itself to a Cryostat server instance. Required properties
- [ ] `cryostat.agent.harvester.max-size-b` [`long`]: the JFR `maxsize` setting, specified in bytes, to apply to periodic uploads during the application lifecycle. Defaults to `0`, which means `unlimited`.
- [ ] `cryostat.agent.smart-trigger.definitions` [`String[]`]: a comma-separated list of Smart Trigger definitions to load at startup. Defaults to the empty string: no Smart Triggers.
- [ ] `cryostat.agent.smart-trigger.evaluation.period-ms` [`long`]: the length of time between Smart Trigger evaluations. Default `1000`.
- [ ] `rht.insights.java.opt-out` [`boolean`]: for the Red Hat build of Cryostat, set this to true to disable data collection for Red Hat Insights. Defaults to `false`. Red Hat Insights data collection is always disabled for community builds of Cryostat.

These properties can be set by JVM system properties or by environment variables. For example, the property
`cryostat.agent.baseuri` can be set using `-Dcryostat.agent.baseuri=https://mycryostat.example.com:1234/` or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
public class InsightsAgentHelper {

private static final String INSIGHTS_SVC = "INSIGHTS_SVC";
static final String RHT_INSIGHTS_JAVA_OPT_OUT = "rht.insights.java.opt-out";

private static final InsightsLogger log =
new SLF4JWrapper(LoggerFactory.getLogger(InsightsAgentHelper.class));
Expand All @@ -61,7 +62,10 @@ public InsightsAgentHelper(Instrumentation instrumentation) {
}

public boolean isInsightsEnabled(PluginInfo pluginInfo) {
return pluginInfo.getEnv().containsKey(INSIGHTS_SVC);
// Check if the user has opted out
boolean optingOut =
config.getOptionalValue(RHT_INSIGHTS_JAVA_OPT_OUT, boolean.class).orElse(false);
return pluginInfo.getEnv().containsKey(INSIGHTS_SVC) && !optingOut;
}

public void runInsightsAgent(PluginInfo pluginInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ void testInsightsDisabled() {
Assertions.assertFalse(helper.isInsightsEnabled(pluginInfo));
}

@Test
void testInsightsOptingOut() {
when(config.getOptionalValue("rht.insights.java.opt-out", boolean.class))
.thenReturn(Optional.of(true));
Assertions.assertFalse(helper.isInsightsEnabled(pluginInfo));
}

@Test
void testInsightsNotOptingOut() {
when(config.getOptionalValue("rht.insights.java.opt-out", boolean.class))
.thenReturn(Optional.of(false));
Assertions.assertTrue(helper.isInsightsEnabled(pluginInfo));
}

@Test
void testRunInsightsAgent() {
when(config.getValue(ConfigModule.CRYOSTAT_AGENT_APP_NAME, String.class))
Expand Down

0 comments on commit 13033dc

Please sign in to comment.