Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -195,7 +195,10 @@ private boolean isGenerationalGcConfigured() {
}

private void countPoolSizeDelta(Map<String, MemoryUsage> before, Map<String, MemoryUsage> after, Counter counter,
AtomicLong previousPoolSize, String poolName) {
AtomicLong previousPoolSize, @Nullable String poolName) {
if (poolName == null) {
return;
}
final long beforeBytes = before.get(poolName).getUsed();
final long afterBytes = after.get(poolName).getUsed();
final long delta = beforeBytes - previousPoolSize.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.within;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

/**
* Tests for {@link JvmGcMetrics}.
Expand Down Expand Up @@ -65,13 +64,18 @@ void noJvmImplementationSpecificApiSignatures() {
}

@Test
void metersAreBound() {
assertThat(registry.find("jvm.gc.live.data.size").gauge()).isNotNull();
assertThat(registry.find("jvm.gc.memory.allocated").counter()).isNotNull();
assertThat(registry.find("jvm.gc.max.data.size").gauge().value()).isGreaterThan(0);
void gcMetricsAvailableAfterGc() {
System.gc();
await().timeout(200, TimeUnit.MILLISECONDS).alias("NotificationListener takes time after GC")
.untilAsserted(() ->
assertThat(registry.find("jvm.gc.live.data.size").gauge().value()).isPositive());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By forcing a GC and waiting for the notification listener to update metrics, this test does a much better job of ensuring expected metrics are available for the configured collector.

assertThat(registry.find("jvm.gc.memory.allocated").counter().count()).isPositive();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This metric is still missing for optavgpause and optthruput due to the allocation pool name not being set. We don't have a CI job run with OpenJ9 because we're still waiting for CI images (possibly CircleCI-Public/cimg-openjdk#78). I think we can fix the missing allocated counter separately from this pull request because it is still an improvement to get rid of the NPE which allows updating of the live and max data size gauges.

assertThat(registry.find("jvm.gc.max.data.size").gauge().value()).isPositive();

assumeTrue(binder.isGenerationalGc);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the condition failed, the whole test was marked as skipped, but if we want to use this same test for generational and non-generational collectors, we should run the part of this test before here for both and report it as passed (not skipped) for non-generational collectors if all assertions passed before here.

assertThat(registry.find("jvm.gc.memory.promoted").counter()).isNotNull();
if (!binder.isGenerationalGc) {
return;
}
assertThat(registry.find("jvm.gc.memory.promoted").counter().count()).isPositive();
}

@Test
Expand Down