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

feat(insights): add config parameter to opt out of Insights #267

Merged
merged 1 commit into from
Nov 27, 2023
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
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
Loading