diff --git a/Dockerfile.agentbase b/Dockerfile.agentbase new file mode 100644 index 000000000..865e8fa45 --- /dev/null +++ b/Dockerfile.agentbase @@ -0,0 +1,25 @@ +FROM eclipse-temurin:8u382-b05-jdk AS build + +WORKDIR /app + +# Copy the pom.xml and Maven files and install the dependencies +COPY .mvn .mvn/ +COPY pom.xml mvnw mvnw.cmd ./ + +# Use a maven cache to speed up iteration +RUN --mount=type=cache,id=mavenCache,target=/root/.m2,sharing=locked \ + set -eu && \ + ./mvnw dependency:resolve; + +# Copy the source code and build the JAR file +COPY src/ src/ + +RUN --mount=type=cache,id=mavenCache,target=/root/.m2,sharing=locked \ + set -eu && \ + ./mvnw -DskipTests clean package assembly:single; + + +FROM datadog/agent:7-jmx AS final + +COPY --from=build /app/target/jmxfetch-*-jar-with-dependencies.jar /opt/datadog-agent/bin/agent/dist/jmx/jmxfetch.jar + diff --git a/README.md b/README.md index 441072bd9..10a55a9c6 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ The distribution will be created under ```target/```. To use this JAR in the Agent, see [these docs](https://github.com/DataDog/datadog-agent/blob/main/docs/dev/checks/jmxfetch.md). +To test your JAR with a local test-server, see below instructions for "Local Testing" + ### Note If you want build all the JAR files for JMXFetch, you need to use an older JDK version like JDK 8. @@ -72,6 +74,15 @@ the recommended JDK version for development, use `sdk env` to activate it. If you set the system property `-Djmxfetch.filelinelogging=true`, this will enable all log output to include the line number which emitted a given log. +### Local Testing +You can utilize the provided testing server `misbehaving-jmx-server` with the +preset `./docker-compose.yaml` file. This will run two containers, one is the +test server and the other is the Datadog Agent running your local JAR's version +of JMXFetch. + +1. `docker compose up -d` + + ## Testing diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 000000000..4d5b5556b --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,28 @@ +--- +version: "3.9" + +services: + # The docker compose service name is used as the hostname for the misbehaving-jmx-server + # Note it is in the entrypoint as the --rmi-host and in the AD label as the hostname + # that the Agent should reach out to. + jmx-test-server: + build: + context: ./tools/misbehaving-jmx-server/ + # Override entrypoint to specify the docker-compose service name as the RMI host + entrypoint: ["java", "-cp", "misbehavingjmxserver-1.0-SNAPSHOT-jar-with-dependencies.jar", "org.datadog.misbehavingjmxserver.App", "--rmi-host", "jmx-test-server"] + ports: + - "1099:1099" + labels: + com.datadoghq.ad.checks: '{"misbehaving":{"init_config":{"is_jmx":true},"instances":[{"host":"jmx-test-server","port":"1099","collect_default_jvm_metrics":false,"max_returned_metrics":300000,"conf":[{"include":{"domain":"Bohnanza"}}]}]}}' + datadog: + build: + context: . + dockerfile: ./Dockerfile.agentbase + pid: host + environment: + - DD_API_KEY=000000001 + - DD_JMX_TELEMETRY_ENABLED=true + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /proc/:/host/proc/:ro + - /sys/fs/cgroup:/host/sys/fs/cgroup:ro