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

AMLII-1358 - Adding support for Generational ZGC #502

Merged
merged 2 commits into from
Jan 3, 2024
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
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
vickenty marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import java.io.IOException;
import java.nio.file.Paths;
import java.time.Duration;

import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
import org.testcontainers.images.builder.ImageFromDockerfile;
import org.testcontainers.lifecycle.Startable;

Expand Down Expand Up @@ -49,14 +51,23 @@ public MisbehavingJMXServer(
final ImageFromDockerfile img = new ImageFromDockerfile()
.withFileFromPath(".", Paths.get("./tools/misbehaving-jmx-server/"))
.withBuildArg("FINAL_JRE_IMAGE", this.jdkImage);
final WaitAllStrategy strategy = new WaitAllStrategy()
.withStrategy(
Wait.forLogMessage(
".*Supervisor HTTP Server Started. Waiting for initialization payload POST to /init.*",
1)
)
.withStrategy(
Wait.forHttp("/healthy").forPort(this.supervisorPort).forStatusCode(200)
)
.withStartupTimeout(Duration.ofSeconds(10));
this.server = new GenericContainer<>(img)
.withExposedPorts(rmiPort, controlPort, supervisorPort)
.withEnv(RMI_PORT, String.valueOf(rmiPort))
.withEnv(CONTROL_PORT, String.valueOf(controlPort))
.withEnv(SUPERVISOR_PORT, String.valueOf(supervisorPort))
.withEnv(MISBEHAVING_OPTS, this.javaOpts)
.waitingFor(Wait.forLogMessage(
".*Supervisor HTTP Server Started. Waiting for initialization payload POST to /init.*",
1));
.waitingFor(strategy);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.datadog.supervisor;

import io.javalin.http.HttpStatus;
import java.io.File;
import java.io.IOException;
import java.net.ConnectException;
Expand Down Expand Up @@ -91,6 +92,10 @@ public static void main(String[] args) throws IOException {
});
});

app.get("/healthy", ctx -> {
ctx.status(HttpStatus.OK);
});

app.get("/ready", ctx -> {
if (started.get()) {
ctx.status(200);
Expand Down
Loading