Skip to content

Commit

Permalink
Adds a local docker-compose env to test JMXFetch inside the agent
Browse files Browse the repository at this point in the history
  • Loading branch information
scottopell committed Dec 28, 2023
1 parent 68232f3 commit dcc085c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Dockerfile.agentbase
Original file line number Diff line number Diff line change
@@ -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

11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dcc085c

Please sign in to comment.