Skip to content

Commit

Permalink
Adding ZGenerational for ZGC
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosroman committed Dec 27, 2023
1 parent 5b7b838 commit c398012
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,74 @@
domain: java.lang
type: GarbageCollector
name: ZGC Pauses
attribute:
CollectionCount:
alias: jvm.gc.zgc_pauses_collection_count
metric_type: counter
CollectionTime:
alias: jvm.gc.zgc_pauses_collection_time
metric_type: counter

# Z Garbage Collector with ZGenerational
#- include:
# domain: java.lang
# type: GarbageCollector
# name: ZGC Major Cycles
# attribute:
# CollectionCount:
# alias: jvm.gc.major_collection_count
# metric_type: counter
# CollectionTime:
# alias: jvm.gc.major_collection_time
# metric_type: counter
#- include:
# domain: java.lang
# type: GarbageCollector
# name: ZGC Minor Cycles
# attribute:
# CollectionCount:
# alias: jvm.gc.minor_collection_count
# metric_type: counter
# CollectionTime:
# alias: jvm.gc.minor_collection_time
# metric_type: counter
- include:
domain: java.lang
type: GarbageCollector
name: ZGC Major Cycles
attribute:
CollectionCount:
alias: jvm.gc.zgc_cycles_collection_count
metric_type: counter
CollectionTime:
alias: jvm.gc.zgc_cycles_collection_time
metric_type: counter
- include:
domain: java.lang
type: GarbageCollector
name: ZGC Major Pauses
attribute:
CollectionCount:
alias: jvm.gc.zgc_pauses_collection_count
metric_type: counter
CollectionTime:
alias: jvm.gc.zgc_pauses_collection_time
metric_type: counter
- include:
domain: java.lang
type: GarbageCollector
name: ZGC Minor Cycles
attribute:
CollectionCount:
alias: jvm.gc.zgc_cycles_collection_count
metric_type: counter
CollectionTime:
alias: jvm.gc.zgc_cycles_collection_time
metric_type: counter
- include:
domain: java.lang
type: GarbageCollector
name: ZGC Minor Pauses
attribute:
CollectionCount:
alias: jvm.gc.zgc_pauses_collection_count
Expand Down
43 changes: 37 additions & 6 deletions src/test/java/org/datadog/jmxfetch/TestGCMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,34 @@ public void testDefaultNewGCMetricsUseZGC() throws IOException {
}
}

@Test
public void testDefaultNewGCMetricsUseZGCAndZGenerational() throws IOException {
try (final MisbehavingJMXServer server = new MisbehavingJMXServer.Builder().withJDKImage(
JDK_21).appendJavaOpts("-XX:+UseZGC -XX:+ZGenerational").build()) {
final List<Map<String, Object>> actualMetrics = startAndGetMetrics(server, true);
assertThat(actualMetrics, hasSize(17));
// assertGCMetric(actualMetrics,
// "jvm.gc.major_collection_count", "ZGC Major Cycles", "counter");
// assertGCMetric(actualMetrics,
// "jvm.gc.major_collection_time", "ZGC Major Cycles", "counter");
// assertGCMetric(actualMetrics,
// "jvm.gc.minor_collection_count", "ZGC Minor Cycles", "counter");
// assertGCMetric(actualMetrics,
// "jvm.gc.minor_collection_time", "ZGC Minor Cycles", "counter");
final List<String> gcCycles = Arrays.asList(
"ZGC Major Cycles",
"ZGC Minor Cycles");
assertGCMetric(actualMetrics, "jvm.gc.zgc_cycles_collection_count", gcCycles);
assertGCMetric(actualMetrics, "jvm.gc.zgc_cycles_collection_time", gcCycles);

final List<String> gcPauses = Arrays.asList(
"ZGC Major Pauses",
"ZGC Minor Pauses");
assertGCMetric(actualMetrics, "jvm.gc.zgc_pauses_collection_count", gcPauses);
assertGCMetric(actualMetrics, "jvm.gc.zgc_pauses_collection_time", gcPauses);
}
}

private List<Map<String, Object>> startAndGetMetrics(final MisbehavingJMXServer server,
final boolean newGCMetrics) throws IOException {
server.start();
Expand Down Expand Up @@ -188,24 +216,27 @@ private static void assertGCMetric(final List<Map<String, Object>> actualMetrics
filteredMetrics.add(actualMetric);
}
}
assertThat(filteredMetrics, hasSize(gcGenerations.size()));
assertThat(
String.format("Asserting filtered metrics for '%s' of metric '%s'", gcGenerations.size(), expectedMetric),
filteredMetrics, hasSize(gcGenerations.size()));
for (final String name : gcGenerations) {
log.debug("Asserting for metric '{}'", name);
log.debug("Asserting for expected metric '{}' with tag 'name:{}'", expectedMetric, name);
boolean found = false;
for (Map<String, Object> filteredMetric : filteredMetrics) {
final Set<String> mTags = new HashSet<>(
Arrays.asList((String[]) (filteredMetric.get("tags"))));

if(mTags.contains(String.format("name:%s", name))) {
assertThat(mTags, not(empty()));
assertThat(mTags, hasSize(5));
log.debug("mTags '{}' has size: {}\n{}", name, mTags.size(), mTags);
assertThat(mTags, hasItems(
assertThat("Should not be empty", mTags, not(empty()));
assertThat("Should have size 5", mTags, hasSize(5));
assertThat("Has correct tags",
mTags, hasItems(
"instance:jmxint_container",
"jmx_domain:java.lang",
"type:GarbageCollector",
String.format("name:%s", name)));
found = true;
break;
}
}
assertThat(String.format("Did not find metric '%s'", name), found, is(true));
Expand Down

0 comments on commit c398012

Please sign in to comment.