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 28, 2023
1 parent 5b7b838 commit cb484e0
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Changelog
=========
# Next / TBD
# 0.49.1 / TBD
* [FEATURE] Add ZGC Major and Minor Cycles and ZGC Major and Minor Pauses beans support out of the box (generational ZGC support) [#502][]

# 0.49.0 / 2023-11-10
* [FEATURE] Adds more per-instance telemetry data around bean matching
Expand Down Expand Up @@ -761,6 +762,7 @@ Changelog
[#449]: https://github.com/DataDog/jmxfetch/issues/449
[#469]: https://github.com/DataDog/jmxfetch/issues/469
[#477]: https://github.com/DataDog/jmxfetch/issues/477
[#502]: https://github.com/DataDog/jmxfetch/issues/502
[@alz]: https://github.com/alz
[@aoking]: https://github.com/aoking
[@arrawatia]: https://github.com/arrawatia
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,52 @@
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.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
35 changes: 29 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,26 @@ public void testDefaultNewGCMetricsUseZGC() throws IOException {
}
}

@Test
public void testDefaultNewGCMetricsUseGenerationalZGC() 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));
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 +208,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 cb484e0

Please sign in to comment.