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-1359: Adds a local docker-compose env to test JMXFetch inside the agent #504

Merged
merged 4 commits into from
Jan 18, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ target/*
# jenv
.java_version
.java-version

.env
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 runs 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
29 changes: 29 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
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=00000000001 # Remove me if you specify a valid API key in .env
- DD_JMX_TELEMETRY_ENABLED=true
env_file: .env
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /proc/:/host/proc/:ro
- /sys/fs/cgroup:/host/sys/fs/cgroup:ro
Loading