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

Fix NPE when pulling profiler configuration #2987

Merged
merged 1 commit into from
Apr 4, 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
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public boolean hasBeenConfigured() {
@Nullable
public abstract String getCollectionPlan();

@Nullable
public abstract String getCpuTriggerConfiguration();

@Nullable
public abstract String getMemoryTriggerConfiguration();

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,40 @@ public class ProfilerConfigurationTest {

@Test
void hasBeenConfiguredDetectsDefaultDate() throws JsonProcessingException {
ObjectMapper mapper =
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

String configStr =
"{\"id\":\"an-id\",\"lastModified\":\"0001-01-01T00:00:00+00:00\",\"enabledLastModified\":\"0001-01-01T00:00:00+00:00\",\"enabled\":true,\"collectionPlan\":\"\",\"cpuTriggerConfiguration\":\"--cpu-threshold 80 --cpu-trigger-profilingDuration 120 --cpu-trigger-cooldown 14400 --cpu-trigger-enabled true\",\"memoryTriggerConfiguration\":\"--memory-threshold 80 --memory-trigger-profilingDuration 120 --memory-trigger-cooldown 14400 --memory-trigger-enabled true\",\"defaultConfiguration\":null,\"agentConcurrency\":0}";

ProfilerConfiguration config = mapper.readValue(configStr, ProfilerConfiguration.class);
ProfilerConfiguration config = parseConfig(configStr);

Assertions.assertFalse(config.hasBeenConfigured());
}

@Test
void parsingCopesWithNullCpuTriggerConfiguration() throws JsonProcessingException {
String configStr =
"{\"id\":\"an-id\",\"lastModified\":\"0001-01-01T00:00:00+00:00\",\"enabledLastModified\":\"0001-01-01T00:00:00+00:00\",\"enabled\":true,\"collectionPlan\":\"\",\"cpuTriggerConfiguration\":null,\"memoryTriggerConfiguration\":\"--memory-threshold 80 --memory-trigger-profilingDuration 120 --memory-trigger-cooldown 14400 --memory-trigger-enabled true\",\"defaultConfiguration\":null,\"agentConcurrency\":0}";

ProfilerConfiguration config = parseConfig(configStr);

Assertions.assertTrue(config.getCpuTriggerConfiguration() == null);
}

@Test
void parsingCopesWithNullMemoryTriggerConfiguration() throws JsonProcessingException {
String configStr =
"{\"id\":\"an-id\",\"lastModified\":\"0001-01-01T00:00:00+00:00\",\"enabledLastModified\":\"0001-01-01T00:00:00+00:00\",\"enabled\":true,\"collectionPlan\":\"\",\"cpuTriggerConfiguration\":\"--cpu-threshold 80 --cpu-trigger-profilingDuration 120 --cpu-trigger-cooldown 14400 --cpu-trigger-enabled true\",\"memoryTriggerConfiguration\":null,\"defaultConfiguration\":null,\"agentConcurrency\":0}";

ProfilerConfiguration config = parseConfig(configStr);

Assertions.assertTrue(config.getMemoryTriggerConfiguration() == null);
}

private static ProfilerConfiguration parseConfig(String configStr)
throws JsonProcessingException {
ObjectMapper mapper =
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

ProfilerConfiguration config = mapper.readValue(configStr, ProfilerConfiguration.class);
return config;
}
}